< prev index next >
test/langtools/tools/jdeps/listdeps/ListModuleDeps.java
Print this page
*** 33,45 ****
--- 33,47 ----
* @library ../lib
* @build CompilerUtils JdepsRunner
* @run testng ListModuleDeps
*/
+ import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
+ import java.util.List;
import java.util.stream.Collectors;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
*** 51,60 ****
--- 53,63 ----
private static final String TEST_SRC = System.getProperty("test.src");
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path CLASSES_DIR = Paths.get("classes");
private static final Path LIB_DIR = Paths.get("lib");
+ private static final Path LIB2_DIR = Paths.get("lib2");
private static final Path HI_CLASS =
CLASSES_DIR.resolve("hi").resolve("Hi.class");
private static final Path FOO_CLASS =
CLASSES_DIR.resolve("z").resolve("Foo.class");
*** 67,77 ****
* Compiles classes used by the test
*/
@BeforeTest
public void compileAll() throws Exception {
// compile library
! assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "lib"), LIB_DIR));
// simple program depends only on java.base
assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "hi"), CLASSES_DIR));
// compile classes in unnamed module
--- 70,81 ----
* Compiles classes used by the test
*/
@BeforeTest
public void compileAll() throws Exception {
// compile library
! assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "lib2"), LIB2_DIR));
! assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "lib"), LIB_DIR, "-cp", LIB2_DIR.toString()));
// simple program depends only on java.base
assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "hi"), CLASSES_DIR));
// compile classes in unnamed module
*** 109,119 ****
}
@Test(dataProvider = "listdeps")
public void testListDeps(Path classes, String[] expected) {
JdepsRunner jdeps = JdepsRunner.run(
! "--class-path", LIB_DIR.toString(),
"--list-deps", classes.toString()
);
String[] output = Arrays.stream(jdeps.output())
.map(s -> s.trim())
.toArray(String[]::new);
--- 113,123 ----
}
@Test(dataProvider = "listdeps")
public void testListDeps(Path classes, String[] expected) {
JdepsRunner jdeps = JdepsRunner.run(
! "--class-path", LIB_DIR.toString() + File.pathSeparator + LIB2_DIR.toString(),
"--list-deps", classes.toString()
);
String[] output = Arrays.stream(jdeps.output())
.map(s -> s.trim())
.toArray(String[]::new);
*** 121,131 ****
}
@Test(dataProvider = "reduceddeps")
public void testListReducedDeps(Path classes, String[] expected) {
JdepsRunner jdeps = JdepsRunner.run(
! "--class-path", LIB_DIR.toString(),
"--list-reduced-deps", classes.toString()
);
String[] output = Arrays.stream(jdeps.output())
.map(s -> s.trim())
.toArray(String[]::new);
--- 125,135 ----
}
@Test(dataProvider = "reduceddeps")
public void testListReducedDeps(Path classes, String[] expected) {
JdepsRunner jdeps = JdepsRunner.run(
! "--class-path", LIB_DIR.toString() + File.pathSeparator + LIB2_DIR.toString(),
"--list-reduced-deps", classes.toString()
);
String[] output = Arrays.stream(jdeps.output())
.map(s -> s.trim())
.toArray(String[]::new);
*** 138,147 ****
--- 142,152 ----
return new Object[][] {
{ CLASSES_DIR, new String[] {
"java.base/jdk.internal.misc",
"java.base/sun.security.util",
"java.logging",
+ "java.management",
"java.sql",
"java.xml/jdk.xml.internal",
"jdk.unsupported"
}
},
*** 152,161 ****
--- 157,167 ----
},
{ FOO_CLASS, new String[] {
"java.base",
"java.logging",
+ "java.management",
"java.sql",
"java.xml"
}
},
*** 179,188 ****
--- 185,195 ----
return new Object[][] {
{ CLASSES_DIR, new String[] {
"java.base/jdk.internal.misc",
"java.base/sun.security.util",
+ "java.management",
"java.sql",
"java.xml/jdk.xml.internal",
"jdk.unsupported"
}
},
*** 192,201 ****
--- 199,209 ----
}
},
{ FOO_CLASS, new String[] {
"java.base",
+ "java.management",
"java.sql"
}
},
{ BAR_CLASS, new String[] {
*** 213,223 ****
}
@Test(dataProvider = "moduledeps")
public void testPrintModuleDeps(Path classes, String expected) {
JdepsRunner jdeps = JdepsRunner.run(
! "--class-path", LIB_DIR.toString(),
"--print-module-deps", classes.toString()
);
String output = Arrays.stream(jdeps.output())
.map(s -> s.trim())
.collect(Collectors.joining(","));
--- 221,231 ----
}
@Test(dataProvider = "moduledeps")
public void testPrintModuleDeps(Path classes, String expected) {
JdepsRunner jdeps = JdepsRunner.run(
! "--class-path", LIB_DIR.toString() + File.pathSeparator + LIB2_DIR.toString(),
"--print-module-deps", classes.toString()
);
String output = Arrays.stream(jdeps.output())
.map(s -> s.trim())
.collect(Collectors.joining(","));
*** 229,241 ****
public Object[][] moduledeps() {
Path barClass = CLASSES_DIR.resolve("z").resolve("Bar.class");
return new Object[][] {
// java.xml is an implied reads edge from java.sql
! { CLASSES_DIR, "java.base,java.sql,jdk.unsupported"},
{ HI_CLASS, "java.base"},
! { FOO_CLASS, "java.base,java.sql"},
{ BAR_CLASS, "java.base,java.xml"},
{ UNSAFE_CLASS, "java.base,jdk.unsupported"},
};
}
}
--- 237,292 ----
public Object[][] moduledeps() {
Path barClass = CLASSES_DIR.resolve("z").resolve("Bar.class");
return new Object[][] {
// java.xml is an implied reads edge from java.sql
! { CLASSES_DIR, "java.base,java.management,java.sql,jdk.unsupported"},
{ HI_CLASS, "java.base"},
! { FOO_CLASS, "java.base,java.management,java.sql"},
{ BAR_CLASS, "java.base,java.xml"},
{ UNSAFE_CLASS, "java.base,jdk.unsupported"},
};
}
+
+ @DataProvider(name = "recursiveDeps")
+ public Object[][] recursiveDeps() {
+ return new Object[][] {
+ { // lib2 is classpath but not analyzed because lib.Lib is not present
+ // but it is the only class depending on lib2.Lib2
+ List.of("--list-deps", "--class-path", LIB2_DIR.toString(),
+ "--ignore-missing-deps", CLASSES_DIR.toString()),
+ new String[] {
+ "java.base/jdk.internal.misc",
+ "java.base/sun.security.util",
+ "java.logging",
+ "java.sql",
+ "java.xml/jdk.xml.internal",
+ "jdk.unsupported"
+ }
+ },
+ { // lib2 is classpath but not analyzed because lib.Lib is not present
+ // but it is the only class depending on lib2.Lib2
+ List.of("--print-module-deps", "--class-path", LIB2_DIR.toString(),
+ "--ignore-missing-deps", CLASSES_DIR.toString()),
+ new String[] {
+ "java.base,java.sql,jdk.unsupported"
+ }
+ },
+ { // Foo depends on lib.Lib which depends on lib2.Libs
+ List.of("--print-module-deps",
+ "--ignore-missing-deps", FOO_CLASS.toString()),
+ new String[] {
+ "java.base,java.sql"
+ }
+ },
+ };
+ }
+
+ @Test(dataProvider = "recursiveDeps")
+ public void testRecursiveDeps(List<String> options, String[] expected) {
+ JdepsRunner jdeps = JdepsRunner.run(options.toArray(new String[0]));
+ String[] output = Arrays.stream(jdeps.output())
+ .map(s -> s.trim())
+ .toArray(String[]::new);
+ assertEquals(output, expected);
+ }
}
< prev index next >