author | mchung |
Wed, 21 Nov 2018 22:34:01 -0800 | |
changeset 52650 | c16b6cc93272 |
parent 48543 | 7067fe4e054e |
permissions | -rw-r--r-- |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1 |
/* |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48253
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
4 |
* |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
10 |
* |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
16 |
* |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
20 |
* |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
23 |
* questions. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
24 |
*/ |
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
30846
diff
changeset
|
25 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
26 |
package com.sun.tools.jdeps; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
27 |
|
41997 | 28 |
import com.sun.tools.jdeps.Analyzer.Type; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
29 |
import static com.sun.tools.jdeps.Analyzer.Type.*; |
36526 | 30 |
import static com.sun.tools.jdeps.JdepsWriter.*; |
41997 | 31 |
import static java.util.stream.Collectors.*; |
36526 | 32 |
|
33 |
import java.io.IOException; |
|
34 |
import java.io.PrintWriter; |
|
35 |
import java.lang.module.ResolutionException; |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
36 |
import java.nio.file.Files; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
37 |
import java.nio.file.Path; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
38 |
import java.nio.file.Paths; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
39 |
import java.text.MessageFormat; |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
40 |
import java.util.*; |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
41 |
import java.util.jar.JarFile; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
42 |
import java.util.regex.Pattern; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
43 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
44 |
/** |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
45 |
* Implementation for the jdeps tool for static class dependency analysis. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
46 |
*/ |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
47 |
class JdepsTask { |
38524 | 48 |
static interface BadArguments { |
49 |
String getKey(); |
|
50 |
Object[] getArgs(); |
|
51 |
boolean showUsage(); |
|
52 |
} |
|
53 |
static class BadArgs extends Exception implements BadArguments { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
54 |
static final long serialVersionUID = 8765093759964640721L; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
55 |
BadArgs(String key, Object... args) { |
16290
b0b4f52de7ea
8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
15030
diff
changeset
|
56 |
super(JdepsTask.getMessage(key, args)); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
57 |
this.key = key; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
58 |
this.args = args; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
59 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
60 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
61 |
BadArgs showUsage(boolean b) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
62 |
showUsage = b; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
63 |
return this; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
64 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
65 |
final String key; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
66 |
final Object[] args; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
67 |
boolean showUsage; |
38524 | 68 |
|
69 |
@Override |
|
70 |
public String getKey() { |
|
71 |
return key; |
|
72 |
} |
|
73 |
||
74 |
@Override |
|
75 |
public Object[] getArgs() { |
|
76 |
return args; |
|
77 |
} |
|
78 |
||
79 |
@Override |
|
80 |
public boolean showUsage() { |
|
81 |
return showUsage; |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
static class UncheckedBadArgs extends RuntimeException implements BadArguments { |
|
86 |
static final long serialVersionUID = -1L; |
|
87 |
final BadArgs cause; |
|
88 |
UncheckedBadArgs(BadArgs cause) { |
|
89 |
super(cause); |
|
90 |
this.cause = cause; |
|
91 |
} |
|
92 |
@Override |
|
93 |
public String getKey() { |
|
94 |
return cause.key; |
|
95 |
} |
|
96 |
||
97 |
@Override |
|
98 |
public Object[] getArgs() { |
|
99 |
return cause.args; |
|
100 |
} |
|
101 |
||
102 |
@Override |
|
103 |
public boolean showUsage() { |
|
104 |
return cause.showUsage; |
|
105 |
} |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
106 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
107 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
108 |
static abstract class Option { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
109 |
Option(boolean hasArg, String... aliases) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
110 |
this.hasArg = hasArg; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
111 |
this.aliases = aliases; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
112 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
113 |
|
41997 | 114 |
Option(boolean hasArg, CommandOption cmd) { |
115 |
this(hasArg, cmd.names()); |
|
116 |
} |
|
117 |
||
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
118 |
boolean isHidden() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
119 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
120 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
121 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
122 |
boolean matches(String opt) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
123 |
for (String a : aliases) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
124 |
if (a.equals(opt)) |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
125 |
return true; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
126 |
if (hasArg && opt.startsWith(a + "=")) |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
127 |
return true; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
128 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
129 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
130 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
131 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
132 |
boolean ignoreRest() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
133 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
134 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
135 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
136 |
abstract void process(JdepsTask task, String opt, String arg) throws BadArgs; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
137 |
final boolean hasArg; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
138 |
final String[] aliases; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
139 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
140 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
141 |
static abstract class HiddenOption extends Option { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
142 |
HiddenOption(boolean hasArg, String... aliases) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
143 |
super(hasArg, aliases); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
144 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
145 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
146 |
boolean isHidden() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
147 |
return true; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
148 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
149 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
150 |
|
41997 | 151 |
enum CommandOption { |
152 |
ANALYZE_DEPS(""), |
|
153 |
GENERATE_DOT_FILE("-dotoutput", "--dot-output"), |
|
154 |
GENERATE_MODULE_INFO("--generate-module-info"), |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
155 |
GENERATE_OPEN_MODULE("--generate-open-module"), |
41997 | 156 |
LIST_DEPS("--list-deps"), |
157 |
LIST_REDUCED_DEPS("--list-reduced-deps"), |
|
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
158 |
PRINT_MODULE_DEPS("--print-module-deps"), |
41997 | 159 |
CHECK_MODULES("--check"); |
160 |
||
161 |
private final String[] names; |
|
162 |
CommandOption(String... names) { |
|
163 |
this.names = names; |
|
164 |
} |
|
165 |
||
166 |
String[] names() { |
|
167 |
return names; |
|
168 |
} |
|
169 |
||
170 |
@Override |
|
171 |
public String toString() { |
|
172 |
return names[0]; |
|
173 |
} |
|
174 |
} |
|
175 |
||
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
176 |
static Option[] recognizedOptions = { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
177 |
new Option(false, "-h", "-?", "-help", "--help") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
178 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
179 |
task.options.help = true; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
180 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
181 |
}, |
41997 | 182 |
new Option(true, CommandOption.GENERATE_DOT_FILE) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
183 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
41997 | 184 |
if (task.command != null) { |
185 |
throw new BadArgs("err.command.set", task.command, opt); |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
186 |
} |
41997 | 187 |
task.command = task.genDotFile(Paths.get(arg)); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
188 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
189 |
}, |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
190 |
new Option(false, "-s", "-summary") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
191 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
192 |
task.options.showSummary = true; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
193 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
194 |
}, |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
195 |
new Option(false, "-v", "-verbose", |
38524 | 196 |
"-verbose:module", |
197 |
"-verbose:package", |
|
198 |
"-verbose:class") { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
199 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
200 |
switch (opt) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
201 |
case "-v": |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
202 |
case "-verbose": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
203 |
task.options.verbose = VERBOSE; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
204 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
205 |
task.options.filterSamePackage = false; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
206 |
break; |
38524 | 207 |
case "-verbose:module": |
208 |
task.options.verbose = MODULE; |
|
209 |
break; |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
210 |
case "-verbose:package": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
211 |
task.options.verbose = PACKAGE; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
212 |
break; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
213 |
case "-verbose:class": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
214 |
task.options.verbose = CLASS; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
215 |
break; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
216 |
default: |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
217 |
throw new BadArgs("err.invalid.arg.for.option", opt); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
218 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
219 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
220 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
221 |
new Option(false, "-apionly", "--api-only") { |
38524 | 222 |
void process(JdepsTask task, String opt, String arg) { |
223 |
task.options.apiOnly = true; |
|
224 |
} |
|
225 |
}, |
|
41997 | 226 |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
227 |
new Option(false, "-jdkinternals", "--jdk-internals") { |
38524 | 228 |
void process(JdepsTask task, String opt, String arg) { |
229 |
task.options.findJDKInternals = true; |
|
230 |
if (task.options.includePattern == null) { |
|
231 |
task.options.includePattern = Pattern.compile(".*"); |
|
232 |
} |
|
233 |
} |
|
234 |
}, |
|
41997 | 235 |
|
38524 | 236 |
// ---- paths option ---- |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
237 |
new Option(true, "-cp", "-classpath", "--class-path") { |
38524 | 238 |
void process(JdepsTask task, String opt, String arg) { |
239 |
task.options.classpath = arg; |
|
240 |
} |
|
241 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
242 |
new Option(true, "--module-path") { |
38524 | 243 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
244 |
task.options.modulePath = arg; |
|
245 |
} |
|
246 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
247 |
new Option(true, "--upgrade-module-path") { |
38524 | 248 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
249 |
task.options.upgradeModulePath = arg; |
|
250 |
} |
|
251 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
252 |
new Option(true, "--system") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
253 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
254 |
if (arg.equals("none")) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
255 |
task.options.systemModulePath = null; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
256 |
} else { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
257 |
Path path = Paths.get(arg); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
258 |
if (Files.isRegularFile(path.resolve("lib").resolve("modules"))) |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
259 |
task.options.systemModulePath = arg; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
260 |
else |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
261 |
throw new BadArgs("err.invalid.path", arg); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
262 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
263 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
264 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
265 |
new Option(true, "--add-modules") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
266 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
267 |
Set<String> mods = Set.of(arg.split(",")); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
268 |
task.options.addmods.addAll(mods); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
269 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
270 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
271 |
new Option(true, "--multi-release") { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
272 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
273 |
if (arg.equalsIgnoreCase("base")) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
274 |
task.options.multiRelease = JarFile.baseVersion(); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
275 |
} else { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
276 |
try { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
277 |
int v = Integer.parseInt(arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
278 |
if (v < 9) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
279 |
throw new BadArgs("err.invalid.arg.for.option", arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
280 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
281 |
} catch (NumberFormatException x) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
282 |
throw new BadArgs("err.invalid.arg.for.option", arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
283 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
284 |
task.options.multiRelease = Runtime.Version.parse(arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
285 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
286 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
287 |
}, |
47308
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
288 |
new Option(false, "-q", "-quiet") { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
289 |
void process(JdepsTask task, String opt, String arg) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
290 |
task.options.nowarning = true; |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
291 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
292 |
}, |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
293 |
new Option(false, "-version", "--version") { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
294 |
void process(JdepsTask task, String opt, String arg) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
295 |
task.options.version = true; |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
296 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
297 |
}, |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
298 |
|
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
299 |
// ---- module-specific options ---- |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
300 |
|
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
301 |
new Option(true, "-m", "--module") { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
302 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
303 |
if (!task.options.rootModules.isEmpty()) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
304 |
throw new BadArgs("err.option.already.specified", opt); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
305 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
306 |
task.options.rootModules.add(arg); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
307 |
task.options.addmods.add(arg); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
308 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
309 |
}, |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
310 |
new Option(true, CommandOption.GENERATE_MODULE_INFO) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
311 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
312 |
if (task.command != null) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
313 |
throw new BadArgs("err.command.set", task.command, opt); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
314 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
315 |
task.command = task.genModuleInfo(Paths.get(arg), false); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
316 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
317 |
}, |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
318 |
new Option(true, CommandOption.GENERATE_OPEN_MODULE) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
319 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
320 |
if (task.command != null) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
321 |
throw new BadArgs("err.command.set", task.command, opt); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
322 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
323 |
task.command = task.genModuleInfo(Paths.get(arg), true); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
324 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
325 |
}, |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
326 |
new Option(true, CommandOption.CHECK_MODULES) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
327 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
328 |
if (task.command != null) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
329 |
throw new BadArgs("err.command.set", task.command, opt); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
330 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
331 |
Set<String> mods = Set.of(arg.split(",")); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
332 |
task.options.addmods.addAll(mods); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
333 |
task.command = task.checkModuleDeps(mods); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
334 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
335 |
}, |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
336 |
new Option(false, CommandOption.LIST_DEPS) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
337 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
338 |
if (task.command != null) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
339 |
throw new BadArgs("err.command.set", task.command, opt); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
340 |
} |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
341 |
task.command = task.listModuleDeps(CommandOption.LIST_DEPS); |
47308
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
342 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
343 |
}, |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
344 |
new Option(false, CommandOption.LIST_REDUCED_DEPS) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
345 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
346 |
if (task.command != null) { |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
347 |
throw new BadArgs("err.command.set", task.command, opt); |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
348 |
} |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
349 |
task.command = task.listModuleDeps(CommandOption.LIST_REDUCED_DEPS); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
350 |
} |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
351 |
}, |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
352 |
new Option(false, CommandOption.PRINT_MODULE_DEPS) { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
353 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
354 |
if (task.command != null) { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
355 |
throw new BadArgs("err.command.set", task.command, opt); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
356 |
} |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
357 |
task.command = task.listModuleDeps(CommandOption.PRINT_MODULE_DEPS); |
47308
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
358 |
} |
5f351a1131e0
8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents:
47216
diff
changeset
|
359 |
}, |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
360 |
new Option(false, "--ignore-missing-deps") { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
361 |
void process(JdepsTask task, String opt, String arg) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
362 |
task.options.ignoreMissingDeps = true; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
363 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
364 |
}, |
38524 | 365 |
|
366 |
// ---- Target filtering options ---- |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
367 |
new Option(true, "-p", "-package", "--package") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
368 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
369 |
task.options.packageNames.add(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
370 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
371 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
372 |
new Option(true, "-e", "-regex", "--regex") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
373 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 374 |
task.options.regex = Pattern.compile(arg); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
375 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
376 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
377 |
new Option(true, "--require") { |
36526 | 378 |
void process(JdepsTask task, String opt, String arg) { |
379 |
task.options.requires.add(arg); |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
380 |
task.options.addmods.add(arg); |
36526 | 381 |
} |
382 |
}, |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
383 |
new Option(true, "-f", "-filter") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
384 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 385 |
task.options.filterRegex = Pattern.compile(arg); |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
386 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
387 |
}, |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
388 |
new Option(false, "-filter:package", |
36526 | 389 |
"-filter:archive", "-filter:module", |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
390 |
"-filter:none") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
391 |
void process(JdepsTask task, String opt, String arg) { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
392 |
switch (opt) { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
393 |
case "-filter:package": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
394 |
task.options.filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
395 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
396 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
397 |
case "-filter:archive": |
36526 | 398 |
case "-filter:module": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
399 |
task.options.filterSameArchive = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
400 |
task.options.filterSamePackage = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
401 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
402 |
case "-filter:none": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
403 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
404 |
task.options.filterSamePackage = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
405 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
406 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
407 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
408 |
}, |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
409 |
new Option(false, "--missing-deps") { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
410 |
void process(JdepsTask task, String opt, String arg) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
411 |
task.options.findMissingDeps = true; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
412 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
413 |
}, |
38524 | 414 |
|
415 |
// ---- Source filtering options ---- |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
416 |
new Option(true, "-include") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
417 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
418 |
task.options.includePattern = Pattern.compile(arg); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
419 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
420 |
}, |
38524 | 421 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
422 |
new Option(false, "-P", "-profile") { |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
16290
diff
changeset
|
423 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
424 |
task.options.showProfile = true; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
425 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
426 |
}, |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
427 |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
428 |
new Option(false, "-R", "-recursive", "--recursive") { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
429 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
430 |
task.options.recursive = Options.RECURSIVE; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
431 |
// turn off filtering |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
432 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
433 |
task.options.filterSamePackage = false; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
434 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
435 |
}, |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
436 |
new Option(false, "--no-recursive") { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
437 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
438 |
task.options.recursive = Options.NO_RECURSIVE; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
439 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
440 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
441 |
new Option(false, "-I", "--inverse") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
442 |
void process(JdepsTask task, String opt, String arg) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
443 |
task.options.inverse = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
444 |
// equivalent to the inverse of compile-time view analysis |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
445 |
task.options.compileTimeView = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
446 |
task.options.filterSamePackage = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
447 |
task.options.filterSameArchive = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
448 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
449 |
}, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
450 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
451 |
new Option(false, "--compile-time") { |
36526 | 452 |
void process(JdepsTask task, String opt, String arg) { |
453 |
task.options.compileTimeView = true; |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
454 |
task.options.recursive = Options.RECURSIVE; |
36526 | 455 |
task.options.filterSamePackage = true; |
456 |
task.options.filterSameArchive = true; |
|
457 |
} |
|
458 |
}, |
|
38524 | 459 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
460 |
new HiddenOption(false, "-fullversion") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
461 |
void process(JdepsTask task, String opt, String arg) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
462 |
task.options.fullVersion = true; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
463 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
464 |
}, |
21503
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
465 |
new HiddenOption(false, "-showlabel") { |
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
466 |
void process(JdepsTask task, String opt, String arg) { |
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
467 |
task.options.showLabel = true; |
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
468 |
} |
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
469 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
470 |
new HiddenOption(false, "--hide-show-module") { |
38524 | 471 |
void process(JdepsTask task, String opt, String arg) { |
472 |
task.options.showModule = false; |
|
473 |
} |
|
474 |
}, |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
475 |
new HiddenOption(true, "-depth") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
476 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
477 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
478 |
task.options.depth = Integer.parseInt(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
479 |
} catch (NumberFormatException e) { |
16560 | 480 |
throw new BadArgs("err.invalid.arg.for.option", opt); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
481 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
482 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
483 |
}, |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
484 |
}; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
485 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
486 |
private static final String PROGNAME = "jdeps"; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
487 |
private final Options options = new Options(); |
38524 | 488 |
private final List<String> inputArgs = new ArrayList<>(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
489 |
|
41997 | 490 |
private Command command; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
491 |
private PrintWriter log; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
492 |
void setLog(PrintWriter out) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
493 |
log = out; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
494 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
495 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
496 |
/** |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
497 |
* Result codes. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
498 |
*/ |
38524 | 499 |
static final int EXIT_OK = 0, // Completed with no errors. |
500 |
EXIT_ERROR = 1, // Completed but reported errors. |
|
501 |
EXIT_CMDERR = 2, // Bad command-line arguments |
|
502 |
EXIT_SYSERR = 3, // System error or resource exhaustion. |
|
503 |
EXIT_ABNORMAL = 4; // terminated abnormally |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
504 |
|
38524 | 505 |
int run(String... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
506 |
if (log == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
507 |
log = new PrintWriter(System.out); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
508 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
509 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
510 |
handleOptions(args); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
511 |
if (options.help) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
512 |
showHelp(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
513 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
514 |
if (options.version || options.fullVersion) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
515 |
showVersion(options.fullVersion); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
516 |
} |
41997 | 517 |
if (options.help || options.version || options.fullVersion) { |
518 |
return EXIT_OK; |
|
519 |
} |
|
36526 | 520 |
if (options.numFilters() > 1) { |
521 |
reportError("err.invalid.filters"); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
522 |
return EXIT_CMDERR; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
523 |
} |
36526 | 524 |
|
41997 | 525 |
// default command to analyze dependences |
526 |
if (command == null) { |
|
527 |
command = analyzeDeps(); |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
528 |
} |
41997 | 529 |
if (!command.checkOptions()) { |
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
530 |
return EXIT_CMDERR; |
38524 | 531 |
} |
25874 | 532 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
533 |
boolean ok = run(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
534 |
return ok ? EXIT_OK : EXIT_ERROR; |
41997 | 535 |
|
38524 | 536 |
} catch (BadArgs|UncheckedBadArgs e) { |
537 |
reportError(e.getKey(), e.getArgs()); |
|
538 |
if (e.showUsage()) { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
539 |
log.println(getMessage("main.usage.summary", PROGNAME)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
540 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
541 |
return EXIT_CMDERR; |
36526 | 542 |
} catch (ResolutionException e) { |
543 |
reportError("err.exception.message", e.getMessage()); |
|
544 |
return EXIT_CMDERR; |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
545 |
} catch (IOException e) { |
36526 | 546 |
e.printStackTrace(); |
38524 | 547 |
return EXIT_CMDERR; |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
548 |
} catch (MultiReleaseException e) { |
44182
ce2f0cbc81b9
8176333: jdeps error message should include a proper MR jar file name
mchung
parents:
43873
diff
changeset
|
549 |
reportError(e.getKey(), e.getParams()); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
550 |
return EXIT_CMDERR; // could be EXIT_ABNORMAL sometimes |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
551 |
} finally { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
552 |
log.flush(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
553 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
554 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
555 |
|
38524 | 556 |
boolean run() throws IOException { |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
557 |
try (JdepsConfiguration config = buildConfig()) { |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
558 |
if (!options.nowarning) { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
559 |
// detect split packages |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
560 |
config.splitPackages().entrySet() |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
561 |
.stream() |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
562 |
.sorted(Map.Entry.comparingByKey()) |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
563 |
.forEach(e -> warning("warn.split.package", |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
564 |
e.getKey(), |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
565 |
e.getValue().stream().collect(joining(" ")))); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
566 |
} |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
567 |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
568 |
// check if any module specified in --add-modules, --require, and -m is missing |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
569 |
options.addmods.stream() |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
570 |
.filter(mn -> !JdepsConfiguration.isToken(mn)) |
38530 | 571 |
.forEach(mn -> config.findModule(mn).orElseThrow(() -> |
572 |
new UncheckedBadArgs(new BadArgs("err.module.not.found", mn)))); |
|
38524 | 573 |
|
41997 | 574 |
return command.run(config); |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
575 |
} |
25874 | 576 |
} |
577 |
||
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
578 |
private JdepsConfiguration buildConfig() throws IOException { |
38524 | 579 |
JdepsConfiguration.Builder builder = |
580 |
new JdepsConfiguration.Builder(options.systemModulePath); |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
581 |
|
38524 | 582 |
builder.upgradeModulePath(options.upgradeModulePath) |
583 |
.appModulePath(options.modulePath) |
|
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
584 |
.addmods(options.addmods) |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
585 |
.addmods(command.addModules()); |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
586 |
|
38524 | 587 |
if (options.classpath != null) |
588 |
builder.addClassPath(options.classpath); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
589 |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
590 |
if (options.multiRelease != null) |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
591 |
builder.multiRelease(options.multiRelease); |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
592 |
|
38524 | 593 |
// build the root set of archives to be analyzed |
594 |
for (String s : inputArgs) { |
|
595 |
Path p = Paths.get(s); |
|
36526 | 596 |
if (Files.exists(p)) { |
38524 | 597 |
builder.addRoot(p); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
598 |
} else { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
599 |
warning("warn.invalid.arg", s); |
36526 | 600 |
} |
25874 | 601 |
} |
602 |
||
38524 | 603 |
return builder.build(); |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
604 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
605 |
|
41997 | 606 |
// ---- factory methods to create a Command |
607 |
||
608 |
private AnalyzeDeps analyzeDeps() throws BadArgs { |
|
609 |
return options.inverse ? new InverseAnalyzeDeps() |
|
610 |
: new AnalyzeDeps(); |
|
611 |
} |
|
612 |
||
613 |
private GenDotFile genDotFile(Path dir) throws BadArgs { |
|
614 |
if (Files.exists(dir) && (!Files.isDirectory(dir) || !Files.isWritable(dir))) { |
|
615 |
throw new BadArgs("err.invalid.path", dir.toString()); |
|
616 |
} |
|
617 |
return new GenDotFile(dir); |
|
618 |
} |
|
619 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
620 |
private GenModuleInfo genModuleInfo(Path dir, boolean openModule) throws BadArgs { |
41997 | 621 |
if (Files.exists(dir) && (!Files.isDirectory(dir) || !Files.isWritable(dir))) { |
622 |
throw new BadArgs("err.invalid.path", dir.toString()); |
|
623 |
} |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
624 |
return new GenModuleInfo(dir, openModule); |
41997 | 625 |
} |
626 |
||
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
627 |
private ListModuleDeps listModuleDeps(CommandOption option) throws BadArgs { |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
628 |
// do transitive dependence analysis unless --no-recursive is set |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
629 |
if (options.recursive != Options.NO_RECURSIVE) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
630 |
options.recursive = Options.RECURSIVE; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
631 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
632 |
// no need to record the dependences on the same archive or same package |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
633 |
options.filterSameArchive = true; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
634 |
options.filterSamePackage = true; |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
635 |
switch (option) { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
636 |
case LIST_DEPS: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
637 |
return new ListModuleDeps(option, true, false); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
638 |
case LIST_REDUCED_DEPS: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
639 |
return new ListModuleDeps(option, true, true); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
640 |
case PRINT_MODULE_DEPS: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
641 |
return new ListModuleDeps(option, false, true, ","); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
642 |
default: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
643 |
throw new IllegalArgumentException(option.toString()); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
644 |
} |
41997 | 645 |
} |
646 |
||
647 |
private CheckModuleDeps checkModuleDeps(Set<String> mods) throws BadArgs { |
|
648 |
return new CheckModuleDeps(mods); |
|
649 |
} |
|
650 |
||
651 |
abstract class Command { |
|
652 |
final CommandOption option; |
|
653 |
protected Command(CommandOption option) { |
|
654 |
this.option = option; |
|
655 |
} |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
656 |
|
41997 | 657 |
/** |
658 |
* Returns true if the command-line options are all valid; |
|
659 |
* otherwise, returns false. |
|
660 |
*/ |
|
661 |
abstract boolean checkOptions(); |
|
662 |
||
663 |
/** |
|
664 |
* Do analysis |
|
665 |
*/ |
|
666 |
abstract boolean run(JdepsConfiguration config) throws IOException; |
|
667 |
||
668 |
/** |
|
669 |
* Includes all modules on system module path and application module path |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
670 |
* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
671 |
* When a named module is analyzed, it will analyze the dependences |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
672 |
* only. The method should be overridden when this command should |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
673 |
* analyze all modules instead. |
41997 | 674 |
*/ |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
675 |
Set<String> addModules() { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
676 |
return Set.of(); |
41997 | 677 |
} |
678 |
||
679 |
@Override |
|
680 |
public String toString() { |
|
681 |
return option.toString(); |
|
682 |
} |
|
683 |
} |
|
684 |
||
685 |
||
686 |
/** |
|
687 |
* Analyze dependences |
|
688 |
*/ |
|
689 |
class AnalyzeDeps extends Command { |
|
690 |
JdepsWriter writer; |
|
691 |
AnalyzeDeps() { |
|
692 |
this(CommandOption.ANALYZE_DEPS); |
|
693 |
} |
|
694 |
||
695 |
AnalyzeDeps(CommandOption option) { |
|
696 |
super(option); |
|
697 |
} |
|
698 |
||
699 |
@Override |
|
700 |
boolean checkOptions() { |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
701 |
if (options.findJDKInternals || options.findMissingDeps) { |
41997 | 702 |
// cannot set any filter, -verbose and -summary option |
703 |
if (options.showSummary || options.verbose != null) { |
|
704 |
reportError("err.invalid.options", "-summary or -verbose", |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
705 |
options.findJDKInternals ? "-jdkinternals" : "--missing-deps"); |
41997 | 706 |
return false; |
707 |
} |
|
708 |
if (options.hasFilter()) { |
|
709 |
reportError("err.invalid.options", "--package, --regex, --require", |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
710 |
options.findJDKInternals ? "-jdkinternals" : "--missing-deps"); |
41997 | 711 |
return false; |
712 |
} |
|
713 |
} |
|
714 |
if (options.showSummary) { |
|
715 |
// -summary cannot use with -verbose option |
|
716 |
if (options.verbose != null) { |
|
717 |
reportError("err.invalid.options", "-v, -verbose", "-s, -summary"); |
|
718 |
return false; |
|
719 |
} |
|
720 |
} |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
721 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
722 |
if (!inputArgs.isEmpty() && !options.rootModules.isEmpty()) { |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
723 |
reportError("err.invalid.arg.for.option", "-m"); |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
724 |
} |
41997 | 725 |
if (inputArgs.isEmpty() && !options.hasSourcePath()) { |
726 |
showHelp(); |
|
727 |
return false; |
|
728 |
} |
|
729 |
return true; |
|
730 |
} |
|
731 |
||
732 |
/* |
|
733 |
* Default is to show package-level dependencies |
|
734 |
*/ |
|
735 |
Type getAnalyzerType() { |
|
736 |
if (options.showSummary) |
|
737 |
return Type.SUMMARY; |
|
738 |
||
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
739 |
if (options.findJDKInternals || options.findMissingDeps) |
41997 | 740 |
return Type.CLASS; |
741 |
||
742 |
// default to package-level verbose |
|
743 |
return options.verbose != null ? options.verbose : PACKAGE; |
|
744 |
} |
|
745 |
||
746 |
@Override |
|
747 |
boolean run(JdepsConfiguration config) throws IOException { |
|
748 |
Type type = getAnalyzerType(); |
|
749 |
// default to package-level verbose |
|
750 |
JdepsWriter writer = new SimpleWriter(log, |
|
751 |
type, |
|
752 |
options.showProfile, |
|
753 |
options.showModule); |
|
754 |
||
755 |
return run(config, writer, type); |
|
36526 | 756 |
} |
757 |
||
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
758 |
boolean run(JdepsConfiguration config, JdepsWriter writer, Type type) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
759 |
throws IOException |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
760 |
{ |
41997 | 761 |
// analyze the dependencies |
762 |
DepsAnalyzer analyzer = new DepsAnalyzer(config, |
|
763 |
dependencyFilter(config), |
|
764 |
writer, |
|
765 |
type, |
|
766 |
options.apiOnly); |
|
767 |
||
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
768 |
boolean ok = analyzer.run(options.compileTimeView, options.depth()); |
41997 | 769 |
|
770 |
// print skipped entries, if any |
|
771 |
if (!options.nowarning) { |
|
772 |
analyzer.archives() |
|
773 |
.forEach(archive -> archive.reader() |
|
774 |
.skippedEntries().stream() |
|
775 |
.forEach(name -> warning("warn.skipped.entry", name))); |
|
776 |
} |
|
777 |
||
778 |
if (options.findJDKInternals && !options.nowarning) { |
|
779 |
Map<String, String> jdkInternals = new TreeMap<>(); |
|
780 |
Set<String> deps = analyzer.dependences(); |
|
781 |
// find the ones with replacement |
|
782 |
deps.forEach(cn -> replacementFor(cn).ifPresent( |
|
783 |
repl -> jdkInternals.put(cn, repl)) |
|
784 |
); |
|
785 |
||
786 |
if (!deps.isEmpty()) { |
|
787 |
log.println(); |
|
788 |
warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url")); |
|
789 |
} |
|
38524 | 790 |
|
41997 | 791 |
if (!jdkInternals.isEmpty()) { |
792 |
log.println(); |
|
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
793 |
String internalApiTitle = getMessage("internal.api.column.header"); |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
794 |
String replacementApiTitle = getMessage("public.api.replacement.column.header"); |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
795 |
log.format("%-40s %s%n", internalApiTitle, replacementApiTitle); |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
796 |
log.format("%-40s %s%n", |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
797 |
internalApiTitle.replaceAll(".", "-"), |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
798 |
replacementApiTitle.replaceAll(".", "-")); |
41997 | 799 |
jdkInternals.entrySet().stream() |
800 |
.forEach(e -> { |
|
801 |
String key = e.getKey(); |
|
802 |
String[] lines = e.getValue().split("\\n"); |
|
803 |
for (String s : lines) { |
|
804 |
log.format("%-40s %s%n", key, s); |
|
805 |
key = ""; |
|
806 |
} |
|
807 |
}); |
|
808 |
} |
|
809 |
} |
|
810 |
return ok; |
|
811 |
} |
|
812 |
} |
|
813 |
||
38524 | 814 |
|
41997 | 815 |
class InverseAnalyzeDeps extends AnalyzeDeps { |
816 |
InverseAnalyzeDeps() { |
|
817 |
} |
|
818 |
||
819 |
@Override |
|
820 |
boolean checkOptions() { |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
821 |
if (options.recursive != -1 || options.depth != -1) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
822 |
reportError("err.invalid.options", "--recursive and --no-recursive", "--inverse"); |
41997 | 823 |
return false; |
824 |
} |
|
825 |
||
826 |
if (options.numFilters() == 0) { |
|
827 |
reportError("err.filter.not.specified"); |
|
828 |
return false; |
|
829 |
} |
|
830 |
||
831 |
if (!super.checkOptions()) { |
|
832 |
return false; |
|
833 |
} |
|
834 |
||
835 |
return true; |
|
41443
6398801363f2
8167014: jdeps: Missing message: warn.skipped.entry
mchung
parents:
41442
diff
changeset
|
836 |
} |
36526 | 837 |
|
41997 | 838 |
@Override |
839 |
boolean run(JdepsConfiguration config) throws IOException { |
|
840 |
Type type = getAnalyzerType(); |
|
841 |
||
842 |
InverseDepsAnalyzer analyzer = |
|
843 |
new InverseDepsAnalyzer(config, |
|
844 |
dependencyFilter(config), |
|
845 |
writer, |
|
846 |
type, |
|
847 |
options.apiOnly); |
|
848 |
boolean ok = analyzer.run(); |
|
849 |
||
850 |
log.println(); |
|
851 |
if (!options.requires.isEmpty()) |
|
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
852 |
log.println(getMessage("inverse.transitive.dependencies.on", |
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
853 |
options.requires)); |
41997 | 854 |
else |
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
855 |
log.println(getMessage("inverse.transitive.dependencies.matching", |
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
856 |
options.regex != null |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
857 |
? options.regex.toString() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
858 |
: "packages " + options.packageNames)); |
41997 | 859 |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
860 |
analyzer.inverseDependences() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
861 |
.stream() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
862 |
.sorted(comparator()) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
863 |
.map(this::toInversePath) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
864 |
.forEach(log::println); |
41997 | 865 |
return ok; |
866 |
} |
|
867 |
||
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
868 |
private String toInversePath(Deque<Archive> path) { |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
869 |
return path.stream() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
870 |
.map(Archive::getName) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
871 |
.collect(joining(" <- ")); |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
872 |
} |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
873 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
874 |
/* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
875 |
* Returns a comparator for sorting the inversed path, grouped by |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
876 |
* the first module name, then the shortest path and then sort by |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
877 |
* the module names of each path |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
878 |
*/ |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
879 |
private Comparator<Deque<Archive>> comparator() { |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
880 |
return Comparator.<Deque<Archive>, String> |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
881 |
comparing(deque -> deque.peekFirst().getName()) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
882 |
.thenComparingInt(Deque::size) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
883 |
.thenComparing(this::toInversePath); |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
884 |
} |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
885 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
886 |
/* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
887 |
* Returns true if --require is specified so that all modules are |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
888 |
* analyzed to find all modules that depend on the modules specified in the |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
889 |
* --require option directly and indirectly |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
890 |
*/ |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
891 |
Set<String> addModules() { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
892 |
return options.requires.size() > 0 ? Set.of("ALL-SYSTEM") : Set.of(); |
41997 | 893 |
} |
894 |
} |
|
895 |
||
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
896 |
|
41997 | 897 |
class GenModuleInfo extends Command { |
898 |
final Path dir; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
899 |
final boolean openModule; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
900 |
GenModuleInfo(Path dir, boolean openModule) { |
41997 | 901 |
super(CommandOption.GENERATE_MODULE_INFO); |
902 |
this.dir = dir; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
903 |
this.openModule = openModule; |
41997 | 904 |
} |
905 |
||
906 |
@Override |
|
907 |
boolean checkOptions() { |
|
908 |
if (options.classpath != null) { |
|
909 |
reportError("err.invalid.options", "-classpath", |
|
910 |
option); |
|
911 |
return false; |
|
912 |
} |
|
913 |
if (options.hasFilter()) { |
|
914 |
reportError("err.invalid.options", "--package, --regex, --require", |
|
915 |
option); |
|
916 |
return false; |
|
917 |
} |
|
918 |
return true; |
|
919 |
} |
|
920 |
||
921 |
@Override |
|
922 |
boolean run(JdepsConfiguration config) throws IOException { |
|
923 |
// check if any JAR file contains unnamed package |
|
924 |
for (String arg : inputArgs) { |
|
925 |
try (ClassFileReader reader = ClassFileReader.newInstance(Paths.get(arg))) { |
|
926 |
Optional<String> classInUnnamedPackage = |
|
927 |
reader.entries().stream() |
|
928 |
.filter(n -> n.endsWith(".class")) |
|
929 |
.filter(cn -> toPackageName(cn).isEmpty()) |
|
930 |
.findFirst(); |
|
931 |
||
932 |
if (classInUnnamedPackage.isPresent()) { |
|
933 |
if (classInUnnamedPackage.get().equals("module-info.class")) { |
|
934 |
reportError("err.genmoduleinfo.not.jarfile", arg); |
|
935 |
} else { |
|
936 |
reportError("err.genmoduleinfo.unnamed.package", arg); |
|
937 |
} |
|
938 |
return false; |
|
939 |
} |
|
940 |
} |
|
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
941 |
} |
38524 | 942 |
|
41997 | 943 |
ModuleInfoBuilder builder |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
944 |
= new ModuleInfoBuilder(config, inputArgs, dir, openModule); |
41997 | 945 |
boolean ok = builder.run(); |
946 |
||
947 |
if (!ok && !options.nowarning) { |
|
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
948 |
reportError("err.missing.dependences"); |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
949 |
builder.visitMissingDeps(new SimpleDepVisitor()); |
38524 | 950 |
} |
41997 | 951 |
return ok; |
36526 | 952 |
} |
41997 | 953 |
|
954 |
private String toPackageName(String name) { |
|
955 |
int i = name.lastIndexOf('/'); |
|
956 |
return i > 0 ? name.replace('/', '.').substring(0, i) : ""; |
|
957 |
} |
|
36526 | 958 |
} |
959 |
||
41997 | 960 |
class CheckModuleDeps extends Command { |
961 |
final Set<String> modules; |
|
962 |
CheckModuleDeps(Set<String> mods) { |
|
963 |
super(CommandOption.CHECK_MODULES); |
|
964 |
this.modules = mods; |
|
965 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
966 |
|
41997 | 967 |
@Override |
968 |
boolean checkOptions() { |
|
969 |
if (!inputArgs.isEmpty()) { |
|
970 |
reportError("err.invalid.options", inputArgs, "--check"); |
|
971 |
return false; |
|
972 |
} |
|
973 |
return true; |
|
974 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
975 |
|
41997 | 976 |
@Override |
977 |
boolean run(JdepsConfiguration config) throws IOException { |
|
978 |
if (!config.initialArchives().isEmpty()) { |
|
979 |
String list = config.initialArchives().stream() |
|
980 |
.map(Archive::getPathName).collect(joining(" ")); |
|
981 |
throw new UncheckedBadArgs(new BadArgs("err.invalid.options", |
|
982 |
list, "--check")); |
|
983 |
} |
|
984 |
return new ModuleAnalyzer(config, log, modules).run(); |
|
985 |
} |
|
986 |
||
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
987 |
/* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
988 |
* Returns true to analyze all modules |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
989 |
*/ |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
990 |
Set<String> addModules() { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
991 |
return Set.of("ALL-SYSTEM", "ALL-MODULE-PATH"); |
41997 | 992 |
} |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
993 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
994 |
|
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
995 |
class ListModuleDeps extends Command { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
996 |
final boolean jdkinternals; |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
997 |
final boolean reduced; |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
998 |
final String separator; |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
999 |
ListModuleDeps(CommandOption option, boolean jdkinternals, boolean reduced) { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
1000 |
this(option, jdkinternals, reduced, System.getProperty("line.separator")); |
41997 | 1001 |
} |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
1002 |
ListModuleDeps(CommandOption option, boolean jdkinternals, boolean reduced, String sep) { |
41997 | 1003 |
super(option); |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
1004 |
this.jdkinternals = jdkinternals; |
41997 | 1005 |
this.reduced = reduced; |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
1006 |
this.separator = sep; |
41997 | 1007 |
} |
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1008 |
|
41997 | 1009 |
@Override |
1010 |
boolean checkOptions() { |
|
1011 |
if (options.showSummary || options.verbose != null) { |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1012 |
reportError("err.invalid.options", "-summary or -verbose", option); |
41997 | 1013 |
return false; |
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1014 |
} |
41997 | 1015 |
if (options.findJDKInternals) { |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1016 |
reportError("err.invalid.options", "-jdkinternals", option); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1017 |
return false; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1018 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1019 |
if (options.findMissingDeps) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1020 |
reportError("err.invalid.options", "--missing-deps", option); |
41997 | 1021 |
return false; |
1022 |
} |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1023 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1024 |
if (!inputArgs.isEmpty() && !options.rootModules.isEmpty()) { |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1025 |
reportError("err.invalid.arg.for.option", "-m"); |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1026 |
} |
41997 | 1027 |
if (inputArgs.isEmpty() && !options.hasSourcePath()) { |
1028 |
showHelp(); |
|
1029 |
return false; |
|
1030 |
} |
|
1031 |
return true; |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1032 |
} |
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1033 |
|
41997 | 1034 |
@Override |
1035 |
boolean run(JdepsConfiguration config) throws IOException { |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1036 |
ModuleExportsAnalyzer analyzer = new ModuleExportsAnalyzer(config, |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1037 |
dependencyFilter(config), |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1038 |
jdkinternals, |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1039 |
reduced, |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1040 |
log, |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1041 |
separator); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1042 |
boolean ok = analyzer.run(options.depth(), options.ignoreMissingDeps); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1043 |
if (!ok) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1044 |
reportError("err.cant.list.module.deps"); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1045 |
log.println(); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1046 |
analyzer.visitMissingDeps(new SimpleDepVisitor()); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1047 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1048 |
return ok; |
41997 | 1049 |
} |
38524 | 1050 |
} |
1051 |
||
41997 | 1052 |
class GenDotFile extends AnalyzeDeps { |
1053 |
final Path dotOutputDir; |
|
1054 |
GenDotFile(Path dotOutputDir) { |
|
1055 |
super(CommandOption.GENERATE_DOT_FILE); |
|
1056 |
||
1057 |
this.dotOutputDir = dotOutputDir; |
|
1058 |
} |
|
1059 |
||
1060 |
@Override |
|
1061 |
boolean run(JdepsConfiguration config) throws IOException { |
|
1062 |
if ((options.showSummary || options.verbose == MODULE) && |
|
1063 |
!options.addmods.isEmpty() && inputArgs.isEmpty()) { |
|
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
1064 |
// generate dot graph from the resolved graph from module |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
1065 |
// resolution. No class dependency analysis is performed. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
1066 |
return new ModuleDotGraph(config, options.apiOnly) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
1067 |
.genDotFiles(dotOutputDir); |
41997 | 1068 |
} |
1069 |
||
1070 |
Type type = getAnalyzerType(); |
|
1071 |
JdepsWriter writer = new DotFileWriter(dotOutputDir, |
|
1072 |
type, |
|
1073 |
options.showProfile, |
|
1074 |
options.showModule, |
|
1075 |
options.showLabel); |
|
1076 |
return run(config, writer, type); |
|
1077 |
} |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1078 |
} |
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1079 |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1080 |
class SimpleDepVisitor implements Analyzer.Visitor { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1081 |
private Archive source; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1082 |
@Override |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1083 |
public void visitDependence(String origin, Archive originArchive, String target, Archive targetArchive) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1084 |
if (source != originArchive) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1085 |
source = originArchive; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1086 |
log.format("%s%n", originArchive); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1087 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1088 |
log.format(" %-50s -> %-50s %s%n", origin, target, targetArchive.getName()); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1089 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1090 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1091 |
|
38524 | 1092 |
/** |
1093 |
* Returns a filter used during dependency analysis |
|
1094 |
*/ |
|
1095 |
private JdepsFilter dependencyFilter(JdepsConfiguration config) { |
|
41860
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
1096 |
// Filter specified by -filter, -package, -regex, and --require options |
36526 | 1097 |
JdepsFilter.Builder builder = new JdepsFilter.Builder(); |
1098 |
||
1099 |
// source filters |
|
1100 |
builder.includePattern(options.includePattern); |
|
1101 |
||
42840
dfe1a03d4db4
8171418: Remove jdeps internal --include-system-modules option
mchung
parents:
42827
diff
changeset
|
1102 |
// target filters |
36526 | 1103 |
builder.filter(options.filterSamePackage, options.filterSameArchive); |
1104 |
builder.findJDKInternals(options.findJDKInternals); |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1105 |
builder.findMissingDeps(options.findMissingDeps); |
36526 | 1106 |
|
41860
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
1107 |
// --require |
36526 | 1108 |
if (!options.requires.isEmpty()) { |
38524 | 1109 |
options.requires.stream() |
1110 |
.forEach(mn -> { |
|
1111 |
Module m = config.findModule(mn).get(); |
|
1112 |
builder.requires(mn, m.packages()); |
|
1113 |
}); |
|
36526 | 1114 |
} |
1115 |
// -regex |
|
1116 |
if (options.regex != null) |
|
1117 |
builder.regex(options.regex); |
|
1118 |
// -package |
|
1119 |
if (!options.packageNames.isEmpty()) |
|
1120 |
builder.packages(options.packageNames); |
|
1121 |
// -filter |
|
1122 |
if (options.filterRegex != null) |
|
1123 |
builder.filter(options.filterRegex); |
|
1124 |
||
38524 | 1125 |
return builder.build(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1126 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1127 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1128 |
public void handleOptions(String[] args) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1129 |
// process options |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1130 |
for (int i=0; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1131 |
if (args[i].charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1132 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1133 |
Option option = getOption(name); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1134 |
String param = null; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1135 |
if (option.hasArg) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1136 |
if (name.startsWith("-") && name.indexOf('=') > 0) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1137 |
param = name.substring(name.indexOf('=') + 1, name.length()); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1138 |
} else if (i + 1 < args.length) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1139 |
param = args[++i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1140 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1141 |
if (param == null || param.isEmpty() || param.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1142 |
throw new BadArgs("err.missing.arg", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1143 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1144 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1145 |
option.process(this, name, param); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1146 |
if (option.ignoreRest()) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1147 |
i = args.length; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1148 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1149 |
} else { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1150 |
// process rest of the input arguments |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1151 |
for (; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1152 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1153 |
if (name.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1154 |
throw new BadArgs("err.option.after.class", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1155 |
} |
38524 | 1156 |
inputArgs.add(name); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1157 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1158 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1159 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1160 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1161 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1162 |
private Option getOption(String name) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1163 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1164 |
if (o.matches(name)) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1165 |
return o; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1166 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1167 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1168 |
throw new BadArgs("err.unknown.option", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1169 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1170 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1171 |
private void reportError(String key, Object... args) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1172 |
log.println(getMessage("error.prefix") + " " + getMessage(key, args)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1173 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1174 |
|
38524 | 1175 |
void warning(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1176 |
log.println(getMessage("warn.prefix") + " " + getMessage(key, args)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1177 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1178 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1179 |
private void showHelp() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1180 |
log.println(getMessage("main.usage", PROGNAME)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1181 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1182 |
String name = o.aliases[0].substring(1); // there must always be at least one name |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1183 |
name = name.charAt(0) == '-' ? name.substring(1) : name; |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48253
diff
changeset
|
1184 |
if (o.isHidden() || name.startsWith("filter:")) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1185 |
continue; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1186 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1187 |
log.println(getMessage("main.opt." + name)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1188 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1189 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1190 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1191 |
private void showVersion(boolean full) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1192 |
log.println(version(full ? "full" : "release")); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1193 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1194 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1195 |
private String version(String key) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1196 |
// key=version: mm.nn.oo[-milestone] |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1197 |
// key=full: mm.mm.oo[-milestone]-build |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1198 |
try { |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1199 |
return ResourceBundleHelper.getVersion(key); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1200 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1201 |
return getMessage("version.unknown", System.getProperty("java.version")); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1202 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1203 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1204 |
|
16290
b0b4f52de7ea
8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
15030
diff
changeset
|
1205 |
static String getMessage(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1206 |
try { |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1207 |
return MessageFormat.format(ResourceBundleHelper.getMessage(key), args); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1208 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1209 |
throw new InternalError("Missing message: " + key); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1210 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1211 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1212 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1213 |
private static class Options { |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1214 |
static final int NO_RECURSIVE = 0; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1215 |
static final int RECURSIVE = 1; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1216 |
boolean help; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1217 |
boolean version; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1218 |
boolean fullVersion; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1219 |
boolean showProfile; |
38524 | 1220 |
boolean showModule = true; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1221 |
boolean showSummary; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1222 |
boolean apiOnly; |
21503
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
1223 |
boolean showLabel; |
22007
907f7054db16
8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents:
21503
diff
changeset
|
1224 |
boolean findJDKInternals; |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1225 |
boolean findMissingDeps; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1226 |
boolean ignoreMissingDeps; |
36526 | 1227 |
boolean nowarning = false; |
41997 | 1228 |
Analyzer.Type verbose; |
1229 |
// default filter references from same package |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
1230 |
boolean filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
1231 |
boolean filterSameArchive = false; |
36526 | 1232 |
Pattern filterRegex; |
38524 | 1233 |
String classpath; |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1234 |
int recursive = -1; // 0: --no-recursive, 1: --recursive |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1235 |
int depth = -1; |
36526 | 1236 |
Set<String> requires = new HashSet<>(); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1237 |
Set<String> packageNames = new HashSet<>(); |
36526 | 1238 |
Pattern regex; // apply to the dependences |
38524 | 1239 |
Pattern includePattern; |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
1240 |
boolean inverse = false; |
36526 | 1241 |
boolean compileTimeView = false; |
38524 | 1242 |
String systemModulePath = System.getProperty("java.home"); |
36526 | 1243 |
String upgradeModulePath; |
1244 |
String modulePath; |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1245 |
Set<String> rootModules = new HashSet<>(); |
38524 | 1246 |
Set<String> addmods = new HashSet<>(); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
1247 |
Runtime.Version multiRelease; |
41997 | 1248 |
|
1249 |
boolean hasSourcePath() { |
|
42840
dfe1a03d4db4
8171418: Remove jdeps internal --include-system-modules option
mchung
parents:
42827
diff
changeset
|
1250 |
return !addmods.isEmpty() || includePattern != null; |
41997 | 1251 |
} |
36526 | 1252 |
|
1253 |
boolean hasFilter() { |
|
1254 |
return numFilters() > 0; |
|
1255 |
} |
|
1256 |
||
1257 |
int numFilters() { |
|
1258 |
int count = 0; |
|
1259 |
if (requires.size() > 0) count++; |
|
1260 |
if (regex != null) count++; |
|
1261 |
if (packageNames.size() > 0) count++; |
|
1262 |
return count; |
|
1263 |
} |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1264 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1265 |
int depth() { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1266 |
// ignore -depth if --no-recursive is set |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1267 |
if (recursive == NO_RECURSIVE) |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1268 |
return 1; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1269 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1270 |
// depth == 0 if recursive |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1271 |
if (recursive == RECURSIVE && depth == -1) |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1272 |
return 0; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1273 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1274 |
// default depth is 1 unless specified via -depth option |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1275 |
return depth == -1 ? 1 : depth; |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1276 |
} |
38524 | 1277 |
} |
36526 | 1278 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1279 |
private static class ResourceBundleHelper { |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1280 |
static final String LS = System.lineSeparator(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1281 |
static final ResourceBundle versionRB; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1282 |
static final ResourceBundle bundle; |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1283 |
static final ResourceBundle jdkinternals; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1284 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1285 |
static { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1286 |
Locale locale = Locale.getDefault(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1287 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1288 |
bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1289 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1290 |
throw new InternalError("Cannot find jdeps resource bundle for locale " + locale); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1291 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1292 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1293 |
versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1294 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1295 |
throw new InternalError("version.resource.missing"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1296 |
} |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1297 |
try { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1298 |
jdkinternals = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdkinternals"); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1299 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1300 |
throw new InternalError("Cannot find jdkinternals resource bundle"); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1301 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1302 |
} |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1303 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1304 |
static String getMessage(String key) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1305 |
return bundle.getString(key).replace("\n", LS); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1306 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1307 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1308 |
static String getVersion(String key) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1309 |
if (ResourceBundleHelper.versionRB == null) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1310 |
return System.getProperty("java.version"); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1311 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1312 |
return versionRB.getString(key).replace("\n", LS); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1313 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1314 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1315 |
static String getSuggestedReplacement(String key) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1316 |
return ResourceBundleHelper.jdkinternals.getString(key).replace("\n", LS); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1317 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1318 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1319 |
|
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1320 |
/** |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1321 |
* Returns the recommended replacement API for the given classname; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1322 |
* or return null if replacement API is not known. |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1323 |
*/ |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
1324 |
private Optional<String> replacementFor(String cn) { |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1325 |
String name = cn; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1326 |
String value = null; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1327 |
while (value == null && name != null) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1328 |
try { |
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
48543
diff
changeset
|
1329 |
value = ResourceBundleHelper.getSuggestedReplacement(name); |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1330 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1331 |
// go up one subpackage level |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1332 |
int i = name.lastIndexOf('.'); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1333 |
name = i > 0 ? name.substring(0, i) : null; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1334 |
} |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1335 |
} |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
1336 |
return Optional.ofNullable(value); |
36526 | 1337 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1338 |
} |