author | hseigel |
Wed, 02 Mar 2016 23:48:41 +0000 | |
changeset 36397 | c487ced7231c |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
1 |
/* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
4 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
8 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
14 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
18 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
22 |
*/ |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
23 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
24 |
/* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
25 |
* @test |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8071851 |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
27 |
* @summary Test the -Xdoclint/package option |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
29427
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.main |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
29 |
*/ |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
30 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
31 |
import java.io.File; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
32 |
import java.io.PrintWriter; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
33 |
import java.io.StringWriter; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
34 |
import java.net.URI; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
35 |
import java.util.Arrays; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
36 |
import java.util.List; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
37 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
38 |
import javax.tools.Diagnostic; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
39 |
import javax.tools.JavaCompiler; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
40 |
import javax.tools.JavaFileObject; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
41 |
import javax.tools.SimpleJavaFileObject; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
42 |
import javax.tools.StandardJavaFileManager; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
43 |
import javax.tools.StandardLocation; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
44 |
import javax.tools.ToolProvider; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
45 |
import static javax.tools.Diagnostic.Kind.*; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
46 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
47 |
import com.sun.source.util.JavacTask; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
48 |
import com.sun.tools.javac.main.Main; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
49 |
import java.util.ArrayList; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
50 |
import java.util.EnumSet; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
51 |
import java.util.Set; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
52 |
import java.util.regex.Matcher; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
53 |
import java.util.regex.Pattern; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
54 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
55 |
public class IncludePackagesTest { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
56 |
public static void main(String... args) throws Exception { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
57 |
new IncludePackagesTest().run(); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
58 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
59 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
60 |
JavaCompiler javac; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
61 |
StandardJavaFileManager fm; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
62 |
List<JavaFileObject> files; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
63 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
64 |
final String[] sources = new String[] { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
65 |
"p1/p1T.java", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
66 |
"package p1;\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
67 |
"/** Syntax < error. */\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
68 |
"public class p1T {\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
69 |
"}\n", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
70 |
"p1/sp1/p1sp1T.java", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
71 |
"package p1.sp1;\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
72 |
"/** Syntax < error. */\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
73 |
"public class p1sp1T {\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
74 |
"}\n", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
75 |
"p1/sp1/sp2/p1sp1sp2T.java", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
76 |
"package p1.sp1.sp2;\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
77 |
"/** Syntax < error. */\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
78 |
"public class p1sp1sp2T {\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
79 |
"}\n", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
80 |
"p2/p2T.java", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
81 |
"package p2;\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
82 |
"/** Syntax < error. */\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
83 |
"public class p2T {\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
84 |
"}\n", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
85 |
"Default.java", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
86 |
"/** Syntax < error. */\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
87 |
"public class Default {\n" + |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
88 |
"}\n", |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
89 |
}; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
90 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
91 |
final String rawDiags = "-XDrawDiagnostics"; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
92 |
private enum Message { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
93 |
// doclint messages |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
94 |
p1T(ERROR, "p1T.java:2:12: compiler.err.proc.messager: malformed HTML"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
95 |
p1sp1T(ERROR, "p1sp1T.java:2:12: compiler.err.proc.messager: malformed HTML"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
96 |
p1sp1sp2T(ERROR, "p1sp1sp2T.java:2:12: compiler.err.proc.messager: malformed HTML"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
97 |
p2T(ERROR, "p2T.java:2:12: compiler.err.proc.messager: malformed HTML"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
98 |
Default(ERROR, "Default.java:1:12: compiler.err.proc.messager: malformed HTML"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
99 |
INVALID_PACKAGE_ERROR(ERROR, "invalid flag: -Xdoclint/package:wrong+package"); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
100 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
101 |
final Diagnostic.Kind kind; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
102 |
final String text; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
103 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
104 |
static Message get(String text) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
105 |
for (Message m: values()) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
106 |
if (m.text.equals(text)) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
107 |
return m; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
108 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
109 |
return null; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
110 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
111 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
112 |
Message(Diagnostic.Kind kind, String text) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
113 |
this.kind = kind; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
114 |
this.text = text; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
115 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
116 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
117 |
@Override |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
118 |
public String toString() { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
119 |
return "[" + kind + ",\"" + text + "\"]"; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
120 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
121 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
122 |
void run() throws Exception { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
123 |
javac = ToolProvider.getSystemJavaCompiler(); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
124 |
fm = javac.getStandardFileManager(null, null, null); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
125 |
try { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
126 |
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File("."))); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
127 |
files = new ArrayList<>(); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
128 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
129 |
for (int si = 0; si < sources.length; si += 2) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
130 |
files.add(new JFOImpl(sources[si], sources[si + 1])); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
131 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
132 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
133 |
test(Arrays.asList(rawDiags, "-Xdoclint"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
134 |
Main.Result.ERROR, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
135 |
EnumSet.of(Message.p1T, Message.p1sp1T, Message.p1sp1sp2T, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
136 |
Message.p2T, Message.Default)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
137 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
138 |
test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:p1"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
139 |
Main.Result.ERROR, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
140 |
EnumSet.of(Message.p1T)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
141 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
142 |
test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:p1.*"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
143 |
Main.Result.ERROR, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
144 |
EnumSet.of(Message.p1sp1T, Message.p1sp1sp2T)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
145 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
146 |
test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:p1.*,-p1.sp1"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
147 |
Main.Result.ERROR, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
148 |
EnumSet.of(Message.p1sp1sp2T)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
149 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
150 |
test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:-p1.sp1"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
151 |
Main.Result.ERROR, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
152 |
EnumSet.of(Message.p1T, Message.p1sp1sp2T, Message.p2T, Message.Default)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
153 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
154 |
test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:wrong+package"), |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
155 |
Main.Result.CMDERR, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
156 |
EnumSet.of(Message.INVALID_PACKAGE_ERROR)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
157 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
158 |
if (errors > 0) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
159 |
throw new Exception(errors + " errors occurred"); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
160 |
} finally { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
161 |
fm.close(); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
162 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
163 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
164 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
165 |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
166 |
System.err.println("test: " + opts); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
167 |
StringWriter sw = new StringWriter(); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
168 |
PrintWriter pw = new PrintWriter(sw); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
169 |
try { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
170 |
JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
171 |
boolean ok = t.call(); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
172 |
pw.close(); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
173 |
String out = sw.toString().replaceAll("[\r\n]+", "\n"); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
174 |
if (!out.isEmpty()) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
175 |
System.err.println(out); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
176 |
if (ok && expectResult != Main.Result.OK) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
177 |
error("Compilation succeeded unexpectedly"); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
178 |
} else if (!ok && expectResult != Main.Result.ERROR) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
179 |
error("Compilation failed unexpectedly"); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
180 |
} else |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
181 |
check(out, expectMessages); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
182 |
} catch (IllegalArgumentException e) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
183 |
System.err.println(e); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
184 |
String expectOut = expectMessages.iterator().next().text; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
185 |
if (expectResult != Main.Result.CMDERR) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
186 |
error("unexpected exception caught"); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
187 |
else if (!e.getMessage().equals(expectOut)) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
188 |
error("unexpected exception message: " |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
189 |
+ e.getMessage() |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
190 |
+ " expected: " + expectOut); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
191 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
192 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
193 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
194 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
195 |
private void check(String out, Set<Message> expect) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
196 |
Pattern stats = Pattern.compile("^([1-9]+) (error|warning)(s?)"); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
197 |
Set<Message> found = EnumSet.noneOf(Message.class); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
198 |
int e = 0, w = 0; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
199 |
if (!out.isEmpty()) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
200 |
for (String line: out.split("[\r\n]+")) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
201 |
Matcher s = stats.matcher(line); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
202 |
if (s.matches()) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
203 |
int i = Integer.valueOf(s.group(1)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
204 |
if (s.group(2).equals("error")) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
205 |
e++; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
206 |
else |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
207 |
w++; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
208 |
continue; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
209 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
210 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
211 |
Message m = Message.get(line); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
212 |
if (m == null) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
213 |
error("Unexpected line: " + line); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
214 |
else |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
215 |
found.add(m); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
216 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
217 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
218 |
for (Message m: expect) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
219 |
if (!found.contains(m)) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
220 |
error("expected message not found: " + m.text); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
221 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
222 |
for (Message m: found) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
223 |
if (!expect.contains(m)) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
224 |
error("unexpected message found: " + m.text); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
225 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
226 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
227 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
228 |
void error(String msg) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
229 |
System.err.println("Error: " + msg); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
230 |
errors++; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
231 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
232 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
233 |
int errors; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
234 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
235 |
class JFOImpl extends SimpleJavaFileObject { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
236 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
237 |
private final String code; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
238 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
239 |
public JFOImpl(String fileName, String code) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
240 |
super(URI.create(fileName), JavaFileObject.Kind.SOURCE); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
241 |
this.code = code; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
242 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
243 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
244 |
@Override |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
245 |
public CharSequence getCharContent(boolean ignoreEncoding) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
246 |
return code; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
247 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
248 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
249 |
} |