author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
|
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 |
* @summary simple tests of javac compilation modes |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
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.JarTask toolbox.JavacTask ModuleTestBase |
36526 | 32 |
* @run main HelloWorldTest |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.*; |
|
36 |
import javax.tools.*; |
|
37 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
38 |
import toolbox.JarTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
39 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
|
36526 | 43 |
public class HelloWorldTest extends ModuleTestBase { |
44 |
public static void main(String... args) throws Exception { |
|
45 |
HelloWorldTest t = new HelloWorldTest(); |
|
46 |
t.runTests(); |
|
47 |
} |
|
48 |
||
49 |
public static final String HELLO_WORLD = |
|
50 |
"class HelloWorld {\n" |
|
51 |
+ " public static void main(String... args) {\n" |
|
52 |
+ " System.out.println(\"Hello World!\");\n" |
|
53 |
+ " }\n" |
|
54 |
+ "}"; |
|
55 |
||
56 |
public static final String PKG_HELLO_WORLD = |
|
57 |
"package p;\n" |
|
58 |
+ HELLO_WORLD; |
|
59 |
||
60 |
@Test |
|
37758 | 61 |
public void testLegacyMode(Path base) throws Exception { |
36526 | 62 |
Path src = base.resolve("src"); |
63 |
tb.writeJavaFiles(src, HELLO_WORLD); |
|
64 |
||
65 |
Path classes = base.resolve("classes"); |
|
66 |
Files.createDirectories(classes); |
|
67 |
||
68 |
Path smallRtJar = base.resolve("small-rt.jar"); |
|
69 |
try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) { |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
70 |
new JarTask(tb, smallRtJar) |
36526 | 71 |
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, |
72 |
"java.lang.**", "java.io.*", "java.util.*") |
|
73 |
.run(); |
|
74 |
} |
|
75 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
76 |
new JavacTask(tb) |
36526 | 77 |
.options("-source", "8", |
78 |
"-target", "8", |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
79 |
"--boot-class-path", smallRtJar.toString()) |
36526 | 80 |
.outdir(classes) |
81 |
.files(src.resolve("HelloWorld.java")) |
|
82 |
.run(); |
|
83 |
||
84 |
checkFiles(classes.resolve("HelloWorld.class")); |
|
85 |
} |
|
86 |
||
87 |
@Test |
|
37758 | 88 |
public void testUnnamedModule(Path base) throws Exception { |
36526 | 89 |
Path src = base.resolve("src"); |
90 |
tb.writeJavaFiles(src, HELLO_WORLD); |
|
91 |
||
92 |
Path classes = base.resolve("classes"); |
|
93 |
Files.createDirectories(classes); |
|
94 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
95 |
new JavacTask(tb) |
36526 | 96 |
.outdir(classes) |
97 |
.files(src.resolve("HelloWorld.java")) |
|
98 |
.run(); |
|
99 |
||
100 |
checkFiles(classes.resolve("HelloWorld.class")); |
|
101 |
} |
|
102 |
||
103 |
@Test |
|
37758 | 104 |
public void testSingleModule(Path base) throws Exception { |
36526 | 105 |
Path src = base.resolve("src"); |
106 |
tb.writeFile(src.resolve("module-info.java"), "module m { }"); |
|
107 |
tb.writeJavaFiles(src, PKG_HELLO_WORLD); |
|
108 |
||
109 |
Path classes = base.resolve("classes"); |
|
110 |
Files.createDirectories(classes); |
|
111 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
112 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 113 |
.outdir(classes) |
114 |
.files(src.resolve("module-info.java"), src.resolve("p/HelloWorld.java")) |
|
115 |
.run() |
|
116 |
.writeAll(); |
|
117 |
||
118 |
checkFiles( |
|
119 |
classes.resolve("module-info.class"), |
|
120 |
classes.resolve("p/HelloWorld.class")); |
|
121 |
} |
|
122 |
||
123 |
@Test |
|
37758 | 124 |
public void testModuleSourcePath(Path base) throws Exception { |
36526 | 125 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
126 |
Path src_m = src.resolve("m"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
127 |
tb.writeFile(src_m.resolve("module-info.java"), "module m { }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
128 |
tb.writeJavaFiles(src_m, PKG_HELLO_WORLD); |
36526 | 129 |
|
130 |
Path classes = base.resolve("classes"); |
|
131 |
Files.createDirectories(classes); |
|
132 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
133 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
134 |
.options("--module-source-path", src.toString()) |
36526 | 135 |
.outdir(classes) |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
136 |
.files(src_m.resolve("p/HelloWorld.java")) |
36526 | 137 |
.run() |
138 |
.writeAll(); |
|
139 |
||
140 |
checkFiles( |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
141 |
classes.resolve("m/module-info.class"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
142 |
classes.resolve("m/p/HelloWorld.class")); |
36526 | 143 |
} |
144 |
||
145 |
void checkFiles(Path... files) throws Exception { |
|
146 |
for (Path f: files) { |
|
147 |
if (!Files.exists(f)) |
|
148 |
throw new Exception("expected file not found: " + f); |
|
149 |
} |
|
150 |
} |
|
151 |
} |