author | jlahoda |
Mon, 22 Aug 2016 09:59:43 +0200 | |
changeset 40513 | 39b67170b045 |
parent 40308 | 274367a99f98 |
child 41992 | 720257f5307d |
permissions | -rw-r--r-- |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
1 |
/* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
4 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
8 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
14 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
18 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
21 |
* questions. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
22 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
23 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
24 |
/* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
25 |
* @test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
26 |
* @bug 8160489 |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
27 |
* @summary tests for --patch-modules |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
28 |
* @library /tools/lib |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
29 |
* @modules |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.file |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.main |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
33 |
* @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
34 |
* @run main PatchModulesTest |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
35 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
36 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
37 |
import java.io.File; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
38 |
import java.io.IOException; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
39 |
import java.io.PrintWriter; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
40 |
import java.io.StringWriter; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
41 |
import java.lang.reflect.Field; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
42 |
import java.nio.file.Path; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
43 |
import java.nio.file.Paths; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
44 |
import java.util.List; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
45 |
import java.util.Map; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
46 |
import java.util.stream.Collectors; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
47 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
48 |
import javax.tools.JavaFileObject; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
49 |
import javax.tools.ToolProvider; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
50 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
51 |
import com.sun.source.util.JavacTask; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
52 |
import com.sun.tools.javac.api.JavacTool; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
53 |
import com.sun.tools.javac.file.BaseFileManager; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
54 |
import com.sun.tools.javac.file.JavacFileManager; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
55 |
import com.sun.tools.javac.file.Locations; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
56 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
57 |
import static java.util.Arrays.asList; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
58 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
59 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
60 |
public class PatchModulesTest extends ModuleTestBase { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
61 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
62 |
public static void main(String... args) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
63 |
PatchModulesTest t = new PatchModulesTest(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
64 |
t.init(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
65 |
t.runTests(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
66 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
67 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
68 |
private static String PS = File.pathSeparator; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
69 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
70 |
void init() throws IOException { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
71 |
tb.createDirectories("a", "b", "c", "d", "e"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
72 |
tb.writeJavaFiles(Paths.get("."), "class C { }"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
73 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
74 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
75 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
76 |
public void testSimple(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
77 |
test(asList("java.base=a"), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
78 |
"{java.base=[a]}"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
79 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
80 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
81 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
82 |
public void testPair(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
83 |
test(asList("java.base=a", "java.compiler=b"), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
84 |
"{java.base=[a], java.compiler=[b]}"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
85 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
86 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
87 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
88 |
public void testMultiple(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
89 |
test(asList("java.base=a:b"), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
90 |
"{java.base=[a, b]}"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
91 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
92 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
93 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
94 |
public void testLastOneWins(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
95 |
test(asList("java.base=a", "java.compiler=b", "java.base=c"), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
96 |
"{java.base=[c], java.compiler=[b]}"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
97 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
98 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
99 |
void test(List<String> patches, String expect) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
100 |
JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
101 |
StringWriter sw = new StringWriter(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
102 |
try (PrintWriter pw = new PrintWriter(sw)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
103 |
JavacFileManager fm = tool.getStandardFileManager(null, null, null); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
104 |
List<String> opts = patches.stream() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
105 |
.map(p -> "--patch-module=" + p.replace(":", PS)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
106 |
.collect(Collectors.toList()); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
107 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects("C.java"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
108 |
JavacTask task = tool.getTask(pw, fm, null, opts, null, files); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
109 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
110 |
Field locationsField = BaseFileManager.class.getDeclaredField("locations"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
111 |
locationsField.setAccessible(true); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
112 |
Object locations = locationsField.get(fm); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
113 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
114 |
Field patchMapField = Locations.class.getDeclaredField("patchMap"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
115 |
patchMapField.setAccessible(true); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
116 |
Map<?,?> patchMap = (Map<?,?>) patchMapField.get(locations); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
117 |
String found = patchMap.toString(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
118 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
119 |
if (!found.equals(expect)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
120 |
tb.out.println("Expect: " + expect); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
121 |
tb.out.println("Found: " + found); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
122 |
error("output not as expected"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
123 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
124 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
125 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
126 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
127 |