author | jjg |
Wed, 10 Aug 2016 15:47:46 -0700 | |
changeset 40308 | 274367a99f98 |
parent 38530 | 8e89d567748c |
child 42407 | f3702cff2933 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 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 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38530
diff
changeset
|
26 |
* @summary Tests jdeps -m and --module-path options on named modules and unnamed modules |
38524 | 27 |
* @library ../lib |
28 |
* @build CompilerUtils JdepsUtil |
|
36526 | 29 |
* @modules jdk.jdeps/com.sun.tools.jdeps |
30 |
* @run testng ModuleTest |
|
31 |
*/ |
|
32 |
||
38524 | 33 |
import java.io.File; |
34 |
import java.io.IOException; |
|
36526 | 35 |
|
38524 | 36 |
import java.nio.file.Files; |
36526 | 37 |
import java.nio.file.Path; |
38 |
import java.nio.file.Paths; |
|
39 |
import java.util.*; |
|
40 |
import java.util.stream.Collectors; |
|
41 |
||
38524 | 42 |
|
43 |
import com.sun.tools.jdeps.DepsAnalyzer; |
|
44 |
import com.sun.tools.jdeps.Graph; |
|
36526 | 45 |
import org.testng.annotations.DataProvider; |
46 |
import org.testng.annotations.BeforeTest; |
|
47 |
import org.testng.annotations.Test; |
|
48 |
||
49 |
import static org.testng.Assert.assertTrue; |
|
50 |
||
51 |
public class ModuleTest { |
|
52 |
private static final String TEST_SRC = System.getProperty("test.src"); |
|
53 |
private static final String TEST_CLASSES = System.getProperty("test.classes"); |
|
54 |
||
55 |
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
56 |
private static final Path MODS_DIR = Paths.get("mods"); |
|
38524 | 57 |
private static final Path UNNAMED_DIR = Paths.get("unnamed"); |
36526 | 58 |
|
59 |
// the names of the modules in this test |
|
60 |
private static final String UNSUPPORTED = "unsupported"; |
|
61 |
private static String[] modules = new String[] {"m1", "m2", "m3", "m4", UNSUPPORTED}; |
|
62 |
/** |
|
63 |
* Compiles all modules used by the test |
|
64 |
*/ |
|
65 |
@BeforeTest |
|
66 |
public void compileAll() throws Exception { |
|
67 |
CompilerUtils.cleanDir(MODS_DIR); |
|
38524 | 68 |
CompilerUtils.cleanDir(UNNAMED_DIR); |
69 |
||
36526 | 70 |
assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, UNSUPPORTED, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38530
diff
changeset
|
71 |
"--add-exports", "java.base/jdk.internal.perf=" + UNSUPPORTED)); |
36526 | 72 |
// m4 is not referenced |
73 |
Arrays.asList("m1", "m2", "m3", "m4") |
|
74 |
.forEach(mn -> assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, mn))); |
|
38524 | 75 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38530
diff
changeset
|
76 |
assertTrue(CompilerUtils.compile(SRC_DIR.resolve("m3"), UNNAMED_DIR, "-p", MODS_DIR.toString())); |
38524 | 77 |
Files.delete(UNNAMED_DIR.resolve("module-info.class")); |
36526 | 78 |
} |
79 |
||
80 |
@DataProvider(name = "modules") |
|
81 |
public Object[][] expected() { |
|
82 |
return new Object[][]{ |
|
38524 | 83 |
{ "m3", new ModuleMetaData("m3").requiresPublic("java.sql") |
84 |
.requiresPublic("m2") |
|
85 |
.requires("java.logging") |
|
86 |
.requiresPublic("m1") |
|
87 |
.reference("p3", "java.lang", "java.base") |
|
88 |
.reference("p3", "java.sql", "java.sql") |
|
89 |
.reference("p3", "java.util.logging", "java.logging") |
|
90 |
.reference("p3", "p1", "m1") |
|
91 |
.reference("p3", "p2", "m2") |
|
92 |
.qualified("p3", "p2.internal", "m2") |
|
36526 | 93 |
}, |
38524 | 94 |
{ "m2", new ModuleMetaData("m2").requiresPublic("m1") |
95 |
.reference("p2", "java.lang", "java.base") |
|
96 |
.reference("p2", "p1", "m1") |
|
97 |
.reference("p2.internal", "java.lang", "java.base") |
|
98 |
.reference("p2.internal", "java.io", "java.base") |
|
36526 | 99 |
}, |
38524 | 100 |
{ "m1", new ModuleMetaData("m1").requires("unsupported") |
101 |
.reference("p1", "java.lang", "java.base") |
|
102 |
.reference("p1.internal", "java.lang", "java.base") |
|
103 |
.reference("p1.internal", "p1", "m1") |
|
104 |
.reference("p1.internal", "q", "unsupported") |
|
36526 | 105 |
}, |
38524 | 106 |
{ "unsupported", new ModuleMetaData("unsupported") |
107 |
.reference("q", "java.lang", "java.base") |
|
108 |
.jdkInternal("q", "jdk.internal.perf", "java.base") |
|
36526 | 109 |
}, |
110 |
}; |
|
111 |
} |
|
112 |
||
113 |
@Test(dataProvider = "modules") |
|
38524 | 114 |
public void modularTest(String name, ModuleMetaData data) throws IOException { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38530
diff
changeset
|
115 |
// jdeps --module-path mods -m <name> |
38524 | 116 |
runTest(data, MODS_DIR.toString(), Set.of(name)); |
117 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38530
diff
changeset
|
118 |
// jdeps --module-path libs/m1.jar:.... -m <name> |
38524 | 119 |
String mp = Arrays.stream(modules) |
120 |
.filter(mn -> !mn.equals(name)) |
|
121 |
.map(mn -> MODS_DIR.resolve(mn).toString()) |
|
122 |
.collect(Collectors.joining(File.pathSeparator)); |
|
123 |
runTest(data, mp, Collections.emptySet(), MODS_DIR.resolve(name)); |
|
36526 | 124 |
} |
125 |
||
126 |
@DataProvider(name = "unnamed") |
|
127 |
public Object[][] unnamed() { |
|
128 |
return new Object[][]{ |
|
38524 | 129 |
{ "unnamed", new ModuleMetaData("unnamed", false) |
36526 | 130 |
.depends("java.sql") |
131 |
.depends("java.logging") |
|
132 |
.depends("m1") |
|
133 |
.depends("m2") |
|
134 |
.reference("p3", "java.lang", "java.base") |
|
135 |
.reference("p3", "java.sql", "java.sql") |
|
136 |
.reference("p3", "java.util.logging", "java.logging") |
|
137 |
.reference("p3", "p1", "m1") |
|
138 |
.reference("p3", "p2", "m2") |
|
139 |
.internal("p3", "p2.internal", "m2") |
|
140 |
}, |
|
141 |
}; |
|
142 |
} |
|
143 |
||
144 |
@Test(dataProvider = "unnamed") |
|
38524 | 145 |
public void unnamedTest(String name, ModuleMetaData data) throws IOException { |
146 |
runTest(data, MODS_DIR.toString(), Set.of("m1", "m2"), UNNAMED_DIR); |
|
36526 | 147 |
} |
148 |
||
38524 | 149 |
private void runTest(ModuleMetaData data, String modulepath, |
150 |
Set<String> roots, Path... paths) |
|
151 |
throws IOException |
|
152 |
{ |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38530
diff
changeset
|
153 |
// jdeps --module-path <modulepath> -m root paths |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38530
diff
changeset
|
154 |
String cmd = String.format("jdeps --module-path %s --add-modules %s %s%n", |
38530 | 155 |
MODS_DIR, roots.stream().collect(Collectors.joining(",")), paths); |
36526 | 156 |
|
38530 | 157 |
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) { |
158 |
jdeps.appModulePath(modulepath) |
|
159 |
.addmods(roots); |
|
160 |
Arrays.stream(paths).forEach(jdeps::addRoot); |
|
36526 | 161 |
|
38530 | 162 |
// run the analyzer |
163 |
DepsAnalyzer analyzer = jdeps.getDepsAnalyzer(); |
|
164 |
assertTrue(analyzer.run()); |
|
36526 | 165 |
|
38530 | 166 |
// analyze result |
167 |
Graph<DepsAnalyzer.Node> g1 = analyzer.moduleGraph(); |
|
168 |
g1.nodes().stream() |
|
169 |
.filter(u -> u.name.equals(data.moduleName)) |
|
170 |
.forEach(u -> data.checkRequires(u.name, g1.adjacentNodes(u))); |
|
36526 | 171 |
|
38530 | 172 |
Graph<DepsAnalyzer.Node> g2 = analyzer.dependenceGraph(); |
173 |
g2.nodes().stream() |
|
174 |
.filter(u -> u.name.equals(data.moduleName)) |
|
175 |
.forEach(u -> data.checkDependences(u.name, g2.adjacentNodes(u))); |
|
36526 | 176 |
|
38530 | 177 |
jdeps.dumpOutput(System.err); |
178 |
} |
|
36526 | 179 |
} |
180 |
} |