langtools/test/tools/jdeps/modules/ModuleTest.java
changeset 40308 274367a99f98
parent 38530 8e89d567748c
child 42407 f3702cff2933
equal deleted inserted replaced
40306:1a0fcaf3f2ed 40308:274367a99f98
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @summary Tests jdeps -m and -mp options on named modules and unnamed modules
    26  * @summary Tests jdeps -m and --module-path options on named modules and unnamed modules
    27  * @library ../lib
    27  * @library ../lib
    28  * @build CompilerUtils JdepsUtil
    28  * @build CompilerUtils JdepsUtil
    29  * @modules jdk.jdeps/com.sun.tools.jdeps
    29  * @modules jdk.jdeps/com.sun.tools.jdeps
    30  * @run testng ModuleTest
    30  * @run testng ModuleTest
    31  */
    31  */
    66     public void compileAll() throws Exception {
    66     public void compileAll() throws Exception {
    67         CompilerUtils.cleanDir(MODS_DIR);
    67         CompilerUtils.cleanDir(MODS_DIR);
    68         CompilerUtils.cleanDir(UNNAMED_DIR);
    68         CompilerUtils.cleanDir(UNNAMED_DIR);
    69 
    69 
    70         assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, UNSUPPORTED,
    70         assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, UNSUPPORTED,
    71                                                "-XaddExports:java.base/jdk.internal.perf=" + UNSUPPORTED));
    71                                                "--add-exports", "java.base/jdk.internal.perf=" + UNSUPPORTED));
    72         // m4 is not referenced
    72         // m4 is not referenced
    73         Arrays.asList("m1", "m2", "m3", "m4")
    73         Arrays.asList("m1", "m2", "m3", "m4")
    74               .forEach(mn -> assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, mn)));
    74               .forEach(mn -> assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, mn)));
    75 
    75 
    76         assertTrue(CompilerUtils.compile(SRC_DIR.resolve("m3"), UNNAMED_DIR, "-mp", MODS_DIR.toString()));
    76         assertTrue(CompilerUtils.compile(SRC_DIR.resolve("m3"), UNNAMED_DIR, "-p", MODS_DIR.toString()));
    77         Files.delete(UNNAMED_DIR.resolve("module-info.class"));
    77         Files.delete(UNNAMED_DIR.resolve("module-info.class"));
    78     }
    78     }
    79 
    79 
    80     @DataProvider(name = "modules")
    80     @DataProvider(name = "modules")
    81     public Object[][] expected() {
    81     public Object[][] expected() {
   110         };
   110         };
   111     }
   111     }
   112 
   112 
   113     @Test(dataProvider = "modules")
   113     @Test(dataProvider = "modules")
   114     public void modularTest(String name, ModuleMetaData data) throws IOException {
   114     public void modularTest(String name, ModuleMetaData data) throws IOException {
   115         // jdeps -modulepath mods -m <name>
   115         // jdeps --module-path mods -m <name>
   116         runTest(data, MODS_DIR.toString(), Set.of(name));
   116         runTest(data, MODS_DIR.toString(), Set.of(name));
   117 
   117 
   118         // jdeps -modulepath libs/m1.jar:.... -m <name>
   118         // jdeps --module-path libs/m1.jar:.... -m <name>
   119         String mp = Arrays.stream(modules)
   119         String mp = Arrays.stream(modules)
   120                 .filter(mn -> !mn.equals(name))
   120                 .filter(mn -> !mn.equals(name))
   121                 .map(mn -> MODS_DIR.resolve(mn).toString())
   121                 .map(mn -> MODS_DIR.resolve(mn).toString())
   122                 .collect(Collectors.joining(File.pathSeparator));
   122                 .collect(Collectors.joining(File.pathSeparator));
   123         runTest(data, mp, Collections.emptySet(), MODS_DIR.resolve(name));
   123         runTest(data, mp, Collections.emptySet(), MODS_DIR.resolve(name));
   148 
   148 
   149     private void runTest(ModuleMetaData data, String modulepath,
   149     private void runTest(ModuleMetaData data, String modulepath,
   150                          Set<String> roots, Path... paths)
   150                          Set<String> roots, Path... paths)
   151         throws IOException
   151         throws IOException
   152     {
   152     {
   153         // jdeps -modulepath <modulepath> -m root paths
   153         // jdeps --module-path <modulepath> -m root paths
   154         String cmd = String.format("jdeps -modulepath %s -addmods %s %s%n",
   154         String cmd = String.format("jdeps --module-path %s --add-modules %s %s%n",
   155             MODS_DIR, roots.stream().collect(Collectors.joining(",")), paths);
   155             MODS_DIR, roots.stream().collect(Collectors.joining(",")), paths);
   156 
   156 
   157         try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
   157         try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
   158             jdeps.appModulePath(modulepath)
   158             jdeps.appModulePath(modulepath)
   159                 .addmods(roots);
   159                 .addmods(roots);