author | jjg |
Thu, 31 Mar 2016 15:20:50 -0700 | |
changeset 36778 | e04318f39f92 |
parent 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
6577 | 1 |
/* |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
6577 | 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 6604599 |
|
27 |
* @summary ToolProvider should be less compiler-specific |
|
26100 | 28 |
* @library /tools/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JavaTask |
22149
c7e024d637bf
8028708: TEST_BUG, Tests should pass through VM options, langtools tests
vromero
parents:
6577
diff
changeset
|
32 |
* @run main HelloWorldTest |
6577 | 33 |
*/ |
34 |
||
22149
c7e024d637bf
8028708: TEST_BUG, Tests should pass through VM options, langtools tests
vromero
parents:
6577
diff
changeset
|
35 |
import java.util.Arrays; |
6577 | 36 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
37 |
import toolbox.JavaTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
38 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
39 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
|
6577 | 41 |
// verify that running a simple program, such as this one, does not trigger |
42 |
// the loading of ToolProvider or any com.sun.tools.javac class |
|
43 |
public class HelloWorldTest { |
|
44 |
public static void main(String... args) throws Exception { |
|
45 |
if (args.length > 0) { |
|
26100 | 46 |
System.err.println(Arrays.toString(args)); |
6577 | 47 |
return; |
48 |
} |
|
49 |
||
50 |
new HelloWorldTest().run(); |
|
51 |
} |
|
52 |
||
53 |
void run() throws Exception { |
|
26100 | 54 |
ToolBox tb = new ToolBox(); |
55 |
||
6577 | 56 |
String classpath = System.getProperty("java.class.path"); |
57 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
58 |
Task.Result tr = new JavaTask(tb) |
26100 | 59 |
.vmOptions("-verbose:class") |
60 |
.classpath(classpath) |
|
61 |
.className(HelloWorldTest.class.getName()) |
|
62 |
.classArgs("Hello", "World") |
|
63 |
.run(); |
|
6577 | 64 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
65 |
if (tr.getOutput(Task.OutputKind.STDOUT).contains("java.lang.Object")) { |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
66 |
for (String line : tr.getOutputLines(Task.OutputKind.STDOUT)) { |
26100 | 67 |
System.err.println(line); |
68 |
if (line.contains("javax.tools.ToolProvider") || line.contains("com.sun.tools.javac.")) |
|
69 |
error(">>> " + line); |
|
70 |
} |
|
71 |
} else { |
|
72 |
tr.writeAll(); |
|
73 |
error("verbose output not as expected"); |
|
6577 | 74 |
} |
75 |
||
76 |
if (errors > 0) |
|
77 |
throw new Exception(errors + " errors occurred"); |
|
78 |
} |
|
79 |
||
80 |
void error(String msg) { |
|
81 |
System.err.println(msg); |
|
82 |
errors++; |
|
83 |
} |
|
84 |
||
85 |
int errors; |
|
86 |
} |