author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 27579 | d1a63c99cdd5 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
15370 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
15370 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8006263 |
|
27 |
* @summary Supplementary test cases needed for doclint |
|
27579 | 28 |
* @library /tools/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.doclint |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.main |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
33 |
* jdk.compiler/com.sun.tools.javac.util |
27579 | 34 |
* @build ToolBox |
35 |
* @run main PathsTest |
|
15370 | 36 |
*/ |
37 |
||
27579 | 38 |
import com.sun.tools.javac.util.Context; |
39 |
import com.sun.tools.javac.file.JavacFileManager; |
|
15370 | 40 |
import com.sun.tools.doclint.DocLint; |
41 |
import com.sun.tools.doclint.DocLint.BadArgs; |
|
42 |
import java.io.File; |
|
43 |
import java.io.FileWriter; |
|
44 |
import java.io.IOException; |
|
45 |
import java.io.PrintWriter; |
|
46 |
import java.io.StringWriter; |
|
47 |
import java.util.regex.Pattern; |
|
27579 | 48 |
import javax.tools.StandardLocation; |
49 |
import javax.tools.JavaFileManager; |
|
15370 | 50 |
|
51 |
public class PathsTest { |
|
52 |
public static void main(String... args) throws Exception { |
|
53 |
new PathsTest().run(); |
|
54 |
} |
|
55 |
||
56 |
void run() throws Exception { |
|
57 |
String PS = File.pathSeparator; |
|
58 |
writeFile("src1/p/A.java", |
|
59 |
"package p; public class A { }"); |
|
60 |
compile("-d", "classes1", "src1/p/A.java"); |
|
61 |
||
62 |
writeFile("src2/q/B.java", |
|
63 |
"package q; public class B extends p.A { }"); |
|
64 |
compile("-d", "classes2", "-classpath", "classes1", "src2/q/B.java"); |
|
65 |
||
66 |
writeFile("src/Test.java", |
|
67 |
"/** &0; */ class Test extends q.B { }"); |
|
68 |
||
69 |
test("src/Test.java", "-sourcepath", "src1" + PS + "src2"); |
|
70 |
test("src/Test.java", "-classpath", "classes1" + PS + "classes2"); |
|
27579 | 71 |
|
72 |
File testJar = createJar(); |
|
15370 | 73 |
String sysBootClassPath = System.getProperty("sun.boot.class.path"); |
74 |
test("src/Test.java", "-bootclasspath", |
|
27579 | 75 |
testJar + PS + "classes1" + PS + "classes2"); |
15370 | 76 |
|
77 |
if (errors > 0) |
|
78 |
throw new Exception(errors + " errors found"); |
|
79 |
} |
|
80 |
||
81 |
Pattern pkgNotFound = Pattern.compile("package [a-z]+ does not exist"); |
|
82 |
Pattern badHtmlEntity = Pattern.compile("bad HTML entity"); |
|
83 |
||
84 |
void test(String file, String pathOpt, String path) throws BadArgs, IOException { |
|
85 |
System.err.println("test " + pathOpt); |
|
86 |
String out1 = doclint("-Xmsgs", file); |
|
87 |
if (!pkgNotFound.matcher(out1).find()) |
|
88 |
error("message not found: " + pkgNotFound); |
|
89 |
||
90 |
String out2 = doclint("-Xmsgs", pathOpt, path, file); |
|
91 |
if (pkgNotFound.matcher(out2).find()) |
|
92 |
error("unexpected message found: " + pkgNotFound); |
|
93 |
if (!badHtmlEntity.matcher(out1).find()) |
|
94 |
error("message not found: " + badHtmlEntity); |
|
95 |
||
96 |
try { |
|
97 |
doclint("-Xmsgs", pathOpt); |
|
98 |
error("expected exception not thrown"); |
|
99 |
} catch (BadArgs e) { |
|
100 |
System.err.println(e); |
|
101 |
} |
|
102 |
} |
|
103 |
||
27579 | 104 |
File createJar() throws IOException { |
105 |
File f = new File("test.jar"); |
|
106 |
try (JavaFileManager fm = new JavacFileManager(new Context(), false, null)) { |
|
107 |
ToolBox tb = new ToolBox(); |
|
108 |
tb.new JarTask(f.getPath()) |
|
109 |
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*") |
|
110 |
.run(); |
|
111 |
} |
|
112 |
return f; |
|
113 |
} |
|
114 |
||
15370 | 115 |
void compile(String... args) { |
116 |
for (int i = 0; i < args.length; i++) { |
|
117 |
if (args[i].equals("-d")) { |
|
118 |
new File(args[++i]).mkdirs(); |
|
119 |
break; |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
StringWriter sw = new StringWriter(); |
|
124 |
PrintWriter pw = new PrintWriter(sw); |
|
125 |
int rc = com.sun.tools.javac.Main.compile(args, pw); |
|
126 |
pw.close(); |
|
127 |
String out = sw.toString(); |
|
128 |
if (!out.isEmpty()) |
|
129 |
System.err.println(out); |
|
130 |
if (rc != 0) |
|
131 |
error("compilation failed: rc=" + rc); |
|
132 |
} |
|
133 |
||
134 |
String doclint(String... args) throws BadArgs, IOException { |
|
135 |
StringWriter sw = new StringWriter(); |
|
136 |
PrintWriter pw = new PrintWriter(sw); |
|
137 |
DocLint dl = new DocLint(); |
|
138 |
dl.run(pw, args); |
|
139 |
pw.close(); |
|
140 |
String out = sw.toString(); |
|
141 |
if (!out.isEmpty()) |
|
142 |
System.err.println(out); |
|
143 |
return out; |
|
144 |
} |
|
145 |
||
146 |
File writeFile(String path, String body) throws IOException { |
|
147 |
File f = new File(path); |
|
148 |
f.getParentFile().mkdirs(); |
|
149 |
try (FileWriter fw = new FileWriter(path)) { |
|
150 |
fw.write(body); |
|
151 |
} |
|
152 |
return f; |
|
153 |
} |
|
154 |
||
155 |
void error(String msg) { |
|
156 |
System.err.println("Error: " + msg); |
|
157 |
errors++; |
|
158 |
} |
|
159 |
||
160 |
int errors; |
|
161 |
} |