langtools/test/tools/jdeps/modules/GenModuleInfo.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 38530 8e89d567748c
child 41251 6112540cd0c1
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38530
diff changeset
    26
 * @summary Tests jdeps --gen-module-info option
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    27
 * @library ../lib
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    28
 * @build CompilerUtils JdepsUtil
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.jdeps
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @run testng GenModuleInfo
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.io.*;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.lang.module.ModuleDescriptor;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Paths;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.stream.Collectors;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.stream.Stream;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import org.testng.annotations.BeforeTest;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import org.testng.annotations.Test;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import static org.testng.Assert.assertEquals;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import static org.testng.Assert.assertTrue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
public class GenModuleInfo {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    private static final String MODULE_INFO = "module-info.class";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final String TEST_SRC = System.getProperty("test.src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private static final String TEST_CLASSES = System.getProperty("test.classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private static final Path MODS_DIR = Paths.get("mods");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    private static final Path LIBS_DIR = Paths.get("libs");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static final Path DEST_DIR = Paths.get("moduleinfosrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    private static final Path NEW_MODS_DIR = Paths.get("new_mods");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    // the names of the modules in this test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    private static final String UNSUPPORTED = "unsupported";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    private static String[] modules = new String[] {"m1", "m2", "m3", UNSUPPORTED};
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
     * Compiles all modules used by the test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    @BeforeTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    public void compileAll() throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        CompilerUtils.cleanDir(MODS_DIR);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        CompilerUtils.cleanDir(LIBS_DIR);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        CompilerUtils.cleanDir(DEST_DIR);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        CompilerUtils.cleanDir(NEW_MODS_DIR);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        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
    76
                                               "--add-exports", "java.base/jdk.internal.perf=" + UNSUPPORTED));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        Arrays.asList("m1", "m2", "m3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
              .forEach(mn -> assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, mn)));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        Files.createDirectory(LIBS_DIR);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        Files.createDirectory(DEST_DIR);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        for (String mn : modules) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            Path root = MODS_DIR.resolve(mn);
38529
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
    85
            try (Stream<Path> stream = Files.walk(root, Integer.MAX_VALUE)) {
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
    86
                Stream<Path> entries = stream.filter(f -> {
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
    87
                    String fn = f.getFileName().toString();
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
    88
                    return fn.endsWith(".class") && !fn.equals("module-info.class");
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
    89
                });
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
    90
                JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, entries);
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
    91
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
    public void jdeps() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        Stream<String> files = Arrays.stream(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .map(mn -> LIBS_DIR.resolve(mn + ".jar"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .map(Path::toString);
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   100
        JdepsUtil.jdeps(Stream.concat(Stream.of("-cp"), files).toArray(String[]::new));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
    public void test() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Stream<String> files = Arrays.stream(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                .map(mn -> LIBS_DIR.resolve(mn + ".jar"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                .map(Path::toString);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38530
diff changeset
   109
        JdepsUtil.jdeps(Stream.concat(Stream.of("--gen-module-info", DEST_DIR.toString()),
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38529
diff changeset
   110
                                      files).toArray(String[]::new));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        // check file exists
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        Arrays.stream(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                .map(mn -> DEST_DIR.resolve(mn).resolve("module-info.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .forEach(f -> assertTrue(Files.exists(f)));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        // copy classes except the original module-info.class
38529
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   118
        try (Stream<Path> stream = Files.walk(MODS_DIR, Integer.MAX_VALUE)) {
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   119
            stream.filter(path -> !path.getFileName().toString().equals(MODULE_INFO) &&
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   120
                                    path.getFileName().toString().endsWith(".class"))
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   121
                  .map(path -> MODS_DIR.relativize(path))
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   122
                  .forEach(path -> {
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   123
                      try {
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   124
                          Path newFile = NEW_MODS_DIR.resolve(path);
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   125
                          Files.createDirectories(newFile.getParent());
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   126
                          Files.copy(MODS_DIR.resolve(path), newFile);
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   127
                      } catch (IOException e) {
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   128
                          throw new UncheckedIOException(e);
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   129
                      }
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   130
                  });
58cf7e51c16d 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents: 38524
diff changeset
   131
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        // compile new module-info.java
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        assertTrue(CompilerUtils.compileModule(DEST_DIR, NEW_MODS_DIR, UNSUPPORTED,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38530
diff changeset
   135
                        "-p", NEW_MODS_DIR.toString(), "-verbose",
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38530
diff changeset
   136
                        "--add-exports", "java.base/jdk.internal.perf=" + UNSUPPORTED));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        Arrays.asList("m1", "m2", "m3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
              .forEach(mn -> assertTrue(CompilerUtils.compileModule(DEST_DIR, NEW_MODS_DIR,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38530
diff changeset
   139
                                        mn, "-p", NEW_MODS_DIR.toString())));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        for (String mn : modules) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            Path p1 = NEW_MODS_DIR.resolve(mn).resolve(MODULE_INFO);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            Path p2 = MODS_DIR.resolve(mn).resolve(MODULE_INFO);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            try (InputStream in1 = Files.newInputStream(p1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                 InputStream in2 = Files.newInputStream(p2)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                verify(ModuleDescriptor.read(in1),
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   148
                       ModuleDescriptor.read(in2, () -> packages(MODS_DIR.resolve(mn))));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    private void verify(ModuleDescriptor md1, ModuleDescriptor md2) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        System.out.println("verifying: " + md1.name());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        assertEquals(md1.name(), md2.name());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        assertEquals(md1.requires(), md2.requires());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        // all packages are exported
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        assertEquals(md1.exports().stream()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                                  .map(ModuleDescriptor.Exports::source)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                                  .collect(Collectors.toSet()), md2.packages());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    private Set<String> packages(Path dir) {
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38529
diff changeset
   164
        try (Stream<Path> stream = Files.find(dir, Integer.MAX_VALUE,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                             ((path, attrs) -> attrs.isRegularFile() &&
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38529
diff changeset
   166
                                               path.toString().endsWith(".class")))) {
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38529
diff changeset
   167
            return stream.map(path -> toPackageName(dir.relativize(path)))
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38529
diff changeset
   168
                         .filter(pkg -> pkg.length() > 0)   // module-info
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38529
diff changeset
   169
                         .distinct()
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38529
diff changeset
   170
                         .collect(Collectors.toSet());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        } catch (IOException x) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
            throw new UncheckedIOException(x);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    private String toPackageName(Path path) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        String name = path.toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        assert name.endsWith(".class");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        int index = name.lastIndexOf(File.separatorChar);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        if (index != -1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
            return name.substring(0, index).replace(File.separatorChar, '.');
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            return "";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
}