8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows

Reviewed-by: jjg
This commit is contained in:
Mandy Chung 2016-05-19 17:34:05 -07:00
parent b9c61ad8b3
commit 6db305ee0d
5 changed files with 60 additions and 51 deletions
langtools
src/jdk.jdeps/share/classes/com/sun/tools/jdeps
test/tools/jdeps/modules

@ -48,6 +48,7 @@ import java.util.Set;
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 @@ public class ClassFileReader {
* 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 @@ public class ClassFileReader {
}
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 @@ public class ClassFileReader {
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 @@ public class ClassFileReader {
}
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() {

@ -348,12 +348,11 @@ public class JdepsConfiguration {
}
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);
}

@ -82,12 +82,13 @@ public class GenModuleInfo {
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 @@ public class GenModuleInfo {
.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,

@ -39,6 +39,7 @@ import java.util.LinkedHashSet;
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 @@ public class InverseDeps {
// 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);
}
}
}

@ -39,6 +39,7 @@ import java.nio.file.Paths;
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 @@ public class TransitiveDeps {
// 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);
}
}
}