# HG changeset patch # User jjg # Date 1299297362 28800 # Node ID 4ee7de0684f51a5dbf8826bcac799928536c83a1 # Parent ebf7c13df6c07ce2331f13b218c238a993f5a119 6227454: package.html and overview.html may not be read fully Reviewed-by: bpatel diff -r ebf7c13df6c0 -r 4ee7de0684f5 src/share/classes/com/sun/tools/javadoc/DocImpl.java --- a/src/share/classes/com/sun/tools/javadoc/DocImpl.java Fri Mar 04 19:53:03 2011 -0800 +++ b/src/share/classes/com/sun/tools/javadoc/DocImpl.java Fri Mar 04 19:56:02 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ package com.sun.tools.javadoc; +import java.io.DataInputStream; import java.io.InputStream; import java.io.IOException; import java.text.CollationKey; @@ -33,6 +34,8 @@ import com.sun.javadoc.*; import com.sun.tools.javac.util.Position; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * abstract base class of all Doc classes. Doc item's are representations @@ -166,51 +169,28 @@ * Utility for subclasses which read HTML documentation files. */ String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { - int filesize = input.available(); - byte[] filecontents = new byte[filesize]; - input.read(filecontents, 0, filesize); - input.close(); + byte[] filecontents = new byte[input.available()]; + try { + DataInputStream dataIn = new DataInputStream(input); + dataIn.readFully(filecontents); + } finally { + input.close(); + } String encoding = env.getEncoding(); String rawDoc = (encoding!=null) ? new String(filecontents, encoding) : new String(filecontents); - String upper = null; - int bodyIdx = rawDoc.indexOf("', bodyIdx); - if (bodyIdx == -1) { - env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), - "javadoc.Body_missing_from_html_file"); + Pattern bodyPat = Pattern.compile("(?is).*]*>(.*)ABC XYZ"); + test("ABC XYZ"); + test("ABC XYZ"); + test("ABC XYZ"); + test("ABC XYZ"); + test(" ABC XYZ", "Body tag missing from HTML"); + test("ABC XYZ ", "Close body tag missing from HTML"); + test(" ABC XYZ ", "Body tag missing from HTML"); + test("ABC" + bigText(8192, 40) + "XYZ"); + + if (errors > 0) + throw new Exception(errors + " errors occurred"); + } + + void test(String text) throws IOException { + test(text, null); + } + + void test(String text, String expectError) throws IOException { + testNum++; + System.err.println("test " + testNum); + File file = writeFile("overview" + testNum + ".html", text); + String thisClassName = Test.class.getName(); + File testSrc = new File(System.getProperty("test.src")); + String[] args = { + "-bootclasspath", + System.getProperty("java.class.path") + + File.pathSeparator + + System.getProperty("sun.boot.class.path"), + "-classpath", ".", + "-package", + "-overview", file.getPath(), + new File(testSrc, thisClassName + ".java").getPath() + }; + + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + int rc = com.sun.tools.javadoc.Main.execute( + "javadoc", + pw, pw, pw, + thisClassName, + args); + pw.close(); + String out = sw.toString(); + if (!out.isEmpty()) + System.err.println(out); + System.err.println("javadoc exit: rc=" + rc); + + if (expectError == null) { + if (rc != 0) + error("unexpected exit from javadoc; rc:" + rc); + } else { + if (!out.contains(expectError)) + error("expected error text not found: " + expectError); + } + } + + String bigText(int lines, int lineLength) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < lineLength; i++) + sb.append(String.valueOf(i % 10)); + sb.append("\n"); + String line = sb.toString(); + sb.setLength(0); + for (int i = 0; i < lines; i++) + sb.append(line); + return sb.toString(); + } + + File writeFile(String path, String body) throws IOException { + File f = new File(path); + FileWriter out = new FileWriter(f); + try { + out.write(body); + } finally { + out.close(); + } + return f; + } + + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + int testNum; + int errors; + + public static boolean start(RootDoc root) { + String text = root.commentText(); + if (text.length() < 64) + System.err.println("text: '" + text + "'"); + else + System.err.println("text: '" + + text.substring(0, 20) + + "..." + + text.substring(text.length() - 20) + + "'"); + return text.startsWith("ABC") && text.endsWith("XYZ"); + } +}