author | jjg |
Wed, 10 Aug 2016 15:47:46 -0700 | |
changeset 40308 | 274367a99f98 |
parent 37637 | b47af0433922 |
permissions | -rw-r--r-- |
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
1 |
/* |
37637
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
4 |
* |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
8 |
* |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
14 |
* |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
18 |
* |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
21 |
* questions. |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
22 |
*/ |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
23 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
24 |
/* |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
25 |
* @test |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
26 |
* @bug 6964914 |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
27 |
* @summary javadoc does not output number of warnings using user written doclet |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
28 |
* @modules jdk.javadoc |
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
29 |
*/ |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
30 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
31 |
import java.io.*; |
37637
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
32 |
import java.util.*; |
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
33 |
|
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
34 |
import com.sun.javadoc.Doclet; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
35 |
import com.sun.javadoc.RootDoc; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
36 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
37 |
public class TestUserDoclet extends Doclet { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
39 |
new TestUserDoclet().run(); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
40 |
} |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
41 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
42 |
static final String docletWarning = "warning from test doclet"; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
43 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
44 |
/** Main doclet method. */ |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
45 |
public static boolean start(RootDoc root) { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
46 |
root.printWarning(null, docletWarning); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
47 |
return true; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
48 |
} |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
49 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
50 |
/** Main test method. */ |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
51 |
void run() throws Exception { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
52 |
File javaHome = new File(System.getProperty("java.home")); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
53 |
File javadoc = new File(new File(javaHome, "bin"), "javadoc"); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
54 |
File testSrc = new File(System.getProperty("test.src")); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
55 |
File testClasses = new File(System.getProperty("test.classes")); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
56 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
57 |
// run javadoc in separate process to ensure doclet executed under |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
58 |
// normal user conditions w.r.t. classloader |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
59 |
String thisClassName = TestUserDoclet.class.getName(); |
37637
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
60 |
List<String> cmdArgs = new ArrayList<>(); |
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
61 |
cmdArgs.add(javadoc.getPath()); |
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
62 |
cmdArgs.addAll(Arrays.asList( |
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
63 |
"-doclet", thisClassName, |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
64 |
"-docletpath", testClasses.getPath(), |
37637
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
65 |
new File(testSrc, thisClassName + ".java").getPath() |
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
66 |
)); |
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
67 |
Process p = new ProcessBuilder() |
b47af0433922
8154500: fix handling of jdk.launcher.patch.* in tests
jjg
parents:
36526
diff
changeset
|
68 |
.command(cmdArgs) |
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
69 |
.redirectErrorStream(true) |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
70 |
.start(); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
71 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
72 |
int actualDocletWarnCount = 0; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
73 |
int reportedDocletWarnCount = 0; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
74 |
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
75 |
try { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
76 |
String line; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
77 |
while ((line = in.readLine()) != null) { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
78 |
System.err.println(line); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
79 |
if (line.contains(docletWarning)) |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
80 |
actualDocletWarnCount++; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
81 |
if (line.matches("[0-9]+ warning(s)?")) |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
82 |
reportedDocletWarnCount = |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
83 |
Integer.valueOf(line.substring(0, line.indexOf(" "))); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
84 |
} |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
85 |
} finally { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
86 |
in.close(); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
87 |
} |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
88 |
int rc = p.waitFor(); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
89 |
if (rc != 0) |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
90 |
System.err.println("javadoc failed, rc:" + rc); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
91 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
92 |
int expectedDocletWarnCount = 1; |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
93 |
checkEqual("actual", actualDocletWarnCount, "expected", expectedDocletWarnCount); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
94 |
checkEqual("actual", actualDocletWarnCount, "reported", reportedDocletWarnCount); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
95 |
} |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
96 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
97 |
void checkEqual(String l1, int i1, String l2, int i2) throws Exception { |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
98 |
if (i1 != i2) |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
99 |
throw new Exception(l1 + " warn count, " + i1 + ", does not match " |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
100 |
+ l2 + " warn count, " + i2); |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
101 |
} |
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
102 |
|
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
diff
changeset
|
103 |
} |