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