8157391: jdeps left JarFile open

Reviewed-by: alanb
This commit is contained in:
Mandy Chung 2016-05-20 09:47:00 -07:00
parent 6db305ee0d
commit 479ecdbdaf
12 changed files with 257 additions and 212 deletions

View file

@ -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);
} }

View file

@ -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)

View file

@ -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";

View file

@ -499,7 +499,7 @@ 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()
@ -535,6 +535,7 @@ class JdepsTask {
return analyzeDeps(config); return analyzeDeps(config);
} }
} }
}
private JdepsConfiguration buildConfig() throws IOException { private JdepsConfiguration buildConfig() throws IOException {
JdepsConfiguration.Builder builder = JdepsConfiguration.Builder builder =

View file

@ -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)

View file

@ -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) {
this.configuration = builder.build();
requires.forEach(name -> { requires.forEach(name -> {
ModuleDescriptor md = config.findModuleDescriptor(name).get(); ModuleDescriptor md = configuration.findModuleDescriptor(name).get();
filter.requires(name, md.packages()); 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();
}
} }
/** /**

View file

@ -78,9 +78,8 @@ 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));
@ -88,11 +87,12 @@ public class CheckModuleTest {
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));
} }
} }
}
@DataProvider(name = "modules") @DataProvider(name = "modules")
public Object[][] unnamed() { public Object[][] unnamed() {
@ -137,9 +137,9 @@ 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)
); 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));
@ -148,7 +148,7 @@ public class CheckModuleTest {
// compare the module descriptors and the suggested versions // compare the module descriptors and the suggested versions
ModuleDescriptor[] descriptors = analyzer.descriptors(name); ModuleDescriptor[] descriptors = analyzer.descriptors(name);
for (int i=0; i < 3; i++) { for (int i = 0; i < 3; i++) {
ModuleMetaData metaData = data[i]; ModuleMetaData metaData = data[i];
descriptors[i].requires().stream() descriptors[i].requires().stream()
.forEach(req -> metaData.checkRequires(req)); .forEach(req -> metaData.checkRequires(req));
@ -158,5 +158,6 @@ public class CheckModuleTest {
// verify unuused qualified exports // verify unuused qualified exports
assertEquals(unused, data[0].exports); assertEquals(unused, data[0].exports);
} }
}
} }

View file

@ -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,11 +161,10 @@ 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());

View file

@ -117,27 +117,29 @@ 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(","))
)); try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd1)) {
jdeps.appModulePath(MODS_DIR.toString()) jdeps.appModulePath(MODS_DIR.toString())
.addmods(modules) .addmods(modules)
.requires(Set.of(name)); .requires(Set.of(name));
runJdeps(jdeps, expected); runJdeps(jdeps, expected);
}
String cmd2 = String.format("jdeps -inverse -modulepath %s -requires %s" +
" -addmods ALL-MODULE-PATH%n", LIBS_DIR, name);
// automatic module // automatic module
jdeps = JdepsUtil.newCommand( try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd2)) {
String.format("jdeps -inverse -modulepath %s -requires %s -addmods ALL-MODULE-PATH%n",
LIBS_DIR, name)
);
jdeps.appModulePath(MODS_DIR.toString()) jdeps.appModulePath(MODS_DIR.toString())
.addmods(Set.of("ALL-MODULE-PATH")) .addmods(Set.of("ALL-MODULE-PATH"))
.requires(Set.of(name)); .requires(Set.of(name));
runJdeps(jdeps, expected); runJdeps(jdeps, expected);
} }
}
@DataProvider(name = "testpackage") @DataProvider(name = "testpackage")
public Object[][] expected2() { public Object[][] expected2() {
@ -162,16 +164,16 @@ 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")
public Object[][] expected3() { public Object[][] expected3() {
@ -193,17 +195,17 @@ 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(",")))
);
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
jdeps.appModulePath(MODS_DIR.toString()) jdeps.appModulePath(MODS_DIR.toString())
.addmods(modules) .addmods(modules)
.regex(name); .regex(name);
runJdeps(jdeps, expected); runJdeps(jdeps, expected);
} }
}
@DataProvider(name = "classpath") @DataProvider(name = "classpath")
public Object[][] expected4() { public Object[][] expected4() {
@ -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);
} }
} }
} }

View file

@ -151,11 +151,10 @@ 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,
roots.stream().collect(Collectors.joining(",")), paths)
);
jdeps.appModulePath(modulepath) jdeps.appModulePath(modulepath)
.addmods(roots); .addmods(roots);
Arrays.stream(paths).forEach(jdeps::addRoot); Arrays.stream(paths).forEach(jdeps::addRoot);
@ -177,4 +176,5 @@ public class ModuleTest {
jdeps.dumpOutput(System.err); jdeps.dumpOutput(System.err);
} }
}
} }

View file

@ -70,16 +70,15 @@ 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)
); try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
jdeps.verbose("-verbose:class") jdeps.verbose("-verbose:class")
.addRoot(CLASSES_DIR); .addRoot(CLASSES_DIR);
if (root != null) if (root != null)
jdeps.addmods(Set.of(root)); 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();
@ -101,5 +100,5 @@ public class SplitPackage {
jdeps.dumpOutput(System.err); jdeps.dumpOutput(System.err);
} }
}
} }

View file

@ -122,24 +122,24 @@ 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, String cmd1 = String.format("jdeps -modulepath %s -addmods %s -m %s%n", MODS_DIR,
roots.stream().collect(Collectors.joining(",")), name) roots.stream().collect(Collectors.joining(",")), name);
); try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd1)) {
jdeps.verbose("-verbose:class") jdeps.verbose("-verbose:class")
.appModulePath(MODS_DIR.toString()) .appModulePath(MODS_DIR.toString())
.addmods(roots) .addmods(roots)
.addmods(Set.of(name)); .addmods(Set.of(name));
runJdeps(jdeps, data); 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)
); try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd2)) {
jdeps.verbose("-verbose:class") jdeps.verbose("-verbose:class")
.appModulePath(LIBS_DIR.toString()) .appModulePath(LIBS_DIR.toString())
.addmods(roots) .addmods(roots)
@ -147,6 +147,7 @@ public class TransitiveDeps {
runJdeps(jdeps, data); runJdeps(jdeps, data);
} }
}
@DataProvider(name = "jars") @DataProvider(name = "jars")
public Object[][] expected2() { public Object[][] expected2() {
@ -170,15 +171,16 @@ 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) String cmd = String.format("jdeps -classpath %s %s%n", cpath, jarfile);
); try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
jdeps.verbose("-verbose:class") jdeps.verbose("-verbose:class")
.addClassPath(cpath) .addClassPath(cpath)
.addRoot(jarfile); .addRoot(jarfile);
runJdeps(jdeps, data); runJdeps(jdeps, data);
} }
}
@DataProvider(name = "compileTimeView") @DataProvider(name = "compileTimeView")
public Object[][] expected3() { public Object[][] expected3() {
@ -225,16 +227,15 @@ 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") jdeps.verbose("-verbose:class")
.addClassPath(cpath) .addClassPath(cpath)
.addRoot(jarfile); .addRoot(jarfile);
runJdeps(jdeps, data, true, 0 /* -recursive */); runJdeps(jdeps, data, true, 0 /* -recursive */);
} }
}
@DataProvider(name = "recursiveDeps") @DataProvider(name = "recursiveDeps")
public Object[][] expected4() { public Object[][] expected4() {
@ -276,15 +277,15 @@ 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)
throws IOException throws IOException
@ -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));
}); });
} }
} }