mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8157391: jdeps left JarFile open
Reviewed-by: alanb
This commit is contained in:
parent
6db305ee0d
commit
479ecdbdaf
12 changed files with 257 additions and 212 deletions
|
@ -27,6 +27,7 @@ package com.sun.tools.jdeps;
|
||||||
|
|
||||||
import com.sun.tools.classfile.Dependency.Location;
|
import com.sun.tools.classfile.Dependency.Location;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -43,7 +44,7 @@ import java.util.stream.Stream;
|
||||||
/**
|
/**
|
||||||
* Represents the source of the class files.
|
* Represents the source of the class files.
|
||||||
*/
|
*/
|
||||||
public class Archive {
|
public class Archive implements Closeable {
|
||||||
public static Archive getInstance(Path p) {
|
public static Archive getInstance(Path p) {
|
||||||
try {
|
try {
|
||||||
return new Archive(p, ClassFileReader.newInstance(p));
|
return new Archive(p, ClassFileReader.newInstance(p));
|
||||||
|
@ -178,6 +179,13 @@ public class Archive {
|
||||||
private boolean isJrt() {
|
private boolean isJrt() {
|
||||||
return location != null && location.getScheme().equals("jrt");
|
return location != null && location.getScheme().equals("jrt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (reader != null)
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
|
||||||
interface Visitor {
|
interface Visitor {
|
||||||
void visit(Location origin, Location target);
|
void visit(Location origin, Location target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.sun.tools.classfile.ClassFile;
|
||||||
import com.sun.tools.classfile.ConstantPoolException;
|
import com.sun.tools.classfile.ConstantPoolException;
|
||||||
import com.sun.tools.classfile.Dependencies.ClassFileError;
|
import com.sun.tools.classfile.Dependencies.ClassFileError;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -54,7 +55,7 @@ import java.util.stream.Stream;
|
||||||
* ClassFileReader reads ClassFile(s) of a given path that can be
|
* ClassFileReader reads ClassFile(s) of a given path that can be
|
||||||
* a .class file, a directory, or a JAR file.
|
* a .class file, a directory, or a JAR file.
|
||||||
*/
|
*/
|
||||||
public class ClassFileReader {
|
public class ClassFileReader implements Closeable {
|
||||||
/**
|
/**
|
||||||
* Returns a ClassFileReader instance of a given path.
|
* Returns a ClassFileReader instance of a given path.
|
||||||
*/
|
*/
|
||||||
|
@ -177,6 +178,10 @@ public class ClassFileReader {
|
||||||
return fn.endsWith(".class");
|
return fn.endsWith(".class");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
class FileIterator implements Iterator<ClassFile> {
|
class FileIterator implements Iterator<ClassFile> {
|
||||||
int count;
|
int count;
|
||||||
FileIterator() {
|
FileIterator() {
|
||||||
|
@ -306,6 +311,11 @@ public class ClassFileReader {
|
||||||
this.jarfile = jf;
|
this.jarfile = jf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
jarfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
protected Set<String> scan() {
|
protected Set<String> scan() {
|
||||||
try (JarFile jf = new JarFile(path.toFile())) {
|
try (JarFile jf = new JarFile(path.toFile())) {
|
||||||
return jf.stream().map(JarEntry::getName)
|
return jf.stream().map(JarEntry::getName)
|
||||||
|
|
|
@ -64,7 +64,7 @@ import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class JdepsConfiguration {
|
public class JdepsConfiguration implements AutoCloseable {
|
||||||
// the token for "all modules on the module path"
|
// the token for "all modules on the module path"
|
||||||
public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
|
public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
|
||||||
public static final String ALL_DEFAULT = "ALL-DEFAULT";
|
public static final String ALL_DEFAULT = "ALL-DEFAULT";
|
||||||
|
@ -304,6 +304,19 @@ public class JdepsConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Close all archives e.g. JarFile
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
for (Archive archive : initialArchives)
|
||||||
|
archive.close();
|
||||||
|
for (Archive archive : classpathArchives)
|
||||||
|
archive.close();
|
||||||
|
for (Module module : nameToModule.values())
|
||||||
|
module.close();
|
||||||
|
}
|
||||||
|
|
||||||
static class SystemModuleFinder implements ModuleFinder {
|
static class SystemModuleFinder implements ModuleFinder {
|
||||||
private static final String JAVA_HOME = System.getProperty("java.home");
|
private static final String JAVA_HOME = System.getProperty("java.home");
|
||||||
private static final String JAVA_SE = "java.se";
|
private static final String JAVA_SE = "java.se";
|
||||||
|
|
|
@ -499,40 +499,41 @@ class JdepsTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean run() throws IOException {
|
boolean run() throws IOException {
|
||||||
JdepsConfiguration config = buildConfig();
|
try (JdepsConfiguration config = buildConfig()) {
|
||||||
|
|
||||||
// detect split packages
|
// detect split packages
|
||||||
config.splitPackages().entrySet().stream()
|
config.splitPackages().entrySet().stream()
|
||||||
.sorted(Map.Entry.comparingByKey())
|
.sorted(Map.Entry.comparingByKey())
|
||||||
.forEach(e -> System.out.format("split package: %s %s%n", e.getKey(),
|
.forEach(e -> System.out.format("split package: %s %s%n", e.getKey(),
|
||||||
e.getValue().toString()));
|
e.getValue().toString()));
|
||||||
|
|
||||||
// check if any module specified in -requires is missing
|
// check if any module specified in -requires is missing
|
||||||
Stream.concat(options.addmods.stream(), options.requires.stream())
|
Stream.concat(options.addmods.stream(), options.requires.stream())
|
||||||
.filter(mn -> !config.isValidToken(mn))
|
.filter(mn -> !config.isValidToken(mn))
|
||||||
.forEach(mn -> config.findModule(mn).orElseThrow(() ->
|
.forEach(mn -> config.findModule(mn).orElseThrow(() ->
|
||||||
new UncheckedBadArgs(new BadArgs("err.module.not.found", mn))));
|
new UncheckedBadArgs(new BadArgs("err.module.not.found", mn))));
|
||||||
|
|
||||||
// -genmoduleinfo
|
// -genmoduleinfo
|
||||||
if (options.genModuleInfo != null) {
|
if (options.genModuleInfo != null) {
|
||||||
return genModuleInfo(config);
|
return genModuleInfo(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -check
|
// -check
|
||||||
if (options.checkModuleDeps != null) {
|
if (options.checkModuleDeps != null) {
|
||||||
return new ModuleAnalyzer(config, log, options.checkModuleDeps).run();
|
return new ModuleAnalyzer(config, log, options.checkModuleDeps).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.dotOutputDir != null &&
|
if (options.dotOutputDir != null &&
|
||||||
(options.verbose == SUMMARY || options.verbose == MODULE) &&
|
(options.verbose == SUMMARY || options.verbose == MODULE) &&
|
||||||
!options.addmods.isEmpty() && inputArgs.isEmpty()) {
|
!options.addmods.isEmpty() && inputArgs.isEmpty()) {
|
||||||
return new ModuleAnalyzer(config, log).genDotFiles(options.dotOutputDir);
|
return new ModuleAnalyzer(config, log).genDotFiles(options.dotOutputDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.inverse) {
|
if (options.inverse) {
|
||||||
return analyzeInverseDeps(config);
|
return analyzeInverseDeps(config);
|
||||||
} else {
|
} else {
|
||||||
return analyzeDeps(config);
|
return analyzeDeps(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,11 @@ public class ModuleInfoBuilder {
|
||||||
// generate module-info.java
|
// generate module-info.java
|
||||||
descriptors().forEach(md -> writeModuleInfo(outputdir, md));
|
descriptors().forEach(md -> writeModuleInfo(outputdir, md));
|
||||||
|
|
||||||
|
// done parsing
|
||||||
|
for (Module m : automaticModules()) {
|
||||||
|
m.close();
|
||||||
|
}
|
||||||
|
|
||||||
// find any missing dependences
|
// find any missing dependences
|
||||||
return automaticModules().stream()
|
return automaticModules().stream()
|
||||||
.flatMap(analyzer::requires)
|
.flatMap(analyzer::requires)
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.sun.tools.jdeps.JdepsFilter;
|
||||||
import com.sun.tools.jdeps.JdepsWriter;
|
import com.sun.tools.jdeps.JdepsWriter;
|
||||||
import com.sun.tools.jdeps.ModuleAnalyzer;
|
import com.sun.tools.jdeps.ModuleAnalyzer;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
@ -73,7 +74,7 @@ public final class JdepsUtil {
|
||||||
return new Command(cmd);
|
return new Command(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Command {
|
public static class Command implements Closeable {
|
||||||
|
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
final PrintWriter pw = new PrintWriter(sw);
|
final PrintWriter pw = new PrintWriter(sw);
|
||||||
|
@ -81,6 +82,7 @@ public final class JdepsUtil {
|
||||||
final JdepsConfiguration.Builder builder = new JdepsConfiguration.Builder();
|
final JdepsConfiguration.Builder builder = new JdepsConfiguration.Builder();
|
||||||
final Set<String> requires = new HashSet<>();
|
final Set<String> requires = new HashSet<>();
|
||||||
|
|
||||||
|
JdepsConfiguration configuration;
|
||||||
Analyzer.Type verbose = Analyzer.Type.PACKAGE;
|
Analyzer.Type verbose = Analyzer.Type.PACKAGE;
|
||||||
boolean apiOnly = false;
|
boolean apiOnly = false;
|
||||||
|
|
||||||
|
@ -176,12 +178,14 @@ public final class JdepsUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public JdepsConfiguration configuration() throws IOException {
|
public JdepsConfiguration configuration() throws IOException {
|
||||||
JdepsConfiguration config = builder.build();
|
if (configuration == null) {
|
||||||
requires.forEach(name -> {
|
this.configuration = builder.build();
|
||||||
ModuleDescriptor md = config.findModuleDescriptor(name).get();
|
requires.forEach(name -> {
|
||||||
filter.requires(name, md.packages());
|
ModuleDescriptor md = configuration.findModuleDescriptor(name).get();
|
||||||
});
|
filter.requires(name, md.packages());
|
||||||
return config;
|
});
|
||||||
|
}
|
||||||
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JdepsWriter writer() {
|
private JdepsWriter writer() {
|
||||||
|
@ -208,6 +212,11 @@ public final class JdepsUtil {
|
||||||
public void dumpOutput(PrintStream out) {
|
public void dumpOutput(PrintStream out) {
|
||||||
out.println(sw.toString());
|
out.println(sw.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
configuration.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,19 +78,19 @@ public class CheckModuleTest {
|
||||||
|
|
||||||
@Test(dataProvider = "javaBase")
|
@Test(dataProvider = "javaBase")
|
||||||
public void testJavaBase(String name, ModuleMetaData data) throws Exception {
|
public void testJavaBase(String name, ModuleMetaData data) throws Exception {
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd = String.format("jdeps -check %s -mp %s%n", name, MODS_DIR);
|
||||||
String.format("jdeps -check %s -mp %s%n", name, MODS_DIR)
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
);
|
jdeps.appModulePath(MODS_DIR.toString());
|
||||||
jdeps.appModulePath(MODS_DIR.toString());
|
|
||||||
|
|
||||||
ModuleAnalyzer analyzer = jdeps.getModuleAnalyzer(Set.of(name));
|
ModuleAnalyzer analyzer = jdeps.getModuleAnalyzer(Set.of(name));
|
||||||
assertTrue(analyzer.run());
|
assertTrue(analyzer.run());
|
||||||
jdeps.dumpOutput(System.err);
|
jdeps.dumpOutput(System.err);
|
||||||
|
|
||||||
ModuleDescriptor[] descriptors = analyzer.descriptors(name);
|
ModuleDescriptor[] descriptors = analyzer.descriptors(name);
|
||||||
for (int i=0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
descriptors[i].requires().stream()
|
descriptors[i].requires().stream()
|
||||||
.forEach(req -> data.checkRequires(req));
|
.forEach(req -> data.checkRequires(req));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,26 +137,27 @@ public class CheckModuleTest {
|
||||||
|
|
||||||
@Test(dataProvider = "modules")
|
@Test(dataProvider = "modules")
|
||||||
public void modularTest(String name, ModuleMetaData[] data) throws Exception {
|
public void modularTest(String name, ModuleMetaData[] data) throws Exception {
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd = String.format("jdeps -check %s -mp %s%n", name, MODS_DIR);
|
||||||
String.format("jdeps -check %s -mp %s%n", name, MODS_DIR)
|
|
||||||
);
|
|
||||||
jdeps.appModulePath(MODS_DIR.toString());
|
|
||||||
|
|
||||||
ModuleAnalyzer analyzer = jdeps.getModuleAnalyzer(Set.of(name));
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
assertTrue(analyzer.run());
|
jdeps.appModulePath(MODS_DIR.toString());
|
||||||
jdeps.dumpOutput(System.err);
|
|
||||||
|
|
||||||
// compare the module descriptors and the suggested versions
|
ModuleAnalyzer analyzer = jdeps.getModuleAnalyzer(Set.of(name));
|
||||||
ModuleDescriptor[] descriptors = analyzer.descriptors(name);
|
assertTrue(analyzer.run());
|
||||||
for (int i=0; i < 3; i++) {
|
jdeps.dumpOutput(System.err);
|
||||||
ModuleMetaData metaData = data[i];
|
|
||||||
descriptors[i].requires().stream()
|
// compare the module descriptors and the suggested versions
|
||||||
.forEach(req -> metaData.checkRequires(req));
|
ModuleDescriptor[] descriptors = analyzer.descriptors(name);
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
ModuleMetaData metaData = data[i];
|
||||||
|
descriptors[i].requires().stream()
|
||||||
|
.forEach(req -> metaData.checkRequires(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Set<String>> unused = analyzer.unusedQualifiedExports(name);
|
||||||
|
// verify unuused qualified exports
|
||||||
|
assertEquals(unused, data[0].exports);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Set<String>> unused = analyzer.unusedQualifiedExports(name);
|
|
||||||
// verify unuused qualified exports
|
|
||||||
assertEquals(unused, data[0].exports);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,8 +107,7 @@ public class GenModuleInfo {
|
||||||
.map(Path::toString);
|
.map(Path::toString);
|
||||||
|
|
||||||
JdepsUtil.jdeps(Stream.concat(Stream.of("-genmoduleinfo", DEST_DIR.toString()),
|
JdepsUtil.jdeps(Stream.concat(Stream.of("-genmoduleinfo", DEST_DIR.toString()),
|
||||||
files)
|
files).toArray(String[]::new));
|
||||||
.toArray(String[]::new));
|
|
||||||
|
|
||||||
// check file exists
|
// check file exists
|
||||||
Arrays.stream(modules)
|
Arrays.stream(modules)
|
||||||
|
@ -162,14 +161,13 @@ public class GenModuleInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> packages(Path dir) {
|
private Set<String> packages(Path dir) {
|
||||||
try {
|
try (Stream<Path> stream = Files.find(dir, Integer.MAX_VALUE,
|
||||||
return Files.find(dir, Integer.MAX_VALUE,
|
|
||||||
((path, attrs) -> attrs.isRegularFile() &&
|
((path, attrs) -> attrs.isRegularFile() &&
|
||||||
path.toString().endsWith(".class")))
|
path.toString().endsWith(".class")))) {
|
||||||
.map(path -> toPackageName(dir.relativize(path)))
|
return stream.map(path -> toPackageName(dir.relativize(path)))
|
||||||
.filter(pkg -> pkg.length() > 0) // module-info
|
.filter(pkg -> pkg.length() > 0) // module-info
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
} catch (IOException x) {
|
} catch (IOException x) {
|
||||||
throw new UncheckedIOException(x);
|
throw new UncheckedIOException(x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,26 +117,28 @@ public class InverseDeps {
|
||||||
|
|
||||||
@Test(dataProvider = "testrequires")
|
@Test(dataProvider = "testrequires")
|
||||||
public void testrequires(String name, String[][] expected) throws Exception {
|
public void testrequires(String name, String[][] expected) throws Exception {
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd1 = String.format("jdeps -inverse -modulepath %s -requires %s -addmods %s%n",
|
||||||
String.format("jdeps -inverse -modulepath %s -requires %s -addmods %s%n",
|
MODS_DIR, name, modules.stream().collect(Collectors.joining(",")));
|
||||||
MODS_DIR, name, modules.stream().collect(Collectors.joining(","))
|
|
||||||
));
|
|
||||||
jdeps.appModulePath(MODS_DIR.toString())
|
|
||||||
.addmods(modules)
|
|
||||||
.requires(Set.of(name));
|
|
||||||
|
|
||||||
runJdeps(jdeps, expected);
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd1)) {
|
||||||
|
jdeps.appModulePath(MODS_DIR.toString())
|
||||||
|
.addmods(modules)
|
||||||
|
.requires(Set.of(name));
|
||||||
|
|
||||||
// automatic module
|
runJdeps(jdeps, expected);
|
||||||
jdeps = JdepsUtil.newCommand(
|
}
|
||||||
String.format("jdeps -inverse -modulepath %s -requires %s -addmods ALL-MODULE-PATH%n",
|
|
||||||
LIBS_DIR, name)
|
|
||||||
);
|
|
||||||
jdeps.appModulePath(MODS_DIR.toString())
|
|
||||||
.addmods(Set.of("ALL-MODULE-PATH"))
|
|
||||||
.requires(Set.of(name));
|
|
||||||
|
|
||||||
runJdeps(jdeps, expected);
|
String cmd2 = String.format("jdeps -inverse -modulepath %s -requires %s" +
|
||||||
|
" -addmods ALL-MODULE-PATH%n", LIBS_DIR, name);
|
||||||
|
|
||||||
|
// automatic module
|
||||||
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd2)) {
|
||||||
|
jdeps.appModulePath(MODS_DIR.toString())
|
||||||
|
.addmods(Set.of("ALL-MODULE-PATH"))
|
||||||
|
.requires(Set.of(name));
|
||||||
|
|
||||||
|
runJdeps(jdeps, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "testpackage")
|
@DataProvider(name = "testpackage")
|
||||||
|
@ -162,15 +164,15 @@ public class InverseDeps {
|
||||||
|
|
||||||
@Test(dataProvider = "testpackage")
|
@Test(dataProvider = "testpackage")
|
||||||
public void testpackage(String name, String[][] expected) throws Exception {
|
public void testpackage(String name, String[][] expected) throws Exception {
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd = String.format("jdeps -inverse -modulepath %s -package %s -addmods %s%n",
|
||||||
String.format("jdeps -inverse -modulepath %s -package %s -addmods %s%n",
|
MODS_DIR, name, modules.stream().collect(Collectors.joining(",")));
|
||||||
MODS_DIR, name, modules.stream().collect(Collectors.joining(","))
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
));
|
jdeps.appModulePath(MODS_DIR.toString())
|
||||||
jdeps.appModulePath(MODS_DIR.toString())
|
.addmods(modules)
|
||||||
.addmods(modules)
|
.matchPackages(Set.of(name));
|
||||||
.matchPackages(Set.of(name));
|
|
||||||
|
|
||||||
runJdeps(jdeps, expected);
|
runJdeps(jdeps, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "testregex")
|
@DataProvider(name = "testregex")
|
||||||
|
@ -193,16 +195,16 @@ public class InverseDeps {
|
||||||
|
|
||||||
@Test(dataProvider = "testregex")
|
@Test(dataProvider = "testregex")
|
||||||
public void testregex(String name, String[][] expected) throws Exception {
|
public void testregex(String name, String[][] expected) throws Exception {
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd = String.format("jdeps -inverse -modulepath %s -regex %s -addmods %s%n",
|
||||||
String.format("jdeps -inverse -modulepath %s -regex %s -addmods %s%n",
|
MODS_DIR, name, modules.stream().collect(Collectors.joining(",")));
|
||||||
MODS_DIR, name, modules.stream().collect(Collectors.joining(",")))
|
|
||||||
);
|
|
||||||
|
|
||||||
jdeps.appModulePath(MODS_DIR.toString())
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
.addmods(modules)
|
jdeps.appModulePath(MODS_DIR.toString())
|
||||||
.regex(name);
|
.addmods(modules)
|
||||||
|
.regex(name);
|
||||||
|
|
||||||
runJdeps(jdeps, expected);
|
runJdeps(jdeps, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "classpath")
|
@DataProvider(name = "classpath")
|
||||||
|
@ -237,26 +239,26 @@ public class InverseDeps {
|
||||||
.collect(Collectors.joining(File.pathSeparator));
|
.collect(Collectors.joining(File.pathSeparator));
|
||||||
|
|
||||||
Path jarfile = LIBS_DIR.resolve("m7.jar");
|
Path jarfile = LIBS_DIR.resolve("m7.jar");
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
|
||||||
String.format("jdeps -inverse -classpath %s -regex %s %s%n",
|
String cmd1 = String.format("jdeps -inverse -classpath %s -regex %s %s%n",
|
||||||
cpath, name, jarfile)
|
cpath, name, jarfile);
|
||||||
);
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd1)) {
|
||||||
jdeps.verbose("-verbose:class")
|
jdeps.verbose("-verbose:class")
|
||||||
.addClassPath(cpath)
|
.addClassPath(cpath)
|
||||||
.regex(name).addRoot(jarfile);
|
.regex(name).addRoot(jarfile);
|
||||||
runJdeps(jdeps, expected);
|
runJdeps(jdeps, expected);
|
||||||
|
}
|
||||||
|
|
||||||
// all JAR files on the command-line arguments
|
// all JAR files on the command-line arguments
|
||||||
Set<Path> paths = modules.stream()
|
Set<Path> paths = modules.stream()
|
||||||
.map(mn -> LIBS_DIR.resolve(mn + ".jar"))
|
.map(mn -> LIBS_DIR.resolve(mn + ".jar"))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
jdeps = JdepsUtil.newCommand(
|
String cmd2 = String.format("jdeps -inverse -regex %s %s%n", name, paths);
|
||||||
String.format("jdeps -inverse -regex %s %s%n", name, paths)
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd2)) {
|
||||||
);
|
jdeps.verbose("-verbose:class").regex(name);
|
||||||
jdeps.verbose("-verbose:class").regex(name);
|
paths.forEach(jdeps::addRoot);
|
||||||
paths.forEach(jdeps::addRoot);
|
runJdeps(jdeps, expected);
|
||||||
runJdeps(jdeps, expected);
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runJdeps(JdepsUtil.Command jdeps, String[][] expected) throws Exception {
|
private void runJdeps(JdepsUtil.Command jdeps, String[][] expected) throws Exception {
|
||||||
|
@ -292,7 +294,6 @@ public class InverseDeps {
|
||||||
|
|
||||||
assertFalse(noneMatched);
|
assertFalse(noneMatched);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,30 +151,30 @@ public class ModuleTest {
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// jdeps -modulepath <modulepath> -m root paths
|
// jdeps -modulepath <modulepath> -m root paths
|
||||||
|
String cmd = String.format("jdeps -modulepath %s -addmods %s %s%n",
|
||||||
|
MODS_DIR, roots.stream().collect(Collectors.joining(",")), paths);
|
||||||
|
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
String.format("jdeps -modulepath %s -addmods %s %s%n", MODS_DIR,
|
jdeps.appModulePath(modulepath)
|
||||||
roots.stream().collect(Collectors.joining(",")), paths)
|
.addmods(roots);
|
||||||
);
|
Arrays.stream(paths).forEach(jdeps::addRoot);
|
||||||
jdeps.appModulePath(modulepath)
|
|
||||||
.addmods(roots);
|
|
||||||
Arrays.stream(paths).forEach(jdeps::addRoot);
|
|
||||||
|
|
||||||
// run the analyzer
|
// run the analyzer
|
||||||
DepsAnalyzer analyzer = jdeps.getDepsAnalyzer();
|
DepsAnalyzer analyzer = jdeps.getDepsAnalyzer();
|
||||||
assertTrue(analyzer.run());
|
assertTrue(analyzer.run());
|
||||||
|
|
||||||
// analyze result
|
// analyze result
|
||||||
Graph<DepsAnalyzer.Node> g1 = analyzer.moduleGraph();
|
Graph<DepsAnalyzer.Node> g1 = analyzer.moduleGraph();
|
||||||
g1.nodes().stream()
|
g1.nodes().stream()
|
||||||
.filter(u -> u.name.equals(data.moduleName))
|
.filter(u -> u.name.equals(data.moduleName))
|
||||||
.forEach(u -> data.checkRequires(u.name, g1.adjacentNodes(u)));
|
.forEach(u -> data.checkRequires(u.name, g1.adjacentNodes(u)));
|
||||||
|
|
||||||
Graph<DepsAnalyzer.Node> g2 = analyzer.dependenceGraph();
|
Graph<DepsAnalyzer.Node> g2 = analyzer.dependenceGraph();
|
||||||
g2.nodes().stream()
|
g2.nodes().stream()
|
||||||
.filter(u -> u.name.equals(data.moduleName))
|
.filter(u -> u.name.equals(data.moduleName))
|
||||||
.forEach(u -> data.checkDependences(u.name, g2.adjacentNodes(u)));
|
.forEach(u -> data.checkDependences(u.name, g2.adjacentNodes(u)));
|
||||||
|
|
||||||
jdeps.dumpOutput(System.err);
|
jdeps.dumpOutput(System.err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,36 +70,35 @@ public class SplitPackage {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runTest(String root, String... splitPackages) throws Exception {
|
private void runTest(String root, String... splitPackages) throws Exception {
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd = String.format("jdeps -verbose:class -addmods %s %s%n",
|
||||||
String.format("jdeps -verbose:class -addmods %s %s%n",
|
root, CLASSES_DIR);
|
||||||
root, CLASSES_DIR)
|
|
||||||
);
|
|
||||||
jdeps.verbose("-verbose:class")
|
|
||||||
.addRoot(CLASSES_DIR);
|
|
||||||
if (root != null)
|
|
||||||
jdeps.addmods(Set.of(root));
|
|
||||||
|
|
||||||
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
|
jdeps.verbose("-verbose:class")
|
||||||
|
.addRoot(CLASSES_DIR);
|
||||||
|
if (root != null)
|
||||||
|
jdeps.addmods(Set.of(root));
|
||||||
|
|
||||||
JdepsConfiguration config = jdeps.configuration();
|
JdepsConfiguration config = jdeps.configuration();
|
||||||
Map<String, Set<String>> pkgs = config.splitPackages();
|
Map<String, Set<String>> pkgs = config.splitPackages();
|
||||||
|
|
||||||
final Set<String> expected;
|
final Set<String> expected;
|
||||||
if (splitPackages != null) {
|
if (splitPackages != null) {
|
||||||
expected = Arrays.stream(splitPackages).collect(Collectors.toSet());
|
expected = Arrays.stream(splitPackages).collect(Collectors.toSet());
|
||||||
} else {
|
} else {
|
||||||
expected = Collections.emptySet();
|
expected = Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pkgs.keySet().equals(expected)) {
|
||||||
|
throw new RuntimeException(splitPackages.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// java.annotations.common is not observable
|
||||||
|
DepsAnalyzer analyzer = jdeps.getDepsAnalyzer();
|
||||||
|
|
||||||
|
assertTrue(analyzer.run());
|
||||||
|
|
||||||
|
jdeps.dumpOutput(System.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pkgs.keySet().equals(expected)) {
|
|
||||||
throw new RuntimeException(splitPackages.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// java.annotations.common is not observable
|
|
||||||
DepsAnalyzer analyzer = jdeps.getDepsAnalyzer();
|
|
||||||
|
|
||||||
assertTrue(analyzer.run());
|
|
||||||
|
|
||||||
jdeps.dumpOutput(System.err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,30 +122,31 @@ public class TransitiveDeps {
|
||||||
@Test(dataProvider = "modules")
|
@Test(dataProvider = "modules")
|
||||||
public void testModulePath(String name, List<ModuleMetaData> data) throws IOException {
|
public void testModulePath(String name, List<ModuleMetaData> data) throws IOException {
|
||||||
Set<String> roots = Set.of("m6", "unsafe");
|
Set<String> roots = Set.of("m6", "unsafe");
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
|
||||||
String.format("jdeps -modulepath %s -addmods %s -m %s%n", MODS_DIR,
|
|
||||||
roots.stream().collect(Collectors.joining(",")), name)
|
|
||||||
);
|
|
||||||
jdeps.verbose("-verbose:class")
|
|
||||||
.appModulePath(MODS_DIR.toString())
|
|
||||||
.addmods(roots)
|
|
||||||
.addmods(Set.of(name));
|
|
||||||
|
|
||||||
runJdeps(jdeps, data);
|
String cmd1 = String.format("jdeps -modulepath %s -addmods %s -m %s%n", MODS_DIR,
|
||||||
|
roots.stream().collect(Collectors.joining(",")), name);
|
||||||
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd1)) {
|
||||||
|
jdeps.verbose("-verbose:class")
|
||||||
|
.appModulePath(MODS_DIR.toString())
|
||||||
|
.addmods(roots)
|
||||||
|
.addmods(Set.of(name));
|
||||||
|
|
||||||
|
runJdeps(jdeps, data);
|
||||||
|
}
|
||||||
// run automatic modules
|
// run automatic modules
|
||||||
roots = Set.of("ALL-MODULE-PATH", "jdk.unsupported");
|
roots = Set.of("ALL-MODULE-PATH", "jdk.unsupported");
|
||||||
|
|
||||||
jdeps = JdepsUtil.newCommand(
|
String cmd2 = String.format("jdeps -modulepath %s -addmods %s -m %s%n", LIBS_DIR,
|
||||||
String.format("jdeps -modulepath %s -addmods %s -m %s%n", LIBS_DIR,
|
roots.stream().collect(Collectors.joining(",")), name);
|
||||||
roots.stream().collect(Collectors.joining(",")), name)
|
|
||||||
);
|
|
||||||
jdeps.verbose("-verbose:class")
|
|
||||||
.appModulePath(LIBS_DIR.toString())
|
|
||||||
.addmods(roots)
|
|
||||||
.addmods(Set.of(name));
|
|
||||||
|
|
||||||
runJdeps(jdeps, data);
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd2)) {
|
||||||
|
jdeps.verbose("-verbose:class")
|
||||||
|
.appModulePath(LIBS_DIR.toString())
|
||||||
|
.addmods(roots)
|
||||||
|
.addmods(Set.of(name));
|
||||||
|
|
||||||
|
runJdeps(jdeps, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "jars")
|
@DataProvider(name = "jars")
|
||||||
|
@ -170,14 +171,15 @@ public class TransitiveDeps {
|
||||||
.collect(Collectors.joining(File.pathSeparator));
|
.collect(Collectors.joining(File.pathSeparator));
|
||||||
|
|
||||||
Path jarfile = LIBS_DIR.resolve(name + ".jar");
|
Path jarfile = LIBS_DIR.resolve(name + ".jar");
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
|
||||||
String.format("jdeps -classpath %s %s%n", cpath, jarfile)
|
|
||||||
);
|
|
||||||
jdeps.verbose("-verbose:class")
|
|
||||||
.addClassPath(cpath)
|
|
||||||
.addRoot(jarfile);
|
|
||||||
|
|
||||||
runJdeps(jdeps, data);
|
String cmd = String.format("jdeps -classpath %s %s%n", cpath, jarfile);
|
||||||
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
|
jdeps.verbose("-verbose:class")
|
||||||
|
.addClassPath(cpath)
|
||||||
|
.addRoot(jarfile);
|
||||||
|
|
||||||
|
runJdeps(jdeps, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "compileTimeView")
|
@DataProvider(name = "compileTimeView")
|
||||||
|
@ -225,15 +227,14 @@ public class TransitiveDeps {
|
||||||
|
|
||||||
Path jarfile = LIBS_DIR.resolve(name + ".jar");
|
Path jarfile = LIBS_DIR.resolve(name + ".jar");
|
||||||
|
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd = String.format("jdeps -ct -classpath %s %s%n", cpath, jarfile);
|
||||||
String.format("jdeps -ct -classpath %s %s%n", cpath, jarfile)
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
);
|
jdeps.verbose("-verbose:class")
|
||||||
|
.addClassPath(cpath)
|
||||||
|
.addRoot(jarfile);
|
||||||
|
|
||||||
jdeps.verbose("-verbose:class")
|
runJdeps(jdeps, data, true, 0 /* -recursive */);
|
||||||
.addClassPath(cpath)
|
}
|
||||||
.addRoot(jarfile);
|
|
||||||
|
|
||||||
runJdeps(jdeps, data, true, 0 /* -recursive */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "recursiveDeps")
|
@DataProvider(name = "recursiveDeps")
|
||||||
|
@ -276,14 +277,14 @@ public class TransitiveDeps {
|
||||||
|
|
||||||
Path jarfile = LIBS_DIR.resolve(name + ".jar");
|
Path jarfile = LIBS_DIR.resolve(name + ".jar");
|
||||||
|
|
||||||
JdepsUtil.Command jdeps = JdepsUtil.newCommand(
|
String cmd = String.format("jdeps -R -classpath %s %s%n", cpath, jarfile);
|
||||||
String.format("jdeps -R -classpath %s %s%n", cpath, jarfile)
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
);
|
jdeps.verbose("-verbose:class").filter("-filter:archive")
|
||||||
jdeps.verbose("-verbose:class").filter("-filter:archive")
|
.addClassPath(cpath)
|
||||||
.addClassPath(cpath)
|
.addRoot(jarfile);
|
||||||
.addRoot(jarfile);
|
|
||||||
|
|
||||||
runJdeps(jdeps, data, true, 0 /* -recursive */);
|
runJdeps(jdeps, data, true, 0 /* -recursive */);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runJdeps(JdepsUtil.Command jdeps, List<ModuleMetaData> data)
|
private void runJdeps(JdepsUtil.Command jdeps, List<ModuleMetaData> data)
|
||||||
|
@ -322,6 +323,5 @@ public class TransitiveDeps {
|
||||||
ModuleMetaData md = dataMap.get(u.name);
|
ModuleMetaData md = dataMap.get(u.name);
|
||||||
md.checkDependences(u.name, g2.adjacentNodes(u));
|
md.checkDependences(u.name, g2.adjacentNodes(u));
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue