8166238: Update jdeps for GNU-style long form options

Reviewed-by: alanb
This commit is contained in:
Mandy Chung 2016-09-29 21:31:09 -07:00
parent f2eb960882
commit 33b751c3d4
7 changed files with 133 additions and 127 deletions

View File

@ -150,7 +150,7 @@ class JdepsTask {
task.options.help = true;
}
},
new Option(true, "-dotoutput") {
new Option(true, "-dotoutput", "--dot-output") {
void process(JdepsTask task, String opt, String arg) throws BadArgs {
Path p = Paths.get(arg);
if (Files.exists(p) && (!Files.isDirectory(p) || !Files.isWritable(p))) {
@ -191,7 +191,7 @@ class JdepsTask {
}
}
},
new Option(false, "-apionly") {
new Option(false, "-apionly", "--api-only") {
void process(JdepsTask task, String opt, String arg) {
task.options.apiOnly = true;
}
@ -203,7 +203,7 @@ class JdepsTask {
task.options.addmods.addAll(mods);
}
},
new Option(true, "--gen-module-info") {
new Option(true, "--generate-module-info") {
void process(JdepsTask task, String opt, String arg) throws BadArgs {
Path p = Paths.get(arg);
if (Files.exists(p) && (!Files.isDirectory(p) || !Files.isWritable(p))) {
@ -212,7 +212,7 @@ class JdepsTask {
task.options.genModuleInfo = Paths.get(arg);
}
},
new Option(false, "-jdkinternals") {
new Option(false, "-jdkinternals", "--jdk-internals") {
void process(JdepsTask task, String opt, String arg) {
task.options.findJDKInternals = true;
task.options.verbose = CLASS;
@ -263,19 +263,36 @@ class JdepsTask {
task.options.addmods.add(arg);
}
},
new Option(true, "--multi-release") {
void process(JdepsTask task, String opt, String arg) throws BadArgs {
if (arg.equalsIgnoreCase("base")) {
task.options.multiRelease = JarFile.baseVersion();
} else {
try {
int v = Integer.parseInt(arg);
if (v < 9) {
throw new BadArgs("err.invalid.arg.for.option", arg);
}
} catch (NumberFormatException x) {
throw new BadArgs("err.invalid.arg.for.option", arg);
}
task.options.multiRelease = Runtime.Version.parse(arg);
}
}
},
// ---- Target filtering options ----
new Option(true, "-p", "-package") {
new Option(true, "-p", "-package", "--package") {
void process(JdepsTask task, String opt, String arg) {
task.options.packageNames.add(arg);
}
},
new Option(true, "-e", "-regex") {
new Option(true, "-e", "-regex", "--regex") {
void process(JdepsTask task, String opt, String arg) {
task.options.regex = Pattern.compile(arg);
}
},
new Option(true, "-requires") {
new Option(true, "--require") {
void process(JdepsTask task, String opt, String arg) {
task.options.requires.add(arg);
}
@ -336,7 +353,7 @@ class JdepsTask {
}
},
new Option(false, "-I", "-inverse") {
new Option(false, "-I", "--inverse") {
void process(JdepsTask task, String opt, String arg) {
task.options.inverse = true;
// equivalent to the inverse of compile-time view analysis
@ -361,7 +378,7 @@ class JdepsTask {
}
},
new Option(false, "-version") {
new Option(false, "-version", "--version") {
void process(JdepsTask task, String opt, String arg) {
task.options.version = true;
}
@ -390,23 +407,6 @@ class JdepsTask {
}
}
},
new Option(true, "--multi-release") {
void process(JdepsTask task, String opt, String arg) throws BadArgs {
if (arg.equalsIgnoreCase("base")) {
task.options.multiRelease = JarFile.baseVersion();
} else {
try {
int v = Integer.parseInt(arg);
if (v < 9) {
throw new BadArgs("err.invalid.arg.for.option", arg);
}
} catch (NumberFormatException x) {
throw new BadArgs("err.invalid.arg.for.option", arg);
}
task.options.multiRelease = Runtime.Version.parse(arg);
}
}
},
};
private static final String PROGNAME = "jdeps";

View File

@ -16,15 +16,15 @@ main.opt.h=\
\ --help Print this usage message
main.opt.version=\
\ -version Version information
\ -version --version Version information
main.opt.v=\
\ -v -verbose Print all class level dependencies\n\
\ -v -verbose Print all class level dependences\n\
\ Equivalent to -verbose:class -filter:none.\n\
\ -verbose:package Print package-level dependencies excluding\n\
\ dependencies within the same package by default\n\
\ -verbose:class Print class-level dependencies excluding\n\
\ dependencies within the same package by default
\ -verbose:package Print package-level dependences excluding\n\
\ dependences within the same package by default\n\
\ -verbose:class Print class-level dependences excluding\n\
\ dependences within the same package by default
main.opt.s=\
\ -s -summary Print dependency summary only.
@ -42,17 +42,21 @@ main.opt.f=\
\ -filter option still applies.\n\
main.opt.p=\n\
\Options to filter dependencies:\n\
\ -p <pkgname> -package <pkgname> Finds dependences matching the given package\n\
\Options to filter dependences:\n\
\ -p <pkg>\n\
\ -package <pkg>\n\
\ --package <pkg> Finds dependences matching the given package\n\
\ name (may be given multiple times).
main.opt.e=\
\ -e <regex> -regex <regex> Finds dependences matching the given pattern.
\ -e <regex>\n\
\ -regex <regex>\n\
\ --regex <regex> Finds dependences matching the given pattern.
main.opt.requires=\
\ -requires <module-name> Finds dependences matching the given module\n\
\ name (may be given multiple times).\n\
\ -package, -regex, -requires are mutual exclusive.
main.opt.require=\
\ --require <module-name> Finds dependences matching the given module\n\
\ name (may be given multiple times). --package,\n\
\ --regex, --require are mutual exclusive.
main.opt.include=\n\
\Options to filter classes to be analyzed:\n\
@ -70,10 +74,10 @@ main.opt.cp=\
\ --class-path <path> Specify where to find class files
main.opt.module-path=\
\ --module-path <module path>... Specify module path
\ --module-path <module path> Specify module path
main.opt.upgrade-module-path=\
\ --upgrade-module-path <module path>... Specify upgrade module path
\ --upgrade-module-path <module path> Specify upgrade module path
main.opt.system=\
\ --system <java-home> Specify an alternate system module path
@ -87,22 +91,22 @@ main.opt.m=\
\ --module <module-name> Specify the root module for analysis
main.opt.R=\
\ -R -recursive Recursively traverse all run-time dependencies.\n\
\ -R -recursive Recursively traverse all run-time dependences.\n\
\ The -R option implies -filter:none. If -p,\n\
\ -e, -foption is specified, only the matching\n\
\ dependences are analyzed.
main.opt.I=\
\ -I -inverse Analyzes the dependences per other given options\n\
\ -I --inverse Analyzes the dependences per other given options\n\
\ and then find all artifacts that directly\n\
\ and indirectly depend on the matching nodes.\n\
\ This is equivalent to the inverse of\n\
\ compile-time view analysis and print\n\
\ dependency summary. This option must use\n\
\ with -requires, -package or -regex option.
\ with --require, --package or --regex option.
main.opt.compile-time=\
\ --compile-time Compile-time view of transitive dependencies\n\
\ --compile-time Compile-time view of transitive dependences\n\
\ i.e. compile-time view of -R option.\n\
\ Analyzes the dependences per other given options\n\
\ If a dependence is found from a directory,\n\
@ -110,17 +114,18 @@ main.opt.compile-time=\
\ containing archive are analyzed.
main.opt.apionly=\
\ -apionly Restrict analysis to APIs i.e. dependences\n\
\ -apionly\n\
\ --api-only Restrict analysis to APIs i.e. dependences\n\
\ from the signature of public and protected\n\
\ members of public classes including field\n\
\ type, method parameter types, returned type,\n\
\ checked exception types etc.
main.opt.gen-module-info=\
\ --gen-module-info <dir> Generate module-info.java under the specified\n\
main.opt.generate-module-info=\
\ --generate-module-info <dir> Generate module-info.java under the specified\n\
\ directory. The specified JAR files will be\n\
\ analyzed. This option cannot be used with\n\
\ -dotoutput or -cp.
\ --dot-output or --class-path.
main.opt.check=\
\ --check <module-name>[,<module-name>...\n\
@ -132,12 +137,14 @@ main.opt.check=\
main.opt.dotoutput=\
\ -dotoutput <dir> Destination directory for DOT file output
\ -dotoutput <dir>\n\
\ --dot-output <dir> Destination directory for DOT file output
main.opt.jdkinternals=\
\ -jdkinternals Finds class-level dependences on JDK internal\n\
\ -jdkinternals\n\
\ --jdk-internals Finds class-level dependences on JDK internal\n\
\ APIs. By default, it analyzes all classes\n\
\ on -classpath and input files unless -include\n\
\ on --class-path and input files unless -include\n\
\ option is specified. This option cannot be\n\
\ used with -p, -e and -s options.\n\
\ WARNING: JDK internal APIs are inaccessible.
@ -147,8 +154,8 @@ main.opt.depth=\
\ dependency analysis
main.opt.q=\
\ -q -quiet Do not show missing dependencies from \n\
\ -genmoduleinfo output.
\ -q -quiet Do not show missing dependences from \n\
\ --generate-module-info output.
main.opt.multi-release=\
\ --multi-release <version> Specifies the version when processing\n\
@ -159,16 +166,15 @@ err.unknown.option=unknown option: {0}
err.missing.arg=no value given for {0}
err.invalid.arg.for.option=invalid argument for option: {0}
err.option.after.class=option must be specified before classes: {0}
err.genmoduleinfo.not.jarfile={0} not valid for --gen-module-info option (must be non-modular JAR file)
err.genmoduleinfo.not.jarfile={0} not valid for --generate-module-info option (must be non-modular JAR file)
err.profiles.msg=No profile information
err.exception.message={0}
err.invalid.path=invalid path: {0}
err.invalid.module.option=Cannot set {0} with {1} option.
err.invalid.filters=Only one of -package (-p), -regex (-e), -requires option can be set
err.invalid.filters=Only one of --package (-p), --regex (-e), --require option can be set
err.module.not.found=module not found: {0}
err.root.module.not.set=root module set empty
err.invalid.inverse.option={0} cannot be used with -inverse option
err.inverse.filter.not.set={0} cannot be used with -inverse option
err.invalid.inverse.option={0} cannot be used with --inverse option
err.multirelease.option.exists={0} is not a multi-release jar file, but the --multi-release option is set
err.multirelease.option.notfound={0} is a multi-release jar file, but the --multi-release option is not set
err.multirelease.version.associated=class {0} already associated with version {1}, trying to add version {2}
@ -178,7 +184,7 @@ warn.split.package=package {0} defined in {1} {2}
warn.replace.useJDKInternals=\
JDK internal APIs are unsupported and private to JDK implementation that are\n\
subject to be removed or changed incompatibly and could break your application.\n\
Please modify your code to eliminate dependency on any JDK internal APIs.\n\
Please modify your code to eliminate dependence on any JDK internal APIs.\n\
For the most recent update on JDK internal API replacements, please check:\n\
{0}

View File

@ -135,7 +135,7 @@ public class APIDeps {
"java.util.Set",
"c.C", "d.D", "c.I", "e.E", "m.Bar"},
new String[] {"compact1", testDirBasename, mDir.getName()},
new String[] {"-classpath", testDir.getPath(), "-verbose", "-P", "-apionly"});
new String[] {"-classpath", testDir.getPath(), "-verbose", "-P", "--api-only"});
return errors;
}

View File

@ -116,7 +116,7 @@ public class ShowReplacement {
@Test
public void removedPackage() {
Path file = Paths.get("q", "RemovedPackage.class");
String[] output = JdepsUtil.jdeps("-jdkinternals", CLASSES_DIR.resolve(file).toString());
String[] output = JdepsUtil.jdeps("--jdk-internals", CLASSES_DIR.resolve(file).toString());
int i = 0;
// expect no replacement
while (i < output.length && !output[i].contains("Suggested Replacement")) {

View File

@ -23,7 +23,7 @@
/*
* @test
* @summary Tests jdeps --gen-module-info option
* @summary Tests jdeps --generate-module-info option
* @library ../lib
* @build CompilerUtils JdepsUtil
* @modules jdk.jdeps/com.sun.tools.jdeps
@ -106,7 +106,7 @@ public class GenModuleInfo {
.map(mn -> LIBS_DIR.resolve(mn + ".jar"))
.map(Path::toString);
JdepsUtil.jdeps(Stream.concat(Stream.of("--gen-module-info", DEST_DIR.toString()),
JdepsUtil.jdeps(Stream.concat(Stream.of("--generate-module-info", DEST_DIR.toString()),
files).toArray(String[]::new));
// check file exists

View File

@ -91,7 +91,7 @@ public class InverseDeps {
@DataProvider(name = "testrequires")
public Object[][] expected1() {
return new Object[][] {
// -requires and result
// --require and result
{ "java.sql", new String[][] {
new String[] { "java.sql", "m5" },
}
@ -117,7 +117,7 @@ public class InverseDeps {
@Test(dataProvider = "testrequires")
public void testrequires(String name, String[][] expected) throws Exception {
String cmd1 = String.format("jdeps -inverse --module-path %s -requires %s --add-modules %s%n",
String cmd1 = String.format("jdeps --inverse --module-path %s --require %s --add-modules %s%n",
MODS_DIR, name, modules.stream().collect(Collectors.joining(",")));
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd1)) {
@ -128,7 +128,7 @@ public class InverseDeps {
runJdeps(jdeps, expected);
}
String cmd2 = String.format("jdeps -inverse --module-path %s -requires %s" +
String cmd2 = String.format("jdeps --inverse --module-path %s --require %s" +
" --add-modules ALL-MODULE-PATH%n", LIBS_DIR, name);
// automatic module
@ -164,7 +164,7 @@ public class InverseDeps {
@Test(dataProvider = "testpackage")
public void testpackage(String name, String[][] expected) throws Exception {
String cmd = String.format("jdeps -inverse --module-path %s -package %s --add-modules %s%n",
String cmd = String.format("jdeps --inverse --module-path %s -package %s --add-modules %s%n",
MODS_DIR, name, modules.stream().collect(Collectors.joining(",")));
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
jdeps.appModulePath(MODS_DIR.toString())
@ -195,7 +195,7 @@ public class InverseDeps {
@Test(dataProvider = "testregex")
public void testregex(String name, String[][] expected) throws Exception {
String cmd = String.format("jdeps -inverse --module-path %s -regex %s --add-modules %s%n",
String cmd = String.format("jdeps --inverse --module-path %s -regex %s --add-modules %s%n",
MODS_DIR, name, modules.stream().collect(Collectors.joining(",")));
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
@ -240,7 +240,7 @@ public class InverseDeps {
Path jarfile = LIBS_DIR.resolve("m7.jar");
String cmd1 = 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);
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd1)) {
jdeps.verbose("-verbose:class")
@ -253,7 +253,7 @@ public class InverseDeps {
Set<Path> paths = modules.stream()
.map(mn -> LIBS_DIR.resolve(mn + ".jar"))
.collect(Collectors.toSet());
String cmd2 = String.format("jdeps -inverse -regex %s %s%n", name, paths);
String cmd2 = String.format("jdeps --inverse -regex %s %s%n", name, paths);
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd2)) {
jdeps.verbose("-verbose:class").regex(name);
paths.forEach(jdeps::addRoot);

View File

@ -24,7 +24,7 @@
module m3 {
requires public java.sql;
requires public m2;
requires java.logging; // TODO: --gen-module-info to do transitive reduction
requires java.logging; // TODO: --generate-module-info to do transitive reduction
requires public m1;
exports p3;
}