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