8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
Reviewed-by: jjg
--- 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<String> 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<Path> 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<ClassFile> {
- private List<Path> entries;
+ private final List<Path> entries;
private int index = 0;
DirectoryIterator() throws IOException {
- entries = Files.walk(path, Integer.MAX_VALUE)
- .filter(ClassFileReader::isClass)
- .collect(Collectors.toList());
- index = 0;
+ List<Path> paths = null;
+ try (Stream<Path> stream = Files.walk(path, Integer.MAX_VALUE)) {
+ paths = stream.filter(ClassFileReader::isClass)
+ .collect(Collectors.toList());
+ }
+ this.entries = paths;
+ this.index = 0;
}
public boolean hasNext() {
--- 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<String, ModuleReference> 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<Path> 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);
}
--- 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<Path> stream = Files.walk(root, Integer.MAX_VALUE)) {
+ Stream<Path> 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<Path> 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,
--- 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<Path> stream = Files.walk(root, Integer.MAX_VALUE)) {
+ Stream<Path> 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);
+ }
}
}
--- 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<Path> stream = Files.walk(root, Integer.MAX_VALUE)) {
+ Stream<Path> 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);
+ }
}
}