# HG changeset patch # User mchung # Date 1463704445 25200 # Node ID 58cf7e51c16dfa877e8cf17b88f1414b22634a39 # Parent 0bd2b31e70211f350895493324fbd64aa8b02c19 8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows Reviewed-by: jjg diff -r 0bd2b31e7021 -r 58cf7e51c16d langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ClassFileReader.java --- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ClassFileReader.java Thu May 19 20:14:16 2016 +0000 +++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ClassFileReader.java Thu May 19 17:34:05 2016 -0700 @@ -48,6 +48,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * ClassFileReader reads ClassFile(s) of a given path that can be @@ -58,7 +59,7 @@ * Returns a ClassFileReader instance of a given path. */ public static ClassFileReader newInstance(Path path) throws IOException { - if (!Files.exists(path)) { + if (Files.notExists(path)) { throw new FileNotFoundException(path.toString()); } @@ -218,13 +219,12 @@ } protected Set scan() { - try { - return Files.walk(path, Integer.MAX_VALUE) - .filter(ClassFileReader::isClass) - .map(f -> path.relativize(f)) - .map(Path::toString) - .map(p -> p.replace(File.separatorChar, '/')) - .collect(Collectors.toSet()); + try (Stream stream = Files.walk(path, Integer.MAX_VALUE)) { + return stream.filter(ClassFileReader::isClass) + .map(f -> path.relativize(f)) + .map(Path::toString) + .map(p -> p.replace(File.separatorChar, '/')) + .collect(Collectors.toSet()); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -235,7 +235,7 @@ int i = name.lastIndexOf('.'); String pathname = name.replace(".", fsSep) + ".class"; Path p = path.resolve(pathname); - if (!Files.exists(p)) { + if (Files.notExists(p)) { p = path.resolve(pathname.substring(0, i) + "$" + pathname.substring(i+1, pathname.length())); } @@ -261,13 +261,16 @@ } class DirectoryIterator implements Iterator { - private List entries; + private final List entries; private int index = 0; DirectoryIterator() throws IOException { - entries = Files.walk(path, Integer.MAX_VALUE) - .filter(ClassFileReader::isClass) - .collect(Collectors.toList()); - index = 0; + List paths = null; + try (Stream stream = Files.walk(path, Integer.MAX_VALUE)) { + paths = stream.filter(ClassFileReader::isClass) + .collect(Collectors.toList()); + } + this.entries = paths; + this.index = 0; } public boolean hasNext() { diff -r 0bd2b31e7021 -r 58cf7e51c16d langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java --- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java Thu May 19 20:14:16 2016 +0000 +++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java Thu May 19 17:34:05 2016 -0700 @@ -348,12 +348,11 @@ } private Map walk(Path root) { - try { - return Files.walk(root, 1) - .filter(path -> !path.equals(root)) - .map(this::toModuleReference) - .collect(toMap(mref -> mref.descriptor().name(), - Function.identity())); + try (Stream stream = Files.walk(root, 1)) { + return stream.filter(path -> !path.equals(root)) + .map(this::toModuleReference) + .collect(toMap(mref -> mref.descriptor().name(), + Function.identity())); } catch (IOException e) { throw new UncheckedIOException(e); } diff -r 0bd2b31e7021 -r 58cf7e51c16d langtools/test/tools/jdeps/modules/GenModuleInfo.java --- a/langtools/test/tools/jdeps/modules/GenModuleInfo.java Thu May 19 20:14:16 2016 +0000 +++ b/langtools/test/tools/jdeps/modules/GenModuleInfo.java Thu May 19 17:34:05 2016 -0700 @@ -82,12 +82,13 @@ for (String mn : modules) { Path root = MODS_DIR.resolve(mn); - JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, - Files.walk(root, Integer.MAX_VALUE) - .filter(f -> { - String fn = f.getFileName().toString(); - return fn.endsWith(".class") && !fn.equals("module-info.class"); - })); + try (Stream stream = Files.walk(root, Integer.MAX_VALUE)) { + Stream entries = stream.filter(f -> { + String fn = f.getFileName().toString(); + return fn.endsWith(".class") && !fn.equals("module-info.class"); + }); + JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, entries); + } } } @@ -115,19 +116,20 @@ .forEach(f -> assertTrue(Files.exists(f))); // copy classes except the original module-info.class - Files.walk(MODS_DIR, Integer.MAX_VALUE) - .filter(path -> !path.getFileName().toString().equals(MODULE_INFO) && - path.getFileName().toString().endsWith(".class")) - .map(path -> MODS_DIR.relativize(path)) - .forEach(path -> { - try { - Path newFile = NEW_MODS_DIR.resolve(path); - Files.createDirectories(newFile.getParent()); - Files.copy(MODS_DIR.resolve(path), newFile); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - }); + try (Stream stream = Files.walk(MODS_DIR, Integer.MAX_VALUE)) { + stream.filter(path -> !path.getFileName().toString().equals(MODULE_INFO) && + path.getFileName().toString().endsWith(".class")) + .map(path -> MODS_DIR.relativize(path)) + .forEach(path -> { + try { + Path newFile = NEW_MODS_DIR.resolve(path); + Files.createDirectories(newFile.getParent()); + Files.copy(MODS_DIR.resolve(path), newFile); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + }); + } // compile new module-info.java assertTrue(CompilerUtils.compileModule(DEST_DIR, NEW_MODS_DIR, UNSUPPORTED, diff -r 0bd2b31e7021 -r 58cf7e51c16d langtools/test/tools/jdeps/modules/InverseDeps.java --- a/langtools/test/tools/jdeps/modules/InverseDeps.java Thu May 19 20:14:16 2016 +0000 +++ b/langtools/test/tools/jdeps/modules/InverseDeps.java Thu May 19 17:34:05 2016 -0700 @@ -39,6 +39,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import com.sun.tools.jdeps.Archive; import com.sun.tools.jdeps.InverseDepsAnalyzer; @@ -76,12 +77,14 @@ // create JAR files with no module-info.class Path root = MODS_DIR.resolve(mn); - JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, - Files.walk(root, Integer.MAX_VALUE) - .filter(f -> { - String fn = f.getFileName().toString(); - return fn.endsWith(".class") && !fn.equals("module-info.class"); - })); + + try (Stream stream = Files.walk(root, Integer.MAX_VALUE)) { + Stream entries = stream.filter(f -> { + String fn = f.getFileName().toString(); + return fn.endsWith(".class") && !fn.equals("module-info.class"); + }); + JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, entries); + } } } diff -r 0bd2b31e7021 -r 58cf7e51c16d langtools/test/tools/jdeps/modules/TransitiveDeps.java --- a/langtools/test/tools/jdeps/modules/TransitiveDeps.java Thu May 19 20:14:16 2016 +0000 +++ b/langtools/test/tools/jdeps/modules/TransitiveDeps.java Thu May 19 17:34:05 2016 -0700 @@ -39,6 +39,7 @@ import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import com.sun.tools.jdeps.DepsAnalyzer; @@ -72,12 +73,13 @@ // create JAR files with no module-info.class Path root = MODS_DIR.resolve(mn); - JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, - Files.walk(root, Integer.MAX_VALUE) - .filter(f -> { - String fn = f.getFileName().toString(); - return fn.endsWith(".class") && !fn.equals("module-info.class"); - })); + try (Stream stream = Files.walk(root, Integer.MAX_VALUE)) { + Stream entries = stream.filter(f -> { + String fn = f.getFileName().toString(); + return fn.endsWith(".class") && !fn.equals("module-info.class"); + }); + JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, entries); + } } }