author | serb |
Sat, 09 Jun 2018 13:33:35 -0700 | |
changeset 50647 | a98ff7c2103d |
parent 48543 | 7067fe4e054e |
child 52650 | c16b6cc93272 |
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 |
}, |
38524 | 360 |
|
361 |
// ---- Target filtering options ---- |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
362 |
new Option(true, "-p", "-package", "--package") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
363 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
364 |
task.options.packageNames.add(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
365 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
366 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
367 |
new Option(true, "-e", "-regex", "--regex") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
368 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 369 |
task.options.regex = Pattern.compile(arg); |
15030
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, "--require") { |
36526 | 373 |
void process(JdepsTask task, String opt, String arg) { |
374 |
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
|
375 |
task.options.addmods.add(arg); |
36526 | 376 |
} |
377 |
}, |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
378 |
new Option(true, "-f", "-filter") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
379 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 380 |
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
|
381 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
382 |
}, |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
383 |
new Option(false, "-filter:package", |
36526 | 384 |
"-filter:archive", "-filter:module", |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
385 |
"-filter:none") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
386 |
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
|
387 |
switch (opt) { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
388 |
case "-filter:package": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
389 |
task.options.filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
390 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
391 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
392 |
case "-filter:archive": |
36526 | 393 |
case "-filter:module": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
394 |
task.options.filterSameArchive = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
395 |
task.options.filterSamePackage = 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:none": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
398 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
399 |
task.options.filterSamePackage = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
400 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
401 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
402 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
403 |
}, |
38524 | 404 |
|
405 |
// ---- Source filtering options ---- |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
406 |
new Option(true, "-include") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
407 |
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
|
408 |
task.options.includePattern = Pattern.compile(arg); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
409 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
410 |
}, |
38524 | 411 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
412 |
new Option(false, "-P", "-profile") { |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
16290
diff
changeset
|
413 |
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
|
414 |
task.options.showProfile = true; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
415 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
416 |
}, |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
417 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
418 |
new Option(false, "-R", "-recursive") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
419 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
420 |
task.options.depth = 0; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
421 |
// turn off filtering |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
422 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
423 |
task.options.filterSamePackage = false; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
424 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
425 |
}, |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
426 |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
427 |
new Option(false, "-I", "--inverse") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
428 |
void process(JdepsTask task, String opt, String arg) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
429 |
task.options.inverse = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
430 |
// equivalent to the inverse of compile-time view analysis |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
431 |
task.options.compileTimeView = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
432 |
task.options.filterSamePackage = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
433 |
task.options.filterSameArchive = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
434 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
435 |
}, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
436 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
437 |
new Option(false, "--compile-time") { |
36526 | 438 |
void process(JdepsTask task, String opt, String arg) { |
439 |
task.options.compileTimeView = true; |
|
440 |
task.options.filterSamePackage = true; |
|
441 |
task.options.filterSameArchive = true; |
|
442 |
task.options.depth = 0; |
|
443 |
} |
|
444 |
}, |
|
38524 | 445 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
446 |
new HiddenOption(false, "-fullversion") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
447 |
void process(JdepsTask task, String opt, String arg) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
448 |
task.options.fullVersion = true; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
449 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
450 |
}, |
21503
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
451 |
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
|
452 |
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
|
453 |
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
|
454 |
} |
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
455 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
456 |
new HiddenOption(false, "--hide-show-module") { |
38524 | 457 |
void process(JdepsTask task, String opt, String arg) { |
458 |
task.options.showModule = false; |
|
459 |
} |
|
460 |
}, |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
461 |
new HiddenOption(true, "-depth") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
462 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
463 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
464 |
task.options.depth = Integer.parseInt(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
465 |
} catch (NumberFormatException e) { |
16560 | 466 |
throw new BadArgs("err.invalid.arg.for.option", opt); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
467 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
468 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
469 |
}, |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
470 |
}; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
471 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
472 |
private static final String PROGNAME = "jdeps"; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
473 |
private final Options options = new Options(); |
38524 | 474 |
private final List<String> inputArgs = new ArrayList<>(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
475 |
|
41997 | 476 |
private Command command; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
477 |
private PrintWriter log; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
478 |
void setLog(PrintWriter out) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
479 |
log = out; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
480 |
} |
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 |
* Result codes. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
484 |
*/ |
38524 | 485 |
static final int EXIT_OK = 0, // Completed with no errors. |
486 |
EXIT_ERROR = 1, // Completed but reported errors. |
|
487 |
EXIT_CMDERR = 2, // Bad command-line arguments |
|
488 |
EXIT_SYSERR = 3, // System error or resource exhaustion. |
|
489 |
EXIT_ABNORMAL = 4; // terminated abnormally |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
490 |
|
38524 | 491 |
int run(String... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
492 |
if (log == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
493 |
log = new PrintWriter(System.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 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
496 |
handleOptions(args); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
497 |
if (options.help) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
498 |
showHelp(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
499 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
500 |
if (options.version || options.fullVersion) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
501 |
showVersion(options.fullVersion); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
502 |
} |
41997 | 503 |
if (options.help || options.version || options.fullVersion) { |
504 |
return EXIT_OK; |
|
505 |
} |
|
36526 | 506 |
if (options.numFilters() > 1) { |
507 |
reportError("err.invalid.filters"); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
508 |
return EXIT_CMDERR; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
509 |
} |
36526 | 510 |
|
41997 | 511 |
// default command to analyze dependences |
512 |
if (command == null) { |
|
513 |
command = analyzeDeps(); |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
514 |
} |
41997 | 515 |
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
|
516 |
return EXIT_CMDERR; |
38524 | 517 |
} |
25874 | 518 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
519 |
boolean ok = run(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
520 |
return ok ? EXIT_OK : EXIT_ERROR; |
41997 | 521 |
|
38524 | 522 |
} catch (BadArgs|UncheckedBadArgs e) { |
523 |
reportError(e.getKey(), e.getArgs()); |
|
524 |
if (e.showUsage()) { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
525 |
log.println(getMessage("main.usage.summary", PROGNAME)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
526 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
527 |
return EXIT_CMDERR; |
36526 | 528 |
} catch (ResolutionException e) { |
529 |
reportError("err.exception.message", e.getMessage()); |
|
530 |
return EXIT_CMDERR; |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
531 |
} catch (IOException e) { |
36526 | 532 |
e.printStackTrace(); |
38524 | 533 |
return EXIT_CMDERR; |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
534 |
} catch (MultiReleaseException e) { |
44182
ce2f0cbc81b9
8176333: jdeps error message should include a proper MR jar file name
mchung
parents:
43873
diff
changeset
|
535 |
reportError(e.getKey(), e.getParams()); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
536 |
return EXIT_CMDERR; // could be EXIT_ABNORMAL sometimes |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
537 |
} finally { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
538 |
log.flush(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
539 |
} |
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 |
|
38524 | 542 |
boolean run() throws IOException { |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
543 |
try (JdepsConfiguration config = buildConfig()) { |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
544 |
if (!options.nowarning) { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
545 |
// detect split packages |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
546 |
config.splitPackages().entrySet() |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
547 |
.stream() |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
548 |
.sorted(Map.Entry.comparingByKey()) |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
549 |
.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
|
550 |
e.getKey(), |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
551 |
e.getValue().stream().collect(joining(" ")))); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
552 |
} |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
553 |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
554 |
// 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
|
555 |
options.addmods.stream() |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
556 |
.filter(mn -> !JdepsConfiguration.isToken(mn)) |
38530 | 557 |
.forEach(mn -> config.findModule(mn).orElseThrow(() -> |
558 |
new UncheckedBadArgs(new BadArgs("err.module.not.found", mn)))); |
|
38524 | 559 |
|
41997 | 560 |
return command.run(config); |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
561 |
} |
25874 | 562 |
} |
563 |
||
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
564 |
private JdepsConfiguration buildConfig() throws IOException { |
38524 | 565 |
JdepsConfiguration.Builder builder = |
566 |
new JdepsConfiguration.Builder(options.systemModulePath); |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
567 |
|
38524 | 568 |
builder.upgradeModulePath(options.upgradeModulePath) |
569 |
.appModulePath(options.modulePath) |
|
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
570 |
.addmods(options.addmods) |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
571 |
.addmods(command.addModules()); |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
572 |
|
38524 | 573 |
if (options.classpath != null) |
574 |
builder.addClassPath(options.classpath); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
575 |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
576 |
if (options.multiRelease != null) |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
577 |
builder.multiRelease(options.multiRelease); |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
578 |
|
38524 | 579 |
// build the root set of archives to be analyzed |
580 |
for (String s : inputArgs) { |
|
581 |
Path p = Paths.get(s); |
|
36526 | 582 |
if (Files.exists(p)) { |
38524 | 583 |
builder.addRoot(p); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
584 |
} else { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
585 |
warning("warn.invalid.arg", s); |
36526 | 586 |
} |
25874 | 587 |
} |
588 |
||
38524 | 589 |
return builder.build(); |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
590 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
591 |
|
41997 | 592 |
// ---- factory methods to create a Command |
593 |
||
594 |
private AnalyzeDeps analyzeDeps() throws BadArgs { |
|
595 |
return options.inverse ? new InverseAnalyzeDeps() |
|
596 |
: new AnalyzeDeps(); |
|
597 |
} |
|
598 |
||
599 |
private GenDotFile genDotFile(Path dir) throws BadArgs { |
|
600 |
if (Files.exists(dir) && (!Files.isDirectory(dir) || !Files.isWritable(dir))) { |
|
601 |
throw new BadArgs("err.invalid.path", dir.toString()); |
|
602 |
} |
|
603 |
return new GenDotFile(dir); |
|
604 |
} |
|
605 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
606 |
private GenModuleInfo genModuleInfo(Path dir, boolean openModule) throws BadArgs { |
41997 | 607 |
if (Files.exists(dir) && (!Files.isDirectory(dir) || !Files.isWritable(dir))) { |
608 |
throw new BadArgs("err.invalid.path", dir.toString()); |
|
609 |
} |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
610 |
return new GenModuleInfo(dir, openModule); |
41997 | 611 |
} |
612 |
||
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
613 |
private ListModuleDeps listModuleDeps(CommandOption option) throws BadArgs { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
614 |
switch (option) { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
615 |
case LIST_DEPS: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
616 |
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
|
617 |
case LIST_REDUCED_DEPS: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
618 |
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
|
619 |
case PRINT_MODULE_DEPS: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
620 |
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
|
621 |
default: |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
622 |
throw new IllegalArgumentException(option.toString()); |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
623 |
} |
41997 | 624 |
} |
625 |
||
626 |
private CheckModuleDeps checkModuleDeps(Set<String> mods) throws BadArgs { |
|
627 |
return new CheckModuleDeps(mods); |
|
628 |
} |
|
629 |
||
630 |
abstract class Command { |
|
631 |
final CommandOption option; |
|
632 |
protected Command(CommandOption option) { |
|
633 |
this.option = option; |
|
634 |
} |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
635 |
|
41997 | 636 |
/** |
637 |
* Returns true if the command-line options are all valid; |
|
638 |
* otherwise, returns false. |
|
639 |
*/ |
|
640 |
abstract boolean checkOptions(); |
|
641 |
||
642 |
/** |
|
643 |
* Do analysis |
|
644 |
*/ |
|
645 |
abstract boolean run(JdepsConfiguration config) throws IOException; |
|
646 |
||
647 |
/** |
|
648 |
* 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
|
649 |
* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
650 |
* 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
|
651 |
* 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
|
652 |
* analyze all modules instead. |
41997 | 653 |
*/ |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
654 |
Set<String> addModules() { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
655 |
return Set.of(); |
41997 | 656 |
} |
657 |
||
658 |
@Override |
|
659 |
public String toString() { |
|
660 |
return option.toString(); |
|
661 |
} |
|
662 |
} |
|
663 |
||
664 |
||
665 |
/** |
|
666 |
* Analyze dependences |
|
667 |
*/ |
|
668 |
class AnalyzeDeps extends Command { |
|
669 |
JdepsWriter writer; |
|
670 |
AnalyzeDeps() { |
|
671 |
this(CommandOption.ANALYZE_DEPS); |
|
672 |
} |
|
673 |
||
674 |
AnalyzeDeps(CommandOption option) { |
|
675 |
super(option); |
|
676 |
} |
|
677 |
||
678 |
@Override |
|
679 |
boolean checkOptions() { |
|
680 |
if (options.findJDKInternals) { |
|
681 |
// cannot set any filter, -verbose and -summary option |
|
682 |
if (options.showSummary || options.verbose != null) { |
|
683 |
reportError("err.invalid.options", "-summary or -verbose", |
|
684 |
"-jdkinternals"); |
|
685 |
return false; |
|
686 |
} |
|
687 |
if (options.hasFilter()) { |
|
688 |
reportError("err.invalid.options", "--package, --regex, --require", |
|
689 |
"-jdkinternals"); |
|
690 |
return false; |
|
691 |
} |
|
692 |
} |
|
693 |
if (options.showSummary) { |
|
694 |
// -summary cannot use with -verbose option |
|
695 |
if (options.verbose != null) { |
|
696 |
reportError("err.invalid.options", "-v, -verbose", "-s, -summary"); |
|
697 |
return false; |
|
698 |
} |
|
699 |
} |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
700 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
701 |
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
|
702 |
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
|
703 |
} |
41997 | 704 |
if (inputArgs.isEmpty() && !options.hasSourcePath()) { |
705 |
showHelp(); |
|
706 |
return false; |
|
707 |
} |
|
708 |
return true; |
|
709 |
} |
|
710 |
||
711 |
/* |
|
712 |
* Default is to show package-level dependencies |
|
713 |
*/ |
|
714 |
Type getAnalyzerType() { |
|
715 |
if (options.showSummary) |
|
716 |
return Type.SUMMARY; |
|
717 |
||
718 |
if (options.findJDKInternals) |
|
719 |
return Type.CLASS; |
|
720 |
||
721 |
// default to package-level verbose |
|
722 |
return options.verbose != null ? options.verbose : PACKAGE; |
|
723 |
} |
|
724 |
||
725 |
@Override |
|
726 |
boolean run(JdepsConfiguration config) throws IOException { |
|
727 |
Type type = getAnalyzerType(); |
|
728 |
// default to package-level verbose |
|
729 |
JdepsWriter writer = new SimpleWriter(log, |
|
730 |
type, |
|
731 |
options.showProfile, |
|
732 |
options.showModule); |
|
733 |
||
734 |
return run(config, writer, type); |
|
36526 | 735 |
} |
736 |
||
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
737 |
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
|
738 |
throws IOException |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
739 |
{ |
41997 | 740 |
// analyze the dependencies |
741 |
DepsAnalyzer analyzer = new DepsAnalyzer(config, |
|
742 |
dependencyFilter(config), |
|
743 |
writer, |
|
744 |
type, |
|
745 |
options.apiOnly); |
|
746 |
||
747 |
boolean ok = analyzer.run(options.compileTimeView, options.depth); |
|
748 |
||
749 |
// print skipped entries, if any |
|
750 |
if (!options.nowarning) { |
|
751 |
analyzer.archives() |
|
752 |
.forEach(archive -> archive.reader() |
|
753 |
.skippedEntries().stream() |
|
754 |
.forEach(name -> warning("warn.skipped.entry", name))); |
|
755 |
} |
|
756 |
||
757 |
if (options.findJDKInternals && !options.nowarning) { |
|
758 |
Map<String, String> jdkInternals = new TreeMap<>(); |
|
759 |
Set<String> deps = analyzer.dependences(); |
|
760 |
// find the ones with replacement |
|
761 |
deps.forEach(cn -> replacementFor(cn).ifPresent( |
|
762 |
repl -> jdkInternals.put(cn, repl)) |
|
763 |
); |
|
764 |
||
765 |
if (!deps.isEmpty()) { |
|
766 |
log.println(); |
|
767 |
warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url")); |
|
768 |
} |
|
38524 | 769 |
|
41997 | 770 |
if (!jdkInternals.isEmpty()) { |
771 |
log.println(); |
|
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
772 |
String internalApiTitle = getMessage("internal.api.column.header"); |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
773 |
String replacementApiTitle = getMessage("public.api.replacement.column.header"); |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
774 |
log.format("%-40s %s%n", internalApiTitle, replacementApiTitle); |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
775 |
log.format("%-40s %s%n", |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
776 |
internalApiTitle.replaceAll(".", "-"), |
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
777 |
replacementApiTitle.replaceAll(".", "-")); |
41997 | 778 |
jdkInternals.entrySet().stream() |
779 |
.forEach(e -> { |
|
780 |
String key = e.getKey(); |
|
781 |
String[] lines = e.getValue().split("\\n"); |
|
782 |
for (String s : lines) { |
|
783 |
log.format("%-40s %s%n", key, s); |
|
784 |
key = ""; |
|
785 |
} |
|
786 |
}); |
|
787 |
} |
|
788 |
} |
|
789 |
return ok; |
|
790 |
} |
|
791 |
} |
|
792 |
||
38524 | 793 |
|
41997 | 794 |
class InverseAnalyzeDeps extends AnalyzeDeps { |
795 |
InverseAnalyzeDeps() { |
|
796 |
} |
|
797 |
||
798 |
@Override |
|
799 |
boolean checkOptions() { |
|
800 |
if (options.depth != 1) { |
|
801 |
reportError("err.invalid.options", "-R", "--inverse"); |
|
802 |
return false; |
|
803 |
} |
|
804 |
||
805 |
if (options.numFilters() == 0) { |
|
806 |
reportError("err.filter.not.specified"); |
|
807 |
return false; |
|
808 |
} |
|
809 |
||
810 |
if (!super.checkOptions()) { |
|
811 |
return false; |
|
812 |
} |
|
813 |
||
814 |
return true; |
|
41443
6398801363f2
8167014: jdeps: Missing message: warn.skipped.entry
mchung
parents:
41442
diff
changeset
|
815 |
} |
36526 | 816 |
|
41997 | 817 |
@Override |
818 |
boolean run(JdepsConfiguration config) throws IOException { |
|
819 |
Type type = getAnalyzerType(); |
|
820 |
||
821 |
InverseDepsAnalyzer analyzer = |
|
822 |
new InverseDepsAnalyzer(config, |
|
823 |
dependencyFilter(config), |
|
824 |
writer, |
|
825 |
type, |
|
826 |
options.apiOnly); |
|
827 |
boolean ok = analyzer.run(); |
|
828 |
||
829 |
log.println(); |
|
830 |
if (!options.requires.isEmpty()) |
|
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
831 |
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
|
832 |
options.requires)); |
41997 | 833 |
else |
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
834 |
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
|
835 |
options.regex != null |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
836 |
? options.regex.toString() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
837 |
: "packages " + options.packageNames)); |
41997 | 838 |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
839 |
analyzer.inverseDependences() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
840 |
.stream() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
841 |
.sorted(comparator()) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
842 |
.map(this::toInversePath) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
843 |
.forEach(log::println); |
41997 | 844 |
return ok; |
845 |
} |
|
846 |
||
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
847 |
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
|
848 |
return path.stream() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
849 |
.map(Archive::getName) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
850 |
.collect(joining(" <- ")); |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
851 |
} |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
852 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
853 |
/* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
854 |
* 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
|
855 |
* 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
|
856 |
* 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
|
857 |
*/ |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
858 |
private Comparator<Deque<Archive>> comparator() { |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
859 |
return Comparator.<Deque<Archive>, String> |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
860 |
comparing(deque -> deque.peekFirst().getName()) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
861 |
.thenComparingInt(Deque::size) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
862 |
.thenComparing(this::toInversePath); |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
863 |
} |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
864 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
865 |
/* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
866 |
* 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
|
867 |
* 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
|
868 |
* --require option directly and indirectly |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
869 |
*/ |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
870 |
Set<String> addModules() { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
871 |
return options.requires.size() > 0 ? Set.of("ALL-SYSTEM") : Set.of(); |
41997 | 872 |
} |
873 |
} |
|
874 |
||
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
875 |
|
41997 | 876 |
class GenModuleInfo extends Command { |
877 |
final Path dir; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
878 |
final boolean openModule; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
879 |
GenModuleInfo(Path dir, boolean openModule) { |
41997 | 880 |
super(CommandOption.GENERATE_MODULE_INFO); |
881 |
this.dir = dir; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
882 |
this.openModule = openModule; |
41997 | 883 |
} |
884 |
||
885 |
@Override |
|
886 |
boolean checkOptions() { |
|
887 |
if (options.classpath != null) { |
|
888 |
reportError("err.invalid.options", "-classpath", |
|
889 |
option); |
|
890 |
return false; |
|
891 |
} |
|
892 |
if (options.hasFilter()) { |
|
893 |
reportError("err.invalid.options", "--package, --regex, --require", |
|
894 |
option); |
|
895 |
return false; |
|
896 |
} |
|
897 |
return true; |
|
898 |
} |
|
899 |
||
900 |
@Override |
|
901 |
boolean run(JdepsConfiguration config) throws IOException { |
|
902 |
// check if any JAR file contains unnamed package |
|
903 |
for (String arg : inputArgs) { |
|
904 |
try (ClassFileReader reader = ClassFileReader.newInstance(Paths.get(arg))) { |
|
905 |
Optional<String> classInUnnamedPackage = |
|
906 |
reader.entries().stream() |
|
907 |
.filter(n -> n.endsWith(".class")) |
|
908 |
.filter(cn -> toPackageName(cn).isEmpty()) |
|
909 |
.findFirst(); |
|
910 |
||
911 |
if (classInUnnamedPackage.isPresent()) { |
|
912 |
if (classInUnnamedPackage.get().equals("module-info.class")) { |
|
913 |
reportError("err.genmoduleinfo.not.jarfile", arg); |
|
914 |
} else { |
|
915 |
reportError("err.genmoduleinfo.unnamed.package", arg); |
|
916 |
} |
|
917 |
return false; |
|
918 |
} |
|
919 |
} |
|
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
920 |
} |
38524 | 921 |
|
41997 | 922 |
ModuleInfoBuilder builder |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
923 |
= new ModuleInfoBuilder(config, inputArgs, dir, openModule); |
41997 | 924 |
boolean ok = builder.run(); |
925 |
||
926 |
if (!ok && !options.nowarning) { |
|
42262
251bfd8289ee
8169659: (jdeps) missing messages for localization
reinhapa
parents:
41998
diff
changeset
|
927 |
reportError("err.missing.dependences"); |
41997 | 928 |
builder.visitMissingDeps( |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42408
diff
changeset
|
929 |
(origin, originArchive, target, targetArchive) -> { |
41997 | 930 |
if (builder.notFound(targetArchive)) |
931 |
log.format(" %-50s -> %-50s %s%n", |
|
932 |
origin, target, targetArchive.getName()); |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42408
diff
changeset
|
933 |
}); |
38524 | 934 |
} |
41997 | 935 |
return ok; |
36526 | 936 |
} |
41997 | 937 |
|
938 |
private String toPackageName(String name) { |
|
939 |
int i = name.lastIndexOf('/'); |
|
940 |
return i > 0 ? name.replace('/', '.').substring(0, i) : ""; |
|
941 |
} |
|
36526 | 942 |
} |
943 |
||
41997 | 944 |
class CheckModuleDeps extends Command { |
945 |
final Set<String> modules; |
|
946 |
CheckModuleDeps(Set<String> mods) { |
|
947 |
super(CommandOption.CHECK_MODULES); |
|
948 |
this.modules = mods; |
|
949 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
950 |
|
41997 | 951 |
@Override |
952 |
boolean checkOptions() { |
|
953 |
if (!inputArgs.isEmpty()) { |
|
954 |
reportError("err.invalid.options", inputArgs, "--check"); |
|
955 |
return false; |
|
956 |
} |
|
957 |
return true; |
|
958 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
959 |
|
41997 | 960 |
@Override |
961 |
boolean run(JdepsConfiguration config) throws IOException { |
|
962 |
if (!config.initialArchives().isEmpty()) { |
|
963 |
String list = config.initialArchives().stream() |
|
964 |
.map(Archive::getPathName).collect(joining(" ")); |
|
965 |
throw new UncheckedBadArgs(new BadArgs("err.invalid.options", |
|
966 |
list, "--check")); |
|
967 |
} |
|
968 |
return new ModuleAnalyzer(config, log, modules).run(); |
|
969 |
} |
|
970 |
||
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
971 |
/* |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
972 |
* 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
|
973 |
*/ |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
974 |
Set<String> addModules() { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47357
diff
changeset
|
975 |
return Set.of("ALL-SYSTEM", "ALL-MODULE-PATH"); |
41997 | 976 |
} |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
977 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
978 |
|
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
979 |
class ListModuleDeps extends Command { |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
980 |
final boolean jdkinternals; |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
981 |
final boolean reduced; |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
982 |
final String separator; |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
983 |
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
|
984 |
this(option, jdkinternals, reduced, System.getProperty("line.separator")); |
41997 | 985 |
} |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
986 |
ListModuleDeps(CommandOption option, boolean jdkinternals, boolean reduced, String sep) { |
41997 | 987 |
super(option); |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
988 |
this.jdkinternals = jdkinternals; |
41997 | 989 |
this.reduced = reduced; |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
990 |
this.separator = sep; |
41997 | 991 |
} |
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
992 |
|
41997 | 993 |
@Override |
994 |
boolean checkOptions() { |
|
995 |
if (options.showSummary || options.verbose != null) { |
|
996 |
reportError("err.invalid.options", "-summary or -verbose", |
|
997 |
option); |
|
998 |
return false; |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
999 |
} |
41997 | 1000 |
if (options.findJDKInternals) { |
1001 |
reportError("err.invalid.options", "-jdkinternals", |
|
1002 |
option); |
|
1003 |
return false; |
|
1004 |
} |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1005 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1006 |
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
|
1007 |
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
|
1008 |
} |
41997 | 1009 |
if (inputArgs.isEmpty() && !options.hasSourcePath()) { |
1010 |
showHelp(); |
|
1011 |
return false; |
|
1012 |
} |
|
1013 |
return true; |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1014 |
} |
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1015 |
|
41997 | 1016 |
@Override |
1017 |
boolean run(JdepsConfiguration config) throws IOException { |
|
1018 |
return new ModuleExportsAnalyzer(config, |
|
1019 |
dependencyFilter(config), |
|
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
1020 |
jdkinternals, |
41997 | 1021 |
reduced, |
47357
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
1022 |
log, |
74700c8e39e9
8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents:
47308
diff
changeset
|
1023 |
separator).run(); |
41997 | 1024 |
} |
38524 | 1025 |
} |
1026 |
||
41997 | 1027 |
|
1028 |
class GenDotFile extends AnalyzeDeps { |
|
1029 |
final Path dotOutputDir; |
|
1030 |
GenDotFile(Path dotOutputDir) { |
|
1031 |
super(CommandOption.GENERATE_DOT_FILE); |
|
1032 |
||
1033 |
this.dotOutputDir = dotOutputDir; |
|
1034 |
} |
|
1035 |
||
1036 |
@Override |
|
1037 |
boolean run(JdepsConfiguration config) throws IOException { |
|
1038 |
if ((options.showSummary || options.verbose == MODULE) && |
|
1039 |
!options.addmods.isEmpty() && inputArgs.isEmpty()) { |
|
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
1040 |
// 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
|
1041 |
// 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
|
1042 |
return new ModuleDotGraph(config, options.apiOnly) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43026
diff
changeset
|
1043 |
.genDotFiles(dotOutputDir); |
41997 | 1044 |
} |
1045 |
||
1046 |
Type type = getAnalyzerType(); |
|
1047 |
JdepsWriter writer = new DotFileWriter(dotOutputDir, |
|
1048 |
type, |
|
1049 |
options.showProfile, |
|
1050 |
options.showModule, |
|
1051 |
options.showLabel); |
|
1052 |
return run(config, writer, type); |
|
1053 |
} |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1054 |
} |
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1055 |
|
38524 | 1056 |
/** |
1057 |
* Returns a filter used during dependency analysis |
|
1058 |
*/ |
|
1059 |
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
|
1060 |
// Filter specified by -filter, -package, -regex, and --require options |
36526 | 1061 |
JdepsFilter.Builder builder = new JdepsFilter.Builder(); |
1062 |
||
1063 |
// source filters |
|
1064 |
builder.includePattern(options.includePattern); |
|
1065 |
||
42840
dfe1a03d4db4
8171418: Remove jdeps internal --include-system-modules option
mchung
parents:
42827
diff
changeset
|
1066 |
// target filters |
36526 | 1067 |
builder.filter(options.filterSamePackage, options.filterSameArchive); |
1068 |
builder.findJDKInternals(options.findJDKInternals); |
|
1069 |
||
41860
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
1070 |
// --require |
36526 | 1071 |
if (!options.requires.isEmpty()) { |
38524 | 1072 |
options.requires.stream() |
1073 |
.forEach(mn -> { |
|
1074 |
Module m = config.findModule(mn).get(); |
|
1075 |
builder.requires(mn, m.packages()); |
|
1076 |
}); |
|
36526 | 1077 |
} |
1078 |
// -regex |
|
1079 |
if (options.regex != null) |
|
1080 |
builder.regex(options.regex); |
|
1081 |
// -package |
|
1082 |
if (!options.packageNames.isEmpty()) |
|
1083 |
builder.packages(options.packageNames); |
|
1084 |
// -filter |
|
1085 |
if (options.filterRegex != null) |
|
1086 |
builder.filter(options.filterRegex); |
|
1087 |
||
38524 | 1088 |
return builder.build(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1089 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1090 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1091 |
public void handleOptions(String[] args) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1092 |
// process options |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1093 |
for (int i=0; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1094 |
if (args[i].charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1095 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1096 |
Option option = getOption(name); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1097 |
String param = null; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1098 |
if (option.hasArg) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1099 |
if (name.startsWith("-") && name.indexOf('=') > 0) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1100 |
param = name.substring(name.indexOf('=') + 1, name.length()); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1101 |
} else if (i + 1 < args.length) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1102 |
param = args[++i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1103 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1104 |
if (param == null || param.isEmpty() || param.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1105 |
throw new BadArgs("err.missing.arg", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1106 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1107 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1108 |
option.process(this, name, param); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1109 |
if (option.ignoreRest()) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1110 |
i = args.length; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1111 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1112 |
} else { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1113 |
// process rest of the input arguments |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1114 |
for (; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1115 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1116 |
if (name.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1117 |
throw new BadArgs("err.option.after.class", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1118 |
} |
38524 | 1119 |
inputArgs.add(name); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1120 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1121 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1122 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1123 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1124 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1125 |
private Option getOption(String name) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1126 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1127 |
if (o.matches(name)) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1128 |
return o; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1129 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1130 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1131 |
throw new BadArgs("err.unknown.option", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1132 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1133 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1134 |
private void reportError(String key, Object... args) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1135 |
log.println(getMessage("error.prefix") + " " + getMessage(key, args)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1136 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1137 |
|
38524 | 1138 |
void warning(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1139 |
log.println(getMessage("warn.prefix") + " " + getMessage(key, args)); |
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 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1142 |
private void showHelp() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1143 |
log.println(getMessage("main.usage", PROGNAME)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1144 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1145 |
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
|
1146 |
name = name.charAt(0) == '-' ? name.substring(1) : name; |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48253
diff
changeset
|
1147 |
if (o.isHidden() || name.startsWith("filter:")) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1148 |
continue; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1149 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1150 |
log.println(getMessage("main.opt." + name)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1151 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1152 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1153 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1154 |
private void showVersion(boolean full) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1155 |
log.println(version(full ? "full" : "release")); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1156 |
} |
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 |
private String version(String key) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1159 |
// key=version: mm.nn.oo[-milestone] |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1160 |
// key=full: mm.mm.oo[-milestone]-build |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1161 |
if (ResourceBundleHelper.versionRB == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1162 |
return System.getProperty("java.version"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1163 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1164 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1165 |
return ResourceBundleHelper.versionRB.getString(key); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1166 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1167 |
return getMessage("version.unknown", System.getProperty("java.version")); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1168 |
} |
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 |
|
16290
b0b4f52de7ea
8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
15030
diff
changeset
|
1171 |
static String getMessage(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1172 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1173 |
return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1174 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1175 |
throw new InternalError("Missing message: " + key); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1176 |
} |
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 static class Options { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1180 |
boolean help; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1181 |
boolean version; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1182 |
boolean fullVersion; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1183 |
boolean showProfile; |
38524 | 1184 |
boolean showModule = true; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1185 |
boolean showSummary; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1186 |
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
|
1187 |
boolean showLabel; |
22007
907f7054db16
8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents:
21503
diff
changeset
|
1188 |
boolean findJDKInternals; |
36526 | 1189 |
boolean nowarning = false; |
41997 | 1190 |
Analyzer.Type verbose; |
1191 |
// 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
|
1192 |
boolean filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
1193 |
boolean filterSameArchive = false; |
36526 | 1194 |
Pattern filterRegex; |
38524 | 1195 |
String classpath; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1196 |
int depth = 1; |
36526 | 1197 |
Set<String> requires = new HashSet<>(); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1198 |
Set<String> packageNames = new HashSet<>(); |
36526 | 1199 |
Pattern regex; // apply to the dependences |
38524 | 1200 |
Pattern includePattern; |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
1201 |
boolean inverse = false; |
36526 | 1202 |
boolean compileTimeView = false; |
38524 | 1203 |
String systemModulePath = System.getProperty("java.home"); |
36526 | 1204 |
String upgradeModulePath; |
1205 |
String modulePath; |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
1206 |
Set<String> rootModules = new HashSet<>(); |
38524 | 1207 |
Set<String> addmods = new HashSet<>(); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
1208 |
Runtime.Version multiRelease; |
41997 | 1209 |
|
1210 |
boolean hasSourcePath() { |
|
42840
dfe1a03d4db4
8171418: Remove jdeps internal --include-system-modules option
mchung
parents:
42827
diff
changeset
|
1211 |
return !addmods.isEmpty() || includePattern != null; |
41997 | 1212 |
} |
36526 | 1213 |
|
1214 |
boolean hasFilter() { |
|
1215 |
return numFilters() > 0; |
|
1216 |
} |
|
1217 |
||
1218 |
int numFilters() { |
|
1219 |
int count = 0; |
|
1220 |
if (requires.size() > 0) count++; |
|
1221 |
if (regex != null) count++; |
|
1222 |
if (packageNames.size() > 0) count++; |
|
1223 |
return count; |
|
1224 |
} |
|
38524 | 1225 |
} |
36526 | 1226 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1227 |
private static class ResourceBundleHelper { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1228 |
static final ResourceBundle versionRB; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1229 |
static final ResourceBundle bundle; |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1230 |
static final ResourceBundle jdkinternals; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1231 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1232 |
static { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1233 |
Locale locale = Locale.getDefault(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1234 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1235 |
bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1236 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1237 |
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
|
1238 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1239 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1240 |
versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1241 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1242 |
throw new InternalError("version.resource.missing"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1243 |
} |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1244 |
try { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1245 |
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
|
1246 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1247 |
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
|
1248 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1249 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1250 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1251 |
|
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1252 |
/** |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1253 |
* 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
|
1254 |
* 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
|
1255 |
*/ |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
1256 |
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
|
1257 |
String name = cn; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1258 |
String value = null; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1259 |
while (value == null && name != null) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1260 |
try { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1261 |
value = ResourceBundleHelper.jdkinternals.getString(name); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1262 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1263 |
// go up one subpackage level |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1264 |
int i = name.lastIndexOf('.'); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1265 |
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
|
1266 |
} |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1267 |
} |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
1268 |
return Optional.ofNullable(value); |
36526 | 1269 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1270 |
} |