author | katleman |
Tue, 21 Jan 2014 18:17:23 -0800 | |
changeset 22365 | 895bfde469d4 |
parent 8632 | af2a1f02c8ac |
child 25280 | 687ed8b6d77b |
permissions | -rw-r--r-- |
8632
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
1 |
/* |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
4 |
* |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
8 |
* |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
14 |
* |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
18 |
* |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
21 |
* questions. |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
22 |
*/ |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
23 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
24 |
/* |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
25 |
* @test |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
26 |
* @bug 6227454 |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
27 |
* @summary package.html and overview.html may not be read fully |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
28 |
*/ |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
29 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
30 |
import java.io.*; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
31 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
32 |
import com.sun.javadoc.Doclet; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
33 |
import com.sun.javadoc.RootDoc; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
34 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
35 |
public class Test extends Doclet { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
36 |
public static void main(String... args) throws Exception { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
37 |
new Test().run(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
38 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
39 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
40 |
void run() throws Exception { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
41 |
test("<html><body>ABC XYZ</body></html>"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
42 |
test("<html><body>ABC XYZ</BODY></html>"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
43 |
test("<html><BODY>ABC XYZ</body></html>"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
44 |
test("<html><BODY>ABC XYZ</BODY></html>"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
45 |
test("<html><BoDy>ABC XYZ</bOdY></html>"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
46 |
test("<html> ABC XYZ</bOdY></html>", "Body tag missing from HTML"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
47 |
test("<html><body>ABC XYZ </html>", "Close body tag missing from HTML"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
48 |
test("<html> ABC XYZ </html>", "Body tag missing from HTML"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
49 |
test("<html><body>ABC" + bigText(8192, 40) + "XYZ</body></html>"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
50 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
51 |
if (errors > 0) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
52 |
throw new Exception(errors + " errors occurred"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
53 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
54 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
55 |
void test(String text) throws IOException { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
56 |
test(text, null); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
57 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
58 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
59 |
void test(String text, String expectError) throws IOException { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
60 |
testNum++; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
61 |
System.err.println("test " + testNum); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
62 |
File file = writeFile("overview" + testNum + ".html", text); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
63 |
String thisClassName = Test.class.getName(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
64 |
File testSrc = new File(System.getProperty("test.src")); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
65 |
String[] args = { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
66 |
"-bootclasspath", |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
67 |
System.getProperty("java.class.path") |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
68 |
+ File.pathSeparator |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
69 |
+ System.getProperty("sun.boot.class.path"), |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
70 |
"-classpath", ".", |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
71 |
"-package", |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
72 |
"-overview", file.getPath(), |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
73 |
new File(testSrc, thisClassName + ".java").getPath() |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
74 |
}; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
75 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
76 |
StringWriter sw = new StringWriter(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
77 |
PrintWriter pw = new PrintWriter(sw); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
78 |
int rc = com.sun.tools.javadoc.Main.execute( |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
79 |
"javadoc", |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
80 |
pw, pw, pw, |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
81 |
thisClassName, |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
82 |
args); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
83 |
pw.close(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
84 |
String out = sw.toString(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
85 |
if (!out.isEmpty()) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
86 |
System.err.println(out); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
87 |
System.err.println("javadoc exit: rc=" + rc); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
88 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
89 |
if (expectError == null) { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
90 |
if (rc != 0) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
91 |
error("unexpected exit from javadoc; rc:" + rc); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
92 |
} else { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
93 |
if (!out.contains(expectError)) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
94 |
error("expected error text not found: " + expectError); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
95 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
96 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
97 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
98 |
String bigText(int lines, int lineLength) { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
99 |
StringBuilder sb = new StringBuilder(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
100 |
for (int i = 0; i < lineLength; i++) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
101 |
sb.append(String.valueOf(i % 10)); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
102 |
sb.append("\n"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
103 |
String line = sb.toString(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
104 |
sb.setLength(0); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
105 |
for (int i = 0; i < lines; i++) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
106 |
sb.append(line); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
107 |
return sb.toString(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
108 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
109 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
110 |
File writeFile(String path, String body) throws IOException { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
111 |
File f = new File(path); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
112 |
FileWriter out = new FileWriter(f); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
113 |
try { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
114 |
out.write(body); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
115 |
} finally { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
116 |
out.close(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
117 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
118 |
return f; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
119 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
120 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
121 |
void error(String msg) { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
122 |
System.err.println("Error: " + msg); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
123 |
errors++; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
124 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
125 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
126 |
int testNum; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
127 |
int errors; |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
128 |
|
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
129 |
public static boolean start(RootDoc root) { |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
130 |
String text = root.commentText(); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
131 |
if (text.length() < 64) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
132 |
System.err.println("text: '" + text + "'"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
133 |
else |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
134 |
System.err.println("text: '" |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
135 |
+ text.substring(0, 20) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
136 |
+ "..." |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
137 |
+ text.substring(text.length() - 20) |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
138 |
+ "'"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
139 |
return text.startsWith("ABC") && text.endsWith("XYZ"); |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
140 |
} |
af2a1f02c8ac
6227454: package.html and overview.html may not be read fully
jjg
parents:
diff
changeset
|
141 |
} |