author | mchung |
Sat, 12 Nov 2016 09:26:08 -0800 | |
changeset 41998 | feae61dc2280 |
parent 41997 | 79da2a8f4274 |
child 42407 | f3702cff2933 |
child 42262 | 251bfd8289ee |
permissions | -rw-r--r-- |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1 |
/* |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 2012, 2014, 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; |
36526 | 43 |
import java.util.stream.Collectors; |
44 |
import java.util.stream.Stream; |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
45 |
|
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 |
* Implementation for the jdeps tool for static class dependency analysis. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
48 |
*/ |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
49 |
class JdepsTask { |
38524 | 50 |
static interface BadArguments { |
51 |
String getKey(); |
|
52 |
Object[] getArgs(); |
|
53 |
boolean showUsage(); |
|
54 |
} |
|
55 |
static class BadArgs extends Exception implements BadArguments { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
56 |
static final long serialVersionUID = 8765093759964640721L; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
57 |
BadArgs(String key, Object... args) { |
16290
b0b4f52de7ea
8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
15030
diff
changeset
|
58 |
super(JdepsTask.getMessage(key, args)); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
59 |
this.key = key; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
60 |
this.args = args; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
61 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
62 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
63 |
BadArgs showUsage(boolean b) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
64 |
showUsage = b; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
65 |
return this; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
66 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
67 |
final String key; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
68 |
final Object[] args; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
69 |
boolean showUsage; |
38524 | 70 |
|
71 |
@Override |
|
72 |
public String getKey() { |
|
73 |
return key; |
|
74 |
} |
|
75 |
||
76 |
@Override |
|
77 |
public Object[] getArgs() { |
|
78 |
return args; |
|
79 |
} |
|
80 |
||
81 |
@Override |
|
82 |
public boolean showUsage() { |
|
83 |
return showUsage; |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
static class UncheckedBadArgs extends RuntimeException implements BadArguments { |
|
88 |
static final long serialVersionUID = -1L; |
|
89 |
final BadArgs cause; |
|
90 |
UncheckedBadArgs(BadArgs cause) { |
|
91 |
super(cause); |
|
92 |
this.cause = cause; |
|
93 |
} |
|
94 |
@Override |
|
95 |
public String getKey() { |
|
96 |
return cause.key; |
|
97 |
} |
|
98 |
||
99 |
@Override |
|
100 |
public Object[] getArgs() { |
|
101 |
return cause.args; |
|
102 |
} |
|
103 |
||
104 |
@Override |
|
105 |
public boolean showUsage() { |
|
106 |
return cause.showUsage; |
|
107 |
} |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
108 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
109 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
110 |
static abstract class Option { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
111 |
Option(boolean hasArg, String... aliases) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
112 |
this.hasArg = hasArg; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
113 |
this.aliases = aliases; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
114 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
115 |
|
41997 | 116 |
Option(boolean hasArg, CommandOption cmd) { |
117 |
this(hasArg, cmd.names()); |
|
118 |
} |
|
119 |
||
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
120 |
boolean isHidden() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
121 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
122 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
123 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
124 |
boolean matches(String opt) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
125 |
for (String a : aliases) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
126 |
if (a.equals(opt)) |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
127 |
return true; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
128 |
if (hasArg && opt.startsWith(a + "=")) |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
129 |
return true; |
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 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
132 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
133 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
134 |
boolean ignoreRest() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
135 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
136 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
137 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
138 |
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
|
139 |
final boolean hasArg; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
140 |
final String[] aliases; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
141 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
142 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
143 |
static abstract class HiddenOption extends Option { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
144 |
HiddenOption(boolean hasArg, String... aliases) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
145 |
super(hasArg, aliases); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
146 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
147 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
148 |
boolean isHidden() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
149 |
return true; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
150 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
151 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
152 |
|
41997 | 153 |
enum CommandOption { |
154 |
ANALYZE_DEPS(""), |
|
155 |
GENERATE_DOT_FILE("-dotoutput", "--dot-output"), |
|
156 |
GENERATE_MODULE_INFO("--generate-module-info"), |
|
157 |
LIST_DEPS("--list-deps"), |
|
158 |
LIST_REDUCED_DEPS("--list-reduced-deps"), |
|
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 |
|
236 |
new Option(true, CommandOption.CHECK_MODULES) { |
|
237 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
|
238 |
if (task.command != null) { |
|
239 |
throw new BadArgs("err.command.set", task.command, opt); |
|
240 |
} |
|
241 |
Set<String> mods = Set.of(arg.split(",")); |
|
242 |
task.options.addmods.addAll(mods); |
|
243 |
task.command = task.checkModuleDeps(mods); |
|
244 |
} |
|
245 |
}, |
|
246 |
new Option(true, CommandOption.GENERATE_MODULE_INFO) { |
|
247 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
|
248 |
if (task.command != null) { |
|
249 |
throw new BadArgs("err.command.set", task.command, opt); |
|
250 |
} |
|
251 |
task.command = task.genModuleInfo(Paths.get(arg)); |
|
252 |
} |
|
253 |
}, |
|
254 |
new Option(false, CommandOption.LIST_DEPS) { |
|
255 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
|
256 |
if (task.command != null) { |
|
257 |
throw new BadArgs("err.command.set", task.command, opt); |
|
258 |
} |
|
259 |
task.command = task.listModuleDeps(false); |
|
260 |
} |
|
261 |
}, |
|
262 |
new Option(false, CommandOption.LIST_REDUCED_DEPS) { |
|
263 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
|
264 |
if (task.command != null) { |
|
265 |
throw new BadArgs("err.command.set", task.command, opt); |
|
266 |
} |
|
267 |
task.command = task.listModuleDeps(true); |
|
41860
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
268 |
} |
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
269 |
}, |
38524 | 270 |
|
271 |
// ---- paths option ---- |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
272 |
new Option(true, "-cp", "-classpath", "--class-path") { |
38524 | 273 |
void process(JdepsTask task, String opt, String arg) { |
274 |
task.options.classpath = arg; |
|
275 |
} |
|
276 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
277 |
new Option(true, "--module-path") { |
38524 | 278 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
279 |
task.options.modulePath = arg; |
|
280 |
} |
|
281 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
282 |
new Option(true, "--upgrade-module-path") { |
38524 | 283 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
284 |
task.options.upgradeModulePath = arg; |
|
285 |
} |
|
286 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
287 |
new Option(true, "--system") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
288 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
289 |
if (arg.equals("none")) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
290 |
task.options.systemModulePath = null; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
291 |
} else { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
292 |
Path path = Paths.get(arg); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
293 |
if (Files.isRegularFile(path.resolve("lib").resolve("modules"))) |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
294 |
task.options.systemModulePath = arg; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
295 |
else |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
296 |
throw new BadArgs("err.invalid.path", arg); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
297 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
298 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
299 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
300 |
new Option(true, "--add-modules") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
301 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
302 |
Set<String> mods = Set.of(arg.split(",")); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
303 |
task.options.addmods.addAll(mods); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
304 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
305 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
306 |
new Option(true, "-m", "--module") { |
38524 | 307 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
308 |
task.options.rootModule = arg; |
|
309 |
task.options.addmods.add(arg); |
|
310 |
} |
|
311 |
}, |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
312 |
new Option(true, "--multi-release") { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
313 |
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
|
314 |
if (arg.equalsIgnoreCase("base")) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
315 |
task.options.multiRelease = JarFile.baseVersion(); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
316 |
} else { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
317 |
try { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
318 |
int v = Integer.parseInt(arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
319 |
if (v < 9) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
320 |
throw new BadArgs("err.invalid.arg.for.option", arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
321 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
322 |
} catch (NumberFormatException x) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
323 |
throw new BadArgs("err.invalid.arg.for.option", arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
324 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
325 |
task.options.multiRelease = Runtime.Version.parse(arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
326 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
327 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
328 |
}, |
38524 | 329 |
|
330 |
// ---- Target filtering options ---- |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
331 |
new Option(true, "-p", "-package", "--package") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
332 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
333 |
task.options.packageNames.add(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
334 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
335 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
336 |
new Option(true, "-e", "-regex", "--regex") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
337 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 338 |
task.options.regex = Pattern.compile(arg); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
339 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
340 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
341 |
new Option(true, "--require") { |
36526 | 342 |
void process(JdepsTask task, String opt, String arg) { |
343 |
task.options.requires.add(arg); |
|
344 |
} |
|
345 |
}, |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
346 |
new Option(true, "-f", "-filter") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
347 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 348 |
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
|
349 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
350 |
}, |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
351 |
new Option(false, "-filter:package", |
36526 | 352 |
"-filter:archive", "-filter:module", |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
353 |
"-filter:none") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
354 |
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
|
355 |
switch (opt) { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
356 |
case "-filter:package": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
357 |
task.options.filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
358 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
359 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
360 |
case "-filter:archive": |
36526 | 361 |
case "-filter:module": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
362 |
task.options.filterSameArchive = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
363 |
task.options.filterSamePackage = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
364 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
365 |
case "-filter:none": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
366 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
367 |
task.options.filterSamePackage = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
368 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
369 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
370 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
371 |
}, |
38524 | 372 |
|
373 |
// ---- Source filtering options ---- |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
374 |
new Option(true, "-include") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
375 |
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
|
376 |
task.options.includePattern = Pattern.compile(arg); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
377 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
378 |
}, |
38524 | 379 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
380 |
// Another alternative to list modules in --add-modules option |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
381 |
new HiddenOption(true, "--include-system-modules") { |
38524 | 382 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
383 |
task.options.includeSystemModulePattern = Pattern.compile(arg); |
|
384 |
} |
|
385 |
}, |
|
386 |
||
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
387 |
new Option(false, "-P", "-profile") { |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
16290
diff
changeset
|
388 |
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
|
389 |
task.options.showProfile = true; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
390 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
391 |
}, |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
392 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
393 |
new Option(false, "-R", "-recursive") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
394 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
395 |
task.options.depth = 0; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
396 |
// turn off filtering |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
397 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
398 |
task.options.filterSamePackage = false; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
399 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
400 |
}, |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
401 |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
402 |
new Option(false, "-I", "--inverse") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
403 |
void process(JdepsTask task, String opt, String arg) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
404 |
task.options.inverse = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
405 |
// equivalent to the inverse of compile-time view analysis |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
406 |
task.options.compileTimeView = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
407 |
task.options.filterSamePackage = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
408 |
task.options.filterSameArchive = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
409 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
410 |
}, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
411 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
412 |
new Option(false, "--compile-time") { |
36526 | 413 |
void process(JdepsTask task, String opt, String arg) { |
414 |
task.options.compileTimeView = true; |
|
415 |
task.options.filterSamePackage = true; |
|
416 |
task.options.filterSameArchive = true; |
|
417 |
task.options.depth = 0; |
|
418 |
} |
|
419 |
}, |
|
38524 | 420 |
|
36526 | 421 |
new Option(false, "-q", "-quiet") { |
422 |
void process(JdepsTask task, String opt, String arg) { |
|
38524 | 423 |
task.options.nowarning = true; |
424 |
} |
|
36526 | 425 |
}, |
426 |
||
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
427 |
new Option(false, "-version", "--version") { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
428 |
void process(JdepsTask task, String opt, String arg) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
429 |
task.options.version = true; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
430 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
431 |
}, |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
432 |
new HiddenOption(false, "-fullversion") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
433 |
void process(JdepsTask task, String opt, String arg) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
434 |
task.options.fullVersion = true; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
435 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
436 |
}, |
21503
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
437 |
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
|
438 |
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
|
439 |
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
|
440 |
} |
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
441 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
442 |
new HiddenOption(false, "--hide-show-module") { |
38524 | 443 |
void process(JdepsTask task, String opt, String arg) { |
444 |
task.options.showModule = false; |
|
445 |
} |
|
446 |
}, |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
447 |
new HiddenOption(true, "-depth") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
448 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
449 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
450 |
task.options.depth = Integer.parseInt(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
451 |
} catch (NumberFormatException e) { |
16560 | 452 |
throw new BadArgs("err.invalid.arg.for.option", opt); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
453 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
454 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
455 |
}, |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
456 |
}; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
457 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
458 |
private static final String PROGNAME = "jdeps"; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
459 |
private final Options options = new Options(); |
38524 | 460 |
private final List<String> inputArgs = new ArrayList<>(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
461 |
|
41997 | 462 |
private Command command; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
463 |
private PrintWriter log; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
464 |
void setLog(PrintWriter out) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
465 |
log = out; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
466 |
} |
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 |
* Result codes. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
470 |
*/ |
38524 | 471 |
static final int EXIT_OK = 0, // Completed with no errors. |
472 |
EXIT_ERROR = 1, // Completed but reported errors. |
|
473 |
EXIT_CMDERR = 2, // Bad command-line arguments |
|
474 |
EXIT_SYSERR = 3, // System error or resource exhaustion. |
|
475 |
EXIT_ABNORMAL = 4; // terminated abnormally |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
476 |
|
38524 | 477 |
int run(String... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
478 |
if (log == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
479 |
log = new PrintWriter(System.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 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
482 |
handleOptions(args); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
483 |
if (options.help) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
484 |
showHelp(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
485 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
486 |
if (options.version || options.fullVersion) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
487 |
showVersion(options.fullVersion); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
488 |
} |
41997 | 489 |
if (options.help || options.version || options.fullVersion) { |
490 |
return EXIT_OK; |
|
491 |
} |
|
492 |
||
38524 | 493 |
if (!inputArgs.isEmpty() && options.rootModule != null) { |
494 |
reportError("err.invalid.arg.for.option", "-m"); |
|
36526 | 495 |
} |
496 |
||
497 |
if (options.numFilters() > 1) { |
|
498 |
reportError("err.invalid.filters"); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
499 |
return EXIT_CMDERR; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
500 |
} |
36526 | 501 |
|
41997 | 502 |
// default command to analyze dependences |
503 |
if (command == null) { |
|
504 |
command = analyzeDeps(); |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
505 |
} |
41997 | 506 |
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
|
507 |
return EXIT_CMDERR; |
38524 | 508 |
} |
25874 | 509 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
510 |
boolean ok = run(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
511 |
return ok ? EXIT_OK : EXIT_ERROR; |
41997 | 512 |
|
38524 | 513 |
} catch (BadArgs|UncheckedBadArgs e) { |
514 |
reportError(e.getKey(), e.getArgs()); |
|
515 |
if (e.showUsage()) { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
516 |
log.println(getMessage("main.usage.summary", PROGNAME)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
517 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
518 |
return EXIT_CMDERR; |
36526 | 519 |
} catch (ResolutionException e) { |
520 |
reportError("err.exception.message", e.getMessage()); |
|
521 |
return EXIT_CMDERR; |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
522 |
} catch (IOException e) { |
36526 | 523 |
e.printStackTrace(); |
38524 | 524 |
return EXIT_CMDERR; |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
525 |
} catch (MultiReleaseException e) { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
526 |
reportError(e.getKey(), (Object)e.getMsg()); |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
527 |
return EXIT_CMDERR; // could be EXIT_ABNORMAL sometimes |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
528 |
} finally { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
529 |
log.flush(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
530 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
531 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
532 |
|
38524 | 533 |
boolean run() throws IOException { |
41997 | 534 |
try (JdepsConfiguration config = buildConfig(command.allModules())) { |
36526 | 535 |
|
38530 | 536 |
// detect split packages |
41997 | 537 |
config.splitPackages().entrySet() |
538 |
.stream() |
|
38530 | 539 |
.sorted(Map.Entry.comparingByKey()) |
540 |
.forEach(e -> System.out.format("split package: %s %s%n", e.getKey(), |
|
41997 | 541 |
e.getValue().toString())); |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
542 |
|
41860
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
543 |
// check if any module specified in --require is missing |
38530 | 544 |
Stream.concat(options.addmods.stream(), options.requires.stream()) |
545 |
.filter(mn -> !config.isValidToken(mn)) |
|
546 |
.forEach(mn -> config.findModule(mn).orElseThrow(() -> |
|
547 |
new UncheckedBadArgs(new BadArgs("err.module.not.found", mn)))); |
|
38524 | 548 |
|
41997 | 549 |
return command.run(config); |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
550 |
} |
25874 | 551 |
} |
552 |
||
41997 | 553 |
private JdepsConfiguration buildConfig(boolean allModules) throws IOException { |
38524 | 554 |
JdepsConfiguration.Builder builder = |
555 |
new JdepsConfiguration.Builder(options.systemModulePath); |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
556 |
|
38524 | 557 |
builder.upgradeModulePath(options.upgradeModulePath) |
558 |
.appModulePath(options.modulePath) |
|
559 |
.addmods(options.addmods); |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
560 |
|
41997 | 561 |
if (allModules) { |
38524 | 562 |
// check all system modules in the image |
563 |
builder.allModules(); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
564 |
} |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
565 |
|
38524 | 566 |
if (options.classpath != null) |
567 |
builder.addClassPath(options.classpath); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
568 |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
569 |
if (options.multiRelease != null) |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
570 |
builder.multiRelease(options.multiRelease); |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
571 |
|
38524 | 572 |
// build the root set of archives to be analyzed |
573 |
for (String s : inputArgs) { |
|
574 |
Path p = Paths.get(s); |
|
36526 | 575 |
if (Files.exists(p)) { |
38524 | 576 |
builder.addRoot(p); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
577 |
} else { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
578 |
warning("warn.invalid.arg", s); |
36526 | 579 |
} |
25874 | 580 |
} |
581 |
||
38524 | 582 |
return builder.build(); |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
583 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
584 |
|
41997 | 585 |
// ---- factory methods to create a Command |
586 |
||
587 |
private AnalyzeDeps analyzeDeps() throws BadArgs { |
|
588 |
return options.inverse ? new InverseAnalyzeDeps() |
|
589 |
: new AnalyzeDeps(); |
|
590 |
} |
|
591 |
||
592 |
private GenDotFile genDotFile(Path dir) throws BadArgs { |
|
593 |
if (Files.exists(dir) && (!Files.isDirectory(dir) || !Files.isWritable(dir))) { |
|
594 |
throw new BadArgs("err.invalid.path", dir.toString()); |
|
595 |
} |
|
596 |
return new GenDotFile(dir); |
|
597 |
} |
|
598 |
||
599 |
private GenModuleInfo genModuleInfo(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 GenModuleInfo(dir); |
|
604 |
} |
|
605 |
||
606 |
private ListModuleDeps listModuleDeps(boolean reduced) throws BadArgs { |
|
607 |
return reduced ? new ListReducedDeps() |
|
608 |
: new ListModuleDeps(); |
|
609 |
} |
|
610 |
||
611 |
private CheckModuleDeps checkModuleDeps(Set<String> mods) throws BadArgs { |
|
612 |
return new CheckModuleDeps(mods); |
|
613 |
} |
|
614 |
||
615 |
abstract class Command { |
|
616 |
final CommandOption option; |
|
617 |
protected Command(CommandOption option) { |
|
618 |
this.option = option; |
|
619 |
} |
|
620 |
/** |
|
621 |
* Returns true if the command-line options are all valid; |
|
622 |
* otherwise, returns false. |
|
623 |
*/ |
|
624 |
abstract boolean checkOptions(); |
|
625 |
||
626 |
/** |
|
627 |
* Do analysis |
|
628 |
*/ |
|
629 |
abstract boolean run(JdepsConfiguration config) throws IOException; |
|
630 |
||
631 |
/** |
|
632 |
* Includes all modules on system module path and application module path |
|
633 |
*/ |
|
634 |
boolean allModules() { |
|
635 |
return false; |
|
636 |
} |
|
637 |
||
638 |
@Override |
|
639 |
public String toString() { |
|
640 |
return option.toString(); |
|
641 |
} |
|
642 |
} |
|
643 |
||
644 |
||
645 |
/** |
|
646 |
* Analyze dependences |
|
647 |
*/ |
|
648 |
class AnalyzeDeps extends Command { |
|
649 |
JdepsWriter writer; |
|
650 |
AnalyzeDeps() { |
|
651 |
this(CommandOption.ANALYZE_DEPS); |
|
652 |
} |
|
653 |
||
654 |
AnalyzeDeps(CommandOption option) { |
|
655 |
super(option); |
|
656 |
} |
|
657 |
||
658 |
@Override |
|
659 |
boolean checkOptions() { |
|
660 |
if (options.findJDKInternals) { |
|
661 |
// cannot set any filter, -verbose and -summary option |
|
662 |
if (options.showSummary || options.verbose != null) { |
|
663 |
reportError("err.invalid.options", "-summary or -verbose", |
|
664 |
"-jdkinternals"); |
|
665 |
return false; |
|
666 |
} |
|
667 |
if (options.hasFilter()) { |
|
668 |
reportError("err.invalid.options", "--package, --regex, --require", |
|
669 |
"-jdkinternals"); |
|
670 |
return false; |
|
671 |
} |
|
672 |
} |
|
673 |
if (options.showSummary) { |
|
674 |
// -summary cannot use with -verbose option |
|
675 |
if (options.verbose != null) { |
|
676 |
reportError("err.invalid.options", "-v, -verbose", "-s, -summary"); |
|
677 |
return false; |
|
678 |
} |
|
679 |
} |
|
680 |
if (inputArgs.isEmpty() && !options.hasSourcePath()) { |
|
681 |
showHelp(); |
|
682 |
return false; |
|
683 |
} |
|
684 |
return true; |
|
685 |
} |
|
686 |
||
687 |
/* |
|
688 |
* Default is to show package-level dependencies |
|
689 |
*/ |
|
690 |
Type getAnalyzerType() { |
|
691 |
if (options.showSummary) |
|
692 |
return Type.SUMMARY; |
|
693 |
||
694 |
if (options.findJDKInternals) |
|
695 |
return Type.CLASS; |
|
696 |
||
697 |
// default to package-level verbose |
|
698 |
return options.verbose != null ? options.verbose : PACKAGE; |
|
699 |
} |
|
700 |
||
701 |
@Override |
|
702 |
boolean run(JdepsConfiguration config) throws IOException { |
|
703 |
Type type = getAnalyzerType(); |
|
704 |
// default to package-level verbose |
|
705 |
JdepsWriter writer = new SimpleWriter(log, |
|
706 |
type, |
|
707 |
options.showProfile, |
|
708 |
options.showModule); |
|
709 |
||
710 |
return run(config, writer, type); |
|
36526 | 711 |
} |
712 |
||
41997 | 713 |
boolean run(JdepsConfiguration config, JdepsWriter writer, Type type) throws IOException { |
714 |
||
715 |
||
716 |
// analyze the dependencies |
|
717 |
DepsAnalyzer analyzer = new DepsAnalyzer(config, |
|
718 |
dependencyFilter(config), |
|
719 |
writer, |
|
720 |
type, |
|
721 |
options.apiOnly); |
|
722 |
||
723 |
boolean ok = analyzer.run(options.compileTimeView, options.depth); |
|
724 |
||
725 |
// print skipped entries, if any |
|
726 |
if (!options.nowarning) { |
|
727 |
analyzer.archives() |
|
728 |
.forEach(archive -> archive.reader() |
|
729 |
.skippedEntries().stream() |
|
730 |
.forEach(name -> warning("warn.skipped.entry", name))); |
|
731 |
} |
|
732 |
||
733 |
if (options.findJDKInternals && !options.nowarning) { |
|
734 |
Map<String, String> jdkInternals = new TreeMap<>(); |
|
735 |
Set<String> deps = analyzer.dependences(); |
|
736 |
// find the ones with replacement |
|
737 |
deps.forEach(cn -> replacementFor(cn).ifPresent( |
|
738 |
repl -> jdkInternals.put(cn, repl)) |
|
739 |
); |
|
740 |
||
741 |
if (!deps.isEmpty()) { |
|
742 |
log.println(); |
|
743 |
warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url")); |
|
744 |
} |
|
38524 | 745 |
|
41997 | 746 |
if (!jdkInternals.isEmpty()) { |
747 |
log.println(); |
|
748 |
log.format("%-40s %s%n", "JDK Internal API", "Suggested Replacement"); |
|
749 |
log.format("%-40s %s%n", "----------------", "---------------------"); |
|
750 |
jdkInternals.entrySet().stream() |
|
751 |
.forEach(e -> { |
|
752 |
String key = e.getKey(); |
|
753 |
String[] lines = e.getValue().split("\\n"); |
|
754 |
for (String s : lines) { |
|
755 |
log.format("%-40s %s%n", key, s); |
|
756 |
key = ""; |
|
757 |
} |
|
758 |
}); |
|
759 |
} |
|
760 |
} |
|
761 |
return ok; |
|
762 |
} |
|
763 |
} |
|
764 |
||
38524 | 765 |
|
41997 | 766 |
class InverseAnalyzeDeps extends AnalyzeDeps { |
767 |
InverseAnalyzeDeps() { |
|
768 |
} |
|
769 |
||
770 |
@Override |
|
771 |
boolean checkOptions() { |
|
772 |
if (options.depth != 1) { |
|
773 |
reportError("err.invalid.options", "-R", "--inverse"); |
|
774 |
return false; |
|
775 |
} |
|
776 |
||
777 |
if (options.numFilters() == 0) { |
|
778 |
reportError("err.filter.not.specified"); |
|
779 |
return false; |
|
780 |
} |
|
781 |
||
782 |
if (!super.checkOptions()) { |
|
783 |
return false; |
|
784 |
} |
|
785 |
||
786 |
return true; |
|
41443
6398801363f2
8167014: jdeps: Missing message: warn.skipped.entry
mchung
parents:
41442
diff
changeset
|
787 |
} |
36526 | 788 |
|
41997 | 789 |
@Override |
790 |
boolean run(JdepsConfiguration config) throws IOException { |
|
791 |
Type type = getAnalyzerType(); |
|
792 |
||
793 |
InverseDepsAnalyzer analyzer = |
|
794 |
new InverseDepsAnalyzer(config, |
|
795 |
dependencyFilter(config), |
|
796 |
writer, |
|
797 |
type, |
|
798 |
options.apiOnly); |
|
799 |
boolean ok = analyzer.run(); |
|
800 |
||
801 |
log.println(); |
|
802 |
if (!options.requires.isEmpty()) |
|
803 |
log.format("Inverse transitive dependences on %s%n", options.requires); |
|
804 |
else |
|
805 |
log.format("Inverse transitive dependences matching %s%n", |
|
806 |
options.regex != null |
|
807 |
? options.regex.toString() |
|
808 |
: "packages " + options.packageNames); |
|
809 |
||
810 |
analyzer.inverseDependences().stream() |
|
811 |
.sorted(Comparator.comparing(this::sortPath)) |
|
812 |
.forEach(path -> log.println(path.stream() |
|
813 |
.map(Archive::getName) |
|
814 |
.collect(joining(" <- ")))); |
|
815 |
return ok; |
|
816 |
} |
|
817 |
||
818 |
private String sortPath(Deque<Archive> path) { |
|
819 |
return path.peekFirst().getName(); |
|
820 |
} |
|
821 |
} |
|
822 |
||
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
823 |
|
41997 | 824 |
class GenModuleInfo extends Command { |
825 |
final Path dir; |
|
826 |
GenModuleInfo(Path dir) { |
|
827 |
super(CommandOption.GENERATE_MODULE_INFO); |
|
828 |
this.dir = dir; |
|
829 |
} |
|
830 |
||
831 |
@Override |
|
832 |
boolean checkOptions() { |
|
833 |
if (options.classpath != null) { |
|
834 |
reportError("err.invalid.options", "-classpath", |
|
835 |
option); |
|
836 |
return false; |
|
837 |
} |
|
838 |
if (options.hasFilter()) { |
|
839 |
reportError("err.invalid.options", "--package, --regex, --require", |
|
840 |
option); |
|
841 |
return false; |
|
842 |
} |
|
843 |
return true; |
|
844 |
} |
|
845 |
||
846 |
@Override |
|
847 |
boolean run(JdepsConfiguration config) throws IOException { |
|
848 |
// check if any JAR file contains unnamed package |
|
849 |
for (String arg : inputArgs) { |
|
850 |
try (ClassFileReader reader = ClassFileReader.newInstance(Paths.get(arg))) { |
|
851 |
Optional<String> classInUnnamedPackage = |
|
852 |
reader.entries().stream() |
|
853 |
.filter(n -> n.endsWith(".class")) |
|
854 |
.filter(cn -> toPackageName(cn).isEmpty()) |
|
855 |
.findFirst(); |
|
856 |
||
857 |
if (classInUnnamedPackage.isPresent()) { |
|
858 |
if (classInUnnamedPackage.get().equals("module-info.class")) { |
|
859 |
reportError("err.genmoduleinfo.not.jarfile", arg); |
|
860 |
} else { |
|
861 |
reportError("err.genmoduleinfo.unnamed.package", arg); |
|
862 |
} |
|
863 |
return false; |
|
864 |
} |
|
865 |
} |
|
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
866 |
} |
38524 | 867 |
|
41997 | 868 |
ModuleInfoBuilder builder |
869 |
= new ModuleInfoBuilder(config, inputArgs, dir); |
|
870 |
boolean ok = builder.run(); |
|
871 |
||
872 |
if (!ok && !options.nowarning) { |
|
873 |
log.println("ERROR: missing dependencies"); |
|
874 |
builder.visitMissingDeps( |
|
875 |
new Analyzer.Visitor() { |
|
876 |
@Override |
|
877 |
public void visitDependence(String origin, Archive originArchive, |
|
878 |
String target, Archive targetArchive) { |
|
879 |
if (builder.notFound(targetArchive)) |
|
880 |
log.format(" %-50s -> %-50s %s%n", |
|
881 |
origin, target, targetArchive.getName()); |
|
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
882 |
} |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
883 |
}); |
38524 | 884 |
} |
41997 | 885 |
return ok; |
36526 | 886 |
} |
41997 | 887 |
|
888 |
private String toPackageName(String name) { |
|
889 |
int i = name.lastIndexOf('/'); |
|
890 |
return i > 0 ? name.replace('/', '.').substring(0, i) : ""; |
|
891 |
} |
|
36526 | 892 |
} |
893 |
||
41997 | 894 |
class CheckModuleDeps extends Command { |
895 |
final Set<String> modules; |
|
896 |
CheckModuleDeps(Set<String> mods) { |
|
897 |
super(CommandOption.CHECK_MODULES); |
|
898 |
this.modules = mods; |
|
899 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
900 |
|
41997 | 901 |
@Override |
902 |
boolean checkOptions() { |
|
903 |
if (!inputArgs.isEmpty()) { |
|
904 |
reportError("err.invalid.options", inputArgs, "--check"); |
|
905 |
return false; |
|
906 |
} |
|
907 |
return true; |
|
908 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
909 |
|
41997 | 910 |
@Override |
911 |
boolean run(JdepsConfiguration config) throws IOException { |
|
912 |
if (!config.initialArchives().isEmpty()) { |
|
913 |
String list = config.initialArchives().stream() |
|
914 |
.map(Archive::getPathName).collect(joining(" ")); |
|
915 |
throw new UncheckedBadArgs(new BadArgs("err.invalid.options", |
|
916 |
list, "--check")); |
|
917 |
} |
|
918 |
return new ModuleAnalyzer(config, log, modules).run(); |
|
919 |
} |
|
920 |
||
921 |
public boolean allModules() { |
|
922 |
return true; |
|
923 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
924 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
925 |
|
41997 | 926 |
class ListReducedDeps extends ListModuleDeps { |
927 |
ListReducedDeps() { |
|
928 |
super(CommandOption.LIST_REDUCED_DEPS, true); |
|
929 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
930 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
931 |
|
41997 | 932 |
class ListModuleDeps extends Command { |
933 |
final boolean reduced; |
|
934 |
ListModuleDeps() { |
|
935 |
this(CommandOption.LIST_DEPS, false); |
|
936 |
} |
|
937 |
ListModuleDeps(CommandOption option, boolean reduced) { |
|
938 |
super(option); |
|
939 |
this.reduced = reduced; |
|
940 |
} |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
941 |
|
41997 | 942 |
@Override |
943 |
boolean checkOptions() { |
|
944 |
if (options.showSummary || options.verbose != null) { |
|
945 |
reportError("err.invalid.options", "-summary or -verbose", |
|
946 |
option); |
|
947 |
return false; |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
948 |
} |
41997 | 949 |
if (options.findJDKInternals) { |
950 |
reportError("err.invalid.options", "-jdkinternals", |
|
951 |
option); |
|
952 |
return false; |
|
953 |
} |
|
954 |
if (inputArgs.isEmpty() && !options.hasSourcePath()) { |
|
955 |
showHelp(); |
|
956 |
return false; |
|
957 |
} |
|
958 |
return true; |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
959 |
} |
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
960 |
|
41997 | 961 |
@Override |
962 |
boolean run(JdepsConfiguration config) throws IOException { |
|
963 |
return new ModuleExportsAnalyzer(config, |
|
964 |
dependencyFilter(config), |
|
965 |
reduced, |
|
966 |
log).run(); |
|
967 |
} |
|
38524 | 968 |
|
41998
feae61dc2280
8169606: jdeps --list-reduced-deps should not show java.base as all modules require it
mchung
parents:
41997
diff
changeset
|
969 |
@Override |
feae61dc2280
8169606: jdeps --list-reduced-deps should not show java.base as all modules require it
mchung
parents:
41997
diff
changeset
|
970 |
boolean allModules() { |
41997 | 971 |
return true; |
38524 | 972 |
} |
973 |
} |
|
974 |
||
41997 | 975 |
|
976 |
class GenDotFile extends AnalyzeDeps { |
|
977 |
final Path dotOutputDir; |
|
978 |
GenDotFile(Path dotOutputDir) { |
|
979 |
super(CommandOption.GENERATE_DOT_FILE); |
|
980 |
||
981 |
this.dotOutputDir = dotOutputDir; |
|
982 |
} |
|
983 |
||
984 |
@Override |
|
985 |
boolean run(JdepsConfiguration config) throws IOException { |
|
986 |
if ((options.showSummary || options.verbose == MODULE) && |
|
987 |
!options.addmods.isEmpty() && inputArgs.isEmpty()) { |
|
988 |
// print module descriptor |
|
989 |
return new ModuleAnalyzer(config, log).genDotFiles(dotOutputDir); |
|
990 |
} |
|
991 |
||
992 |
Type type = getAnalyzerType(); |
|
993 |
JdepsWriter writer = new DotFileWriter(dotOutputDir, |
|
994 |
type, |
|
995 |
options.showProfile, |
|
996 |
options.showModule, |
|
997 |
options.showLabel); |
|
998 |
return run(config, writer, type); |
|
999 |
} |
|
41442
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1000 |
} |
14db641d4a9f
8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents:
41251
diff
changeset
|
1001 |
|
38524 | 1002 |
/** |
1003 |
* Returns a filter used during dependency analysis |
|
1004 |
*/ |
|
1005 |
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
|
1006 |
// Filter specified by -filter, -package, -regex, and --require options |
36526 | 1007 |
JdepsFilter.Builder builder = new JdepsFilter.Builder(); |
1008 |
||
1009 |
// source filters |
|
1010 |
builder.includePattern(options.includePattern); |
|
38524 | 1011 |
builder.includeSystemModules(options.includeSystemModulePattern); |
36526 | 1012 |
|
1013 |
builder.filter(options.filterSamePackage, options.filterSameArchive); |
|
1014 |
builder.findJDKInternals(options.findJDKInternals); |
|
1015 |
||
41860
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
1016 |
// --require |
36526 | 1017 |
if (!options.requires.isEmpty()) { |
38524 | 1018 |
options.requires.stream() |
1019 |
.forEach(mn -> { |
|
1020 |
Module m = config.findModule(mn).get(); |
|
1021 |
builder.requires(mn, m.packages()); |
|
1022 |
}); |
|
36526 | 1023 |
} |
1024 |
// -regex |
|
1025 |
if (options.regex != null) |
|
1026 |
builder.regex(options.regex); |
|
1027 |
// -package |
|
1028 |
if (!options.packageNames.isEmpty()) |
|
1029 |
builder.packages(options.packageNames); |
|
1030 |
// -filter |
|
1031 |
if (options.filterRegex != null) |
|
1032 |
builder.filter(options.filterRegex); |
|
1033 |
||
38524 | 1034 |
// check if system module is set |
1035 |
config.rootModules().stream() |
|
41860
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
1036 |
.map(Module::name) |
906670ff49c7
8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents:
41522
diff
changeset
|
1037 |
.forEach(builder::includeIfSystemModule); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1038 |
|
38524 | 1039 |
return builder.build(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1040 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1041 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1042 |
public void handleOptions(String[] args) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1043 |
// process options |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1044 |
for (int i=0; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1045 |
if (args[i].charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1046 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1047 |
Option option = getOption(name); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1048 |
String param = null; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1049 |
if (option.hasArg) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1050 |
if (name.startsWith("-") && name.indexOf('=') > 0) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1051 |
param = name.substring(name.indexOf('=') + 1, name.length()); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1052 |
} else if (i + 1 < args.length) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1053 |
param = args[++i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1054 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1055 |
if (param == null || param.isEmpty() || param.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1056 |
throw new BadArgs("err.missing.arg", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1057 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1058 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1059 |
option.process(this, name, param); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1060 |
if (option.ignoreRest()) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1061 |
i = args.length; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1062 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1063 |
} else { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1064 |
// process rest of the input arguments |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1065 |
for (; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1066 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1067 |
if (name.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1068 |
throw new BadArgs("err.option.after.class", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1069 |
} |
38524 | 1070 |
inputArgs.add(name); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1071 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1072 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1073 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1074 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1075 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1076 |
private Option getOption(String name) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1077 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1078 |
if (o.matches(name)) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1079 |
return o; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1080 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1081 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1082 |
throw new BadArgs("err.unknown.option", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1083 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1084 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1085 |
private void reportError(String key, Object... args) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1086 |
log.println(getMessage("error.prefix") + " " + getMessage(key, args)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1087 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1088 |
|
38524 | 1089 |
void warning(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1090 |
log.println(getMessage("warn.prefix") + " " + getMessage(key, args)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1091 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1092 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1093 |
private void showHelp() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1094 |
log.println(getMessage("main.usage", PROGNAME)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1095 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1096 |
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
|
1097 |
name = name.charAt(0) == '-' ? name.substring(1) : name; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
1098 |
if (o.isHidden() || name.equals("h") || name.startsWith("filter:")) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1099 |
continue; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1100 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1101 |
log.println(getMessage("main.opt." + name)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1102 |
} |
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 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1105 |
private void showVersion(boolean full) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1106 |
log.println(version(full ? "full" : "release")); |
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 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1109 |
private String version(String key) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1110 |
// key=version: mm.nn.oo[-milestone] |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1111 |
// key=full: mm.mm.oo[-milestone]-build |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1112 |
if (ResourceBundleHelper.versionRB == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1113 |
return System.getProperty("java.version"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1114 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1115 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1116 |
return ResourceBundleHelper.versionRB.getString(key); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1117 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1118 |
return getMessage("version.unknown", System.getProperty("java.version")); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1119 |
} |
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 |
|
16290
b0b4f52de7ea
8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
15030
diff
changeset
|
1122 |
static String getMessage(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1123 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1124 |
return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1125 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1126 |
throw new InternalError("Missing message: " + key); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1127 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1128 |
} |
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 |
private static class Options { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1131 |
boolean help; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1132 |
boolean version; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1133 |
boolean fullVersion; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1134 |
boolean showProfile; |
38524 | 1135 |
boolean showModule = true; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1136 |
boolean showSummary; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1137 |
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
|
1138 |
boolean showLabel; |
22007
907f7054db16
8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents:
21503
diff
changeset
|
1139 |
boolean findJDKInternals; |
36526 | 1140 |
boolean nowarning = false; |
41997 | 1141 |
Analyzer.Type verbose; |
1142 |
// 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
|
1143 |
boolean filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
1144 |
boolean filterSameArchive = false; |
36526 | 1145 |
Pattern filterRegex; |
38524 | 1146 |
String classpath; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1147 |
int depth = 1; |
36526 | 1148 |
Set<String> requires = new HashSet<>(); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
1149 |
Set<String> packageNames = new HashSet<>(); |
36526 | 1150 |
Pattern regex; // apply to the dependences |
38524 | 1151 |
Pattern includePattern; |
1152 |
Pattern includeSystemModulePattern; |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
1153 |
boolean inverse = false; |
36526 | 1154 |
boolean compileTimeView = false; |
38524 | 1155 |
String systemModulePath = System.getProperty("java.home"); |
36526 | 1156 |
String upgradeModulePath; |
1157 |
String modulePath; |
|
1158 |
String rootModule; |
|
38524 | 1159 |
Set<String> addmods = new HashSet<>(); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
1160 |
Runtime.Version multiRelease; |
41997 | 1161 |
|
1162 |
boolean hasSourcePath() { |
|
1163 |
return !addmods.isEmpty() || includePattern != null || |
|
1164 |
includeSystemModulePattern != null; |
|
1165 |
} |
|
36526 | 1166 |
|
1167 |
boolean hasFilter() { |
|
1168 |
return numFilters() > 0; |
|
1169 |
} |
|
1170 |
||
1171 |
int numFilters() { |
|
1172 |
int count = 0; |
|
1173 |
if (requires.size() > 0) count++; |
|
1174 |
if (regex != null) count++; |
|
1175 |
if (packageNames.size() > 0) count++; |
|
1176 |
return count; |
|
1177 |
} |
|
38524 | 1178 |
} |
36526 | 1179 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1180 |
private static class ResourceBundleHelper { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1181 |
static final ResourceBundle versionRB; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1182 |
static final ResourceBundle bundle; |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1183 |
static final ResourceBundle jdkinternals; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1184 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1185 |
static { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1186 |
Locale locale = Locale.getDefault(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1187 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1188 |
bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1189 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1190 |
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
|
1191 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1192 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1193 |
versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1194 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1195 |
throw new InternalError("version.resource.missing"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1196 |
} |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1197 |
try { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1198 |
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
|
1199 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1200 |
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
|
1201 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1202 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1203 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1204 |
|
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1205 |
/** |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1206 |
* 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
|
1207 |
* 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
|
1208 |
*/ |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
1209 |
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
|
1210 |
String name = cn; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1211 |
String value = null; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1212 |
while (value == null && name != null) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1213 |
try { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1214 |
value = ResourceBundleHelper.jdkinternals.getString(name); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1215 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1216 |
// go up one subpackage level |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1217 |
int i = name.lastIndexOf('.'); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1218 |
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
|
1219 |
} |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
1220 |
} |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
1221 |
return Optional.ofNullable(value); |
36526 | 1222 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
1223 |
} |