author | mchung |
Thu, 29 Sep 2016 21:31:09 -0700 | |
changeset 41251 | 6112540cd0c1 |
parent 41164 | 69167c89e68f |
child 41442 | 14db641d4a9f |
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 |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
28 |
import static com.sun.tools.jdeps.Analyzer.Type.*; |
36526 | 29 |
import static com.sun.tools.jdeps.JdepsWriter.*; |
30 |
||
31 |
import java.io.IOException; |
|
32 |
import java.io.PrintWriter; |
|
33 |
import java.lang.module.ResolutionException; |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
34 |
import java.nio.file.Files; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
35 |
import java.nio.file.Path; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
36 |
import java.nio.file.Paths; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
37 |
import java.text.MessageFormat; |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
38 |
import java.util.*; |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
39 |
import java.util.jar.JarFile; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
40 |
import java.util.regex.Pattern; |
36526 | 41 |
import java.util.stream.Collectors; |
42 |
import java.util.stream.Stream; |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
43 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
44 |
/** |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
45 |
* Implementation for the jdeps tool for static class dependency analysis. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
46 |
*/ |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
47 |
class JdepsTask { |
38524 | 48 |
static interface BadArguments { |
49 |
String getKey(); |
|
50 |
Object[] getArgs(); |
|
51 |
boolean showUsage(); |
|
52 |
} |
|
53 |
static class BadArgs extends Exception implements BadArguments { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
54 |
static final long serialVersionUID = 8765093759964640721L; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
55 |
BadArgs(String key, Object... args) { |
16290
b0b4f52de7ea
8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
15030
diff
changeset
|
56 |
super(JdepsTask.getMessage(key, args)); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
57 |
this.key = key; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
58 |
this.args = args; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
59 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
60 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
61 |
BadArgs showUsage(boolean b) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
62 |
showUsage = b; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
63 |
return this; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
64 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
65 |
final String key; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
66 |
final Object[] args; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
67 |
boolean showUsage; |
38524 | 68 |
|
69 |
@Override |
|
70 |
public String getKey() { |
|
71 |
return key; |
|
72 |
} |
|
73 |
||
74 |
@Override |
|
75 |
public Object[] getArgs() { |
|
76 |
return args; |
|
77 |
} |
|
78 |
||
79 |
@Override |
|
80 |
public boolean showUsage() { |
|
81 |
return showUsage; |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
static class UncheckedBadArgs extends RuntimeException implements BadArguments { |
|
86 |
static final long serialVersionUID = -1L; |
|
87 |
final BadArgs cause; |
|
88 |
UncheckedBadArgs(BadArgs cause) { |
|
89 |
super(cause); |
|
90 |
this.cause = cause; |
|
91 |
} |
|
92 |
@Override |
|
93 |
public String getKey() { |
|
94 |
return cause.key; |
|
95 |
} |
|
96 |
||
97 |
@Override |
|
98 |
public Object[] getArgs() { |
|
99 |
return cause.args; |
|
100 |
} |
|
101 |
||
102 |
@Override |
|
103 |
public boolean showUsage() { |
|
104 |
return cause.showUsage; |
|
105 |
} |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
106 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
107 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
108 |
static abstract class Option { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
109 |
Option(boolean hasArg, String... aliases) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
110 |
this.hasArg = hasArg; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
111 |
this.aliases = aliases; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
112 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
113 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
114 |
boolean isHidden() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
115 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
116 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
117 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
118 |
boolean matches(String opt) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
119 |
for (String a : aliases) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
120 |
if (a.equals(opt)) |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
121 |
return true; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
122 |
if (hasArg && opt.startsWith(a + "=")) |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
123 |
return true; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
124 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
125 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
126 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
127 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
128 |
boolean ignoreRest() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
129 |
return false; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
130 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
131 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
132 |
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
|
133 |
final boolean hasArg; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
134 |
final String[] aliases; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
135 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
136 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
137 |
static abstract class HiddenOption extends Option { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
138 |
HiddenOption(boolean hasArg, String... aliases) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
139 |
super(hasArg, aliases); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
140 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
141 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
142 |
boolean isHidden() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
143 |
return true; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
144 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
145 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
146 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
147 |
static Option[] recognizedOptions = { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
148 |
new Option(false, "-h", "-?", "-help", "--help") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
149 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
150 |
task.options.help = true; |
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 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
153 |
new Option(true, "-dotoutput", "--dot-output") { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
154 |
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
|
155 |
Path p = Paths.get(arg); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
156 |
if (Files.exists(p) && (!Files.isDirectory(p) || !Files.isWritable(p))) { |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
157 |
throw new BadArgs("err.invalid.path", arg); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
158 |
} |
38524 | 159 |
task.options.dotOutputDir = Paths.get(arg);; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
160 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
161 |
}, |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
162 |
new Option(false, "-s", "-summary") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
163 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
164 |
task.options.showSummary = true; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
165 |
task.options.verbose = SUMMARY; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
166 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
167 |
}, |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
168 |
new Option(false, "-v", "-verbose", |
38524 | 169 |
"-verbose:module", |
170 |
"-verbose:package", |
|
171 |
"-verbose:class") { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
172 |
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
|
173 |
switch (opt) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
174 |
case "-v": |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
175 |
case "-verbose": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
176 |
task.options.verbose = VERBOSE; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
177 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
178 |
task.options.filterSamePackage = false; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
179 |
break; |
38524 | 180 |
case "-verbose:module": |
181 |
task.options.verbose = MODULE; |
|
182 |
break; |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
183 |
case "-verbose:package": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
184 |
task.options.verbose = PACKAGE; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
185 |
break; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
186 |
case "-verbose:class": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
187 |
task.options.verbose = CLASS; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
188 |
break; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
189 |
default: |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
190 |
throw new BadArgs("err.invalid.arg.for.option", opt); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
191 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
192 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
193 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
194 |
new Option(false, "-apionly", "--api-only") { |
38524 | 195 |
void process(JdepsTask task, String opt, String arg) { |
196 |
task.options.apiOnly = true; |
|
197 |
} |
|
198 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
199 |
new Option(true, "--check") { |
38524 | 200 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
201 |
Set<String> mods = Set.of(arg.split(",")); |
|
202 |
task.options.checkModuleDeps = mods; |
|
203 |
task.options.addmods.addAll(mods); |
|
204 |
} |
|
205 |
}, |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
206 |
new Option(true, "--generate-module-info") { |
38524 | 207 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
208 |
Path p = Paths.get(arg); |
|
209 |
if (Files.exists(p) && (!Files.isDirectory(p) || !Files.isWritable(p))) { |
|
210 |
throw new BadArgs("err.invalid.path", arg); |
|
211 |
} |
|
212 |
task.options.genModuleInfo = Paths.get(arg); |
|
213 |
} |
|
214 |
}, |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
215 |
new Option(false, "-jdkinternals", "--jdk-internals") { |
38524 | 216 |
void process(JdepsTask task, String opt, String arg) { |
217 |
task.options.findJDKInternals = true; |
|
218 |
task.options.verbose = CLASS; |
|
219 |
if (task.options.includePattern == null) { |
|
220 |
task.options.includePattern = Pattern.compile(".*"); |
|
221 |
} |
|
222 |
} |
|
223 |
}, |
|
224 |
||
225 |
// ---- paths option ---- |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
226 |
new Option(true, "-cp", "-classpath", "--class-path") { |
38524 | 227 |
void process(JdepsTask task, String opt, String arg) { |
228 |
task.options.classpath = arg; |
|
229 |
} |
|
230 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
231 |
new Option(true, "--module-path") { |
38524 | 232 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
233 |
task.options.modulePath = arg; |
|
234 |
} |
|
235 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
236 |
new Option(true, "--upgrade-module-path") { |
38524 | 237 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
238 |
task.options.upgradeModulePath = arg; |
|
239 |
} |
|
240 |
}, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
241 |
new Option(true, "--system") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
242 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
243 |
if (arg.equals("none")) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
244 |
task.options.systemModulePath = null; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
245 |
} else { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
246 |
Path path = Paths.get(arg); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
247 |
if (Files.isRegularFile(path.resolve("lib").resolve("modules"))) |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
248 |
task.options.systemModulePath = arg; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
249 |
else |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
250 |
throw new BadArgs("err.invalid.path", arg); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
251 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
252 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
253 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
254 |
new Option(true, "--add-modules") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
255 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
256 |
Set<String> mods = Set.of(arg.split(",")); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
257 |
task.options.addmods.addAll(mods); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
258 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
259 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
260 |
new Option(true, "-m", "--module") { |
38524 | 261 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
262 |
task.options.rootModule = arg; |
|
263 |
task.options.addmods.add(arg); |
|
264 |
} |
|
265 |
}, |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
266 |
new Option(true, "--multi-release") { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
267 |
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
|
268 |
if (arg.equalsIgnoreCase("base")) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
269 |
task.options.multiRelease = JarFile.baseVersion(); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
270 |
} else { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
271 |
try { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
272 |
int v = Integer.parseInt(arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
273 |
if (v < 9) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
274 |
throw new BadArgs("err.invalid.arg.for.option", arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
275 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
276 |
} catch (NumberFormatException x) { |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
277 |
throw new BadArgs("err.invalid.arg.for.option", arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
278 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
279 |
task.options.multiRelease = Runtime.Version.parse(arg); |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
280 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
281 |
} |
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
282 |
}, |
38524 | 283 |
|
284 |
// ---- Target filtering options ---- |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
285 |
new Option(true, "-p", "-package", "--package") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
286 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
287 |
task.options.packageNames.add(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
288 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
289 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
290 |
new Option(true, "-e", "-regex", "--regex") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
291 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 292 |
task.options.regex = Pattern.compile(arg); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
293 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
294 |
}, |
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
295 |
new Option(true, "--require") { |
36526 | 296 |
void process(JdepsTask task, String opt, String arg) { |
297 |
task.options.requires.add(arg); |
|
298 |
} |
|
299 |
}, |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
300 |
new Option(true, "-f", "-filter") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
301 |
void process(JdepsTask task, String opt, String arg) { |
36526 | 302 |
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
|
303 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
304 |
}, |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
305 |
new Option(false, "-filter:package", |
36526 | 306 |
"-filter:archive", "-filter:module", |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
307 |
"-filter:none") { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
308 |
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
|
309 |
switch (opt) { |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
310 |
case "-filter:package": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
311 |
task.options.filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
312 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
313 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
314 |
case "-filter:archive": |
36526 | 315 |
case "-filter:module": |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
316 |
task.options.filterSameArchive = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
317 |
task.options.filterSamePackage = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
318 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
319 |
case "-filter:none": |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
320 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
321 |
task.options.filterSamePackage = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
322 |
break; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
323 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
324 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
325 |
}, |
38524 | 326 |
|
327 |
// ---- Source filtering options ---- |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
328 |
new Option(true, "-include") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
329 |
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
|
330 |
task.options.includePattern = Pattern.compile(arg); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
331 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
332 |
}, |
38524 | 333 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
334 |
// 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
|
335 |
new HiddenOption(true, "--include-system-modules") { |
38524 | 336 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
337 |
task.options.includeSystemModulePattern = Pattern.compile(arg); |
|
338 |
} |
|
339 |
}, |
|
340 |
||
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
341 |
new Option(false, "-P", "-profile") { |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
16290
diff
changeset
|
342 |
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
|
343 |
task.options.showProfile = true; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
344 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
345 |
}, |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
346 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
347 |
new Option(false, "-R", "-recursive") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
348 |
void process(JdepsTask task, String opt, String arg) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
349 |
task.options.depth = 0; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
350 |
// turn off filtering |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
351 |
task.options.filterSameArchive = false; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
352 |
task.options.filterSamePackage = false; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
353 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
354 |
}, |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
355 |
|
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
356 |
new Option(false, "-I", "--inverse") { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
357 |
void process(JdepsTask task, String opt, String arg) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
358 |
task.options.inverse = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
359 |
// equivalent to the inverse of compile-time view analysis |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
360 |
task.options.compileTimeView = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
361 |
task.options.filterSamePackage = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
362 |
task.options.filterSameArchive = true; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
363 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
364 |
}, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
365 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
366 |
new Option(false, "--compile-time") { |
36526 | 367 |
void process(JdepsTask task, String opt, String arg) { |
368 |
task.options.compileTimeView = true; |
|
369 |
task.options.filterSamePackage = true; |
|
370 |
task.options.filterSameArchive = true; |
|
371 |
task.options.depth = 0; |
|
372 |
} |
|
373 |
}, |
|
38524 | 374 |
|
36526 | 375 |
new Option(false, "-q", "-quiet") { |
376 |
void process(JdepsTask task, String opt, String arg) { |
|
38524 | 377 |
task.options.nowarning = true; |
378 |
} |
|
36526 | 379 |
}, |
380 |
||
41251
6112540cd0c1
8166238: Update jdeps for GNU-style long form options
mchung
parents:
41164
diff
changeset
|
381 |
new Option(false, "-version", "--version") { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
382 |
void process(JdepsTask task, String opt, String arg) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
383 |
task.options.version = true; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
384 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
385 |
}, |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
386 |
new HiddenOption(false, "-fullversion") { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
387 |
void process(JdepsTask task, String opt, String arg) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
388 |
task.options.fullVersion = true; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
389 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
390 |
}, |
21503
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
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
|
394 |
} |
45fc62482cae
8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents:
21046
diff
changeset
|
395 |
}, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
396 |
new HiddenOption(false, "--hide-show-module") { |
38524 | 397 |
void process(JdepsTask task, String opt, String arg) { |
398 |
task.options.showModule = false; |
|
399 |
} |
|
400 |
}, |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
401 |
new HiddenOption(true, "-depth") { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
402 |
void process(JdepsTask task, String opt, String arg) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
403 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
404 |
task.options.depth = Integer.parseInt(arg); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
405 |
} catch (NumberFormatException e) { |
16560 | 406 |
throw new BadArgs("err.invalid.arg.for.option", opt); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
407 |
} |
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 |
}, |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
410 |
}; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
411 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
412 |
private static final String PROGNAME = "jdeps"; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
413 |
private final Options options = new Options(); |
38524 | 414 |
private final List<String> inputArgs = new ArrayList<>(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
415 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
416 |
private PrintWriter log; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
417 |
void setLog(PrintWriter out) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
418 |
log = out; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
419 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
420 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
421 |
/** |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
422 |
* Result codes. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
423 |
*/ |
38524 | 424 |
static final int EXIT_OK = 0, // Completed with no errors. |
425 |
EXIT_ERROR = 1, // Completed but reported errors. |
|
426 |
EXIT_CMDERR = 2, // Bad command-line arguments |
|
427 |
EXIT_SYSERR = 3, // System error or resource exhaustion. |
|
428 |
EXIT_ABNORMAL = 4; // terminated abnormally |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
429 |
|
38524 | 430 |
int run(String... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
431 |
if (log == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
432 |
log = new PrintWriter(System.out); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
433 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
434 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
435 |
handleOptions(args); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
436 |
if (options.help) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
437 |
showHelp(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
438 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
439 |
if (options.version || options.fullVersion) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
440 |
showVersion(options.fullVersion); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
441 |
} |
38524 | 442 |
if (!inputArgs.isEmpty() && options.rootModule != null) { |
443 |
reportError("err.invalid.arg.for.option", "-m"); |
|
36526 | 444 |
} |
38524 | 445 |
if (inputArgs.isEmpty() && options.addmods.isEmpty() && options.includePattern == null |
446 |
&& options.includeSystemModulePattern == null && options.checkModuleDeps == null) { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
447 |
if (options.help || options.version || options.fullVersion) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
448 |
return EXIT_OK; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
449 |
} else { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
450 |
showHelp(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
451 |
return EXIT_CMDERR; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
452 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
453 |
} |
36526 | 454 |
if (options.genModuleInfo != null) { |
38524 | 455 |
if (options.dotOutputDir != null || options.classpath != null || options.hasFilter()) { |
36526 | 456 |
showHelp(); |
457 |
return EXIT_CMDERR; |
|
458 |
} |
|
459 |
} |
|
460 |
||
461 |
if (options.numFilters() > 1) { |
|
462 |
reportError("err.invalid.filters"); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
463 |
return EXIT_CMDERR; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
464 |
} |
36526 | 465 |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
466 |
if (options.inverse && options.depth != 1) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
467 |
reportError("err.invalid.inverse.option", "-R"); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
468 |
return EXIT_CMDERR; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
469 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
470 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
471 |
if (options.inverse && options.numFilters() == 0) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
472 |
reportError("err.invalid.filters"); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
473 |
return EXIT_CMDERR; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
474 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
475 |
|
36526 | 476 |
if ((options.findJDKInternals) && (options.hasFilter() || options.showSummary)) { |
22007
907f7054db16
8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents:
21503
diff
changeset
|
477 |
showHelp(); |
907f7054db16
8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents:
21503
diff
changeset
|
478 |
return EXIT_CMDERR; |
907f7054db16
8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents:
21503
diff
changeset
|
479 |
} |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
480 |
if (options.showSummary && options.verbose != SUMMARY) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
481 |
showHelp(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
482 |
return EXIT_CMDERR; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
483 |
} |
38524 | 484 |
if (options.checkModuleDeps != null && !inputArgs.isEmpty()) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
485 |
reportError("err.invalid.module.option", inputArgs, "--check"); |
38524 | 486 |
} |
25874 | 487 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
488 |
boolean ok = run(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
489 |
return ok ? EXIT_OK : EXIT_ERROR; |
38524 | 490 |
} catch (BadArgs|UncheckedBadArgs e) { |
491 |
reportError(e.getKey(), e.getArgs()); |
|
492 |
if (e.showUsage()) { |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
493 |
log.println(getMessage("main.usage.summary", PROGNAME)); |
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 |
return EXIT_CMDERR; |
36526 | 496 |
} catch (ResolutionException e) { |
497 |
reportError("err.exception.message", e.getMessage()); |
|
498 |
return EXIT_CMDERR; |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
499 |
} catch (IOException e) { |
36526 | 500 |
e.printStackTrace(); |
38524 | 501 |
return EXIT_CMDERR; |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
502 |
} catch (MultiReleaseException e) { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
503 |
reportError(e.getKey(), (Object)e.getMsg()); |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
504 |
return EXIT_CMDERR; // could be EXIT_ABNORMAL sometimes |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
505 |
} finally { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
506 |
log.flush(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
507 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
508 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
509 |
|
38524 | 510 |
boolean run() throws IOException { |
38530 | 511 |
try (JdepsConfiguration config = buildConfig()) { |
36526 | 512 |
|
38530 | 513 |
// detect split packages |
514 |
config.splitPackages().entrySet().stream() |
|
515 |
.sorted(Map.Entry.comparingByKey()) |
|
516 |
.forEach(e -> System.out.format("split package: %s %s%n", e.getKey(), |
|
517 |
e.getValue().toString())); |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
518 |
|
38530 | 519 |
// check if any module specified in -requires is missing |
520 |
Stream.concat(options.addmods.stream(), options.requires.stream()) |
|
521 |
.filter(mn -> !config.isValidToken(mn)) |
|
522 |
.forEach(mn -> config.findModule(mn).orElseThrow(() -> |
|
523 |
new UncheckedBadArgs(new BadArgs("err.module.not.found", mn)))); |
|
38524 | 524 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
525 |
// --gen-module-info |
38530 | 526 |
if (options.genModuleInfo != null) { |
527 |
return genModuleInfo(config); |
|
528 |
} |
|
36526 | 529 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39101
diff
changeset
|
530 |
// --check |
38530 | 531 |
if (options.checkModuleDeps != null) { |
532 |
return new ModuleAnalyzer(config, log, options.checkModuleDeps).run(); |
|
533 |
} |
|
38524 | 534 |
|
38530 | 535 |
if (options.dotOutputDir != null && |
38524 | 536 |
(options.verbose == SUMMARY || options.verbose == MODULE) && |
537 |
!options.addmods.isEmpty() && inputArgs.isEmpty()) { |
|
38530 | 538 |
return new ModuleAnalyzer(config, log).genDotFiles(options.dotOutputDir); |
539 |
} |
|
38524 | 540 |
|
38530 | 541 |
if (options.inverse) { |
542 |
return analyzeInverseDeps(config); |
|
543 |
} else { |
|
544 |
return analyzeDeps(config); |
|
545 |
} |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
546 |
} |
25874 | 547 |
} |
548 |
||
38524 | 549 |
private JdepsConfiguration buildConfig() throws IOException { |
550 |
JdepsConfiguration.Builder builder = |
|
551 |
new JdepsConfiguration.Builder(options.systemModulePath); |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
552 |
|
38524 | 553 |
builder.upgradeModulePath(options.upgradeModulePath) |
554 |
.appModulePath(options.modulePath) |
|
555 |
.addmods(options.addmods); |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
556 |
|
38524 | 557 |
if (options.checkModuleDeps != null) { |
558 |
// check all system modules in the image |
|
559 |
builder.allModules(); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
560 |
} |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
561 |
|
38524 | 562 |
if (options.classpath != null) |
563 |
builder.addClassPath(options.classpath); |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
564 |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
565 |
if (options.multiRelease != null) |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
566 |
builder.multiRelease(options.multiRelease); |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
567 |
|
38524 | 568 |
// build the root set of archives to be analyzed |
569 |
for (String s : inputArgs) { |
|
570 |
Path p = Paths.get(s); |
|
36526 | 571 |
if (Files.exists(p)) { |
38524 | 572 |
builder.addRoot(p); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
573 |
} else { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
574 |
warning("warn.invalid.arg", s); |
36526 | 575 |
} |
25874 | 576 |
} |
577 |
||
38524 | 578 |
return builder.build(); |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
579 |
} |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
580 |
|
38524 | 581 |
private boolean analyzeDeps(JdepsConfiguration config) throws IOException { |
36526 | 582 |
// output result |
583 |
final JdepsWriter writer; |
|
584 |
if (options.dotOutputDir != null) { |
|
38524 | 585 |
writer = new DotFileWriter(options.dotOutputDir, |
586 |
options.verbose, |
|
36526 | 587 |
options.showProfile, |
588 |
options.showModule, |
|
589 |
options.showLabel); |
|
590 |
} else { |
|
38524 | 591 |
writer = new SimpleWriter(log, |
592 |
options.verbose, |
|
36526 | 593 |
options.showProfile, |
594 |
options.showModule); |
|
595 |
} |
|
596 |
||
38524 | 597 |
// analyze the dependencies |
598 |
DepsAnalyzer analyzer = new DepsAnalyzer(config, |
|
599 |
dependencyFilter(config), |
|
600 |
writer, |
|
601 |
options.verbose, |
|
602 |
options.apiOnly); |
|
603 |
||
604 |
boolean ok = analyzer.run(options.compileTimeView, options.depth); |
|
605 |
||
606 |
// print skipped entries, if any |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
607 |
analyzer.archives() |
38524 | 608 |
.forEach(archive -> archive.reader() |
609 |
.skippedEntries().stream() |
|
610 |
.forEach(name -> warning("warn.skipped.entry", |
|
611 |
name, archive.getPathName()))); |
|
36526 | 612 |
|
38524 | 613 |
if (options.findJDKInternals && !options.nowarning) { |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
614 |
Map<String, String> jdkInternals = new TreeMap<>(); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
615 |
Set<String> deps = analyzer.dependences(); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
616 |
// find the ones with replacement |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
617 |
deps.forEach(cn -> replacementFor(cn).ifPresent( |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
618 |
repl -> jdkInternals.put(cn, repl)) |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
619 |
); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
620 |
|
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
621 |
if (!deps.isEmpty()) { |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
622 |
log.println(); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
623 |
warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url")); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
624 |
} |
38524 | 625 |
|
626 |
if (!jdkInternals.isEmpty()) { |
|
627 |
log.println(); |
|
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
628 |
log.format("%-40s %s%n", "JDK Internal API", "Suggested Replacement"); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
629 |
log.format("%-40s %s%n", "----------------", "---------------------"); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
630 |
jdkInternals.entrySet().stream() |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
631 |
.forEach(e -> { |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
632 |
String key = e.getKey(); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
633 |
String[] lines = e.getValue().split("\\n"); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
634 |
for (String s : lines) { |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
635 |
log.format("%-40s %s%n", key, s); |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
636 |
key = ""; |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
637 |
} |
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
638 |
}); |
38524 | 639 |
} |
36526 | 640 |
} |
38524 | 641 |
return ok; |
36526 | 642 |
} |
643 |
||
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
644 |
private boolean analyzeInverseDeps(JdepsConfiguration config) throws IOException { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
645 |
JdepsWriter writer = new SimpleWriter(log, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
646 |
options.verbose, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
647 |
options.showProfile, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
648 |
options.showModule); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
649 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
650 |
InverseDepsAnalyzer analyzer = new InverseDepsAnalyzer(config, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
651 |
dependencyFilter(config), |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
652 |
writer, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
653 |
options.verbose, |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
654 |
options.apiOnly); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
655 |
boolean ok = analyzer.run(); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
656 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
657 |
log.println(); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
658 |
if (!options.requires.isEmpty()) |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
659 |
log.format("Inverse transitive dependences on %s%n", options.requires); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
660 |
else |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
661 |
log.format("Inverse transitive dependences matching %s%n", |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
662 |
options.regex != null |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
663 |
? options.regex.toString() |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
664 |
: "packages " + options.packageNames); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
665 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
666 |
analyzer.inverseDependences().stream() |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
667 |
.sorted(Comparator.comparing(this::sortPath)) |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
668 |
.forEach(path -> log.println(path.stream() |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
669 |
.map(Archive::getName) |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
670 |
.collect(Collectors.joining(" <- ")))); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
671 |
return ok; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
672 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
673 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
674 |
private String sortPath(Deque<Archive> path) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
675 |
return path.peekFirst().getName(); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
676 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
677 |
|
38524 | 678 |
private boolean genModuleInfo(JdepsConfiguration config) throws IOException { |
679 |
ModuleInfoBuilder builder |
|
680 |
= new ModuleInfoBuilder(config, inputArgs, options.genModuleInfo); |
|
681 |
boolean ok = builder.run(); |
|
682 |
||
683 |
builder.modules().forEach(module -> { |
|
684 |
if (module.packages().contains("")) { |
|
685 |
reportError("ERROR: %s contains unnamed package. " + |
|
686 |
"module-info.java not generated%n", module.getPathName()); |
|
687 |
} |
|
688 |
}); |
|
689 |
||
690 |
if (!ok && !options.nowarning) { |
|
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
691 |
log.println("ERROR: missing dependencies"); |
38524 | 692 |
builder.visitMissingDeps( |
693 |
new Analyzer.Visitor() { |
|
694 |
@Override |
|
695 |
public void visitDependence(String origin, Archive originArchive, |
|
696 |
String target, Archive targetArchive) { |
|
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
697 |
if (builder.notFound(targetArchive)) |
38524 | 698 |
log.format(" %-50s -> %-50s %s%n", |
699 |
origin, target, targetArchive.getName()); |
|
700 |
} |
|
701 |
}); |
|
702 |
} |
|
703 |
return ok; |
|
704 |
} |
|
705 |
||
706 |
/** |
|
707 |
* Returns a filter used during dependency analysis |
|
708 |
*/ |
|
709 |
private JdepsFilter dependencyFilter(JdepsConfiguration config) { |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
710 |
// Filter specified by -filter, -package, -regex, and -requires options |
36526 | 711 |
JdepsFilter.Builder builder = new JdepsFilter.Builder(); |
712 |
||
713 |
// source filters |
|
714 |
builder.includePattern(options.includePattern); |
|
38524 | 715 |
builder.includeSystemModules(options.includeSystemModulePattern); |
36526 | 716 |
|
717 |
builder.filter(options.filterSamePackage, options.filterSameArchive); |
|
718 |
builder.findJDKInternals(options.findJDKInternals); |
|
719 |
||
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
720 |
// -requires |
36526 | 721 |
if (!options.requires.isEmpty()) { |
38524 | 722 |
options.requires.stream() |
723 |
.forEach(mn -> { |
|
724 |
Module m = config.findModule(mn).get(); |
|
725 |
builder.requires(mn, m.packages()); |
|
726 |
}); |
|
36526 | 727 |
} |
728 |
// -regex |
|
729 |
if (options.regex != null) |
|
730 |
builder.regex(options.regex); |
|
731 |
// -package |
|
732 |
if (!options.packageNames.isEmpty()) |
|
733 |
builder.packages(options.packageNames); |
|
734 |
// -filter |
|
735 |
if (options.filterRegex != null) |
|
736 |
builder.filter(options.filterRegex); |
|
737 |
||
38524 | 738 |
// check if system module is set |
739 |
config.rootModules().stream() |
|
740 |
.map(Module::name) |
|
741 |
.forEach(builder::includeIfSystemModule); |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
742 |
|
38524 | 743 |
return builder.build(); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
744 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
745 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
746 |
public void handleOptions(String[] args) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
747 |
// process options |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
748 |
for (int i=0; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
749 |
if (args[i].charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
750 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
751 |
Option option = getOption(name); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
752 |
String param = null; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
753 |
if (option.hasArg) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
754 |
if (name.startsWith("-") && name.indexOf('=') > 0) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
755 |
param = name.substring(name.indexOf('=') + 1, name.length()); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
756 |
} else if (i + 1 < args.length) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
757 |
param = args[++i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
758 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
759 |
if (param == null || param.isEmpty() || param.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
760 |
throw new BadArgs("err.missing.arg", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
761 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
762 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
763 |
option.process(this, name, param); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
764 |
if (option.ignoreRest()) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
765 |
i = args.length; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
766 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
767 |
} else { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
768 |
// process rest of the input arguments |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
769 |
for (; i < args.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
770 |
String name = args[i]; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
771 |
if (name.charAt(0) == '-') { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
772 |
throw new BadArgs("err.option.after.class", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
773 |
} |
38524 | 774 |
inputArgs.add(name); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
775 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
776 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
777 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
778 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
779 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
780 |
private Option getOption(String name) throws BadArgs { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
781 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
782 |
if (o.matches(name)) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
783 |
return o; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
784 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
785 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
786 |
throw new BadArgs("err.unknown.option", name).showUsage(true); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
787 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
788 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
789 |
private void reportError(String key, Object... args) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
790 |
log.println(getMessage("error.prefix") + " " + getMessage(key, args)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
791 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
792 |
|
38524 | 793 |
void warning(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
794 |
log.println(getMessage("warn.prefix") + " " + getMessage(key, args)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
795 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
796 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
797 |
private void showHelp() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
798 |
log.println(getMessage("main.usage", PROGNAME)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
799 |
for (Option o : recognizedOptions) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
800 |
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
|
801 |
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
|
802 |
if (o.isHidden() || name.equals("h") || name.startsWith("filter:")) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
803 |
continue; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
804 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
805 |
log.println(getMessage("main.opt." + name)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
806 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
807 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
808 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
809 |
private void showVersion(boolean full) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
810 |
log.println(version(full ? "full" : "release")); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
811 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
812 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
813 |
private String version(String key) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
814 |
// key=version: mm.nn.oo[-milestone] |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
815 |
// key=full: mm.mm.oo[-milestone]-build |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
816 |
if (ResourceBundleHelper.versionRB == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
817 |
return System.getProperty("java.version"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
818 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
819 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
820 |
return ResourceBundleHelper.versionRB.getString(key); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
821 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
822 |
return getMessage("version.unknown", System.getProperty("java.version")); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
823 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
824 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
825 |
|
16290
b0b4f52de7ea
8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
15030
diff
changeset
|
826 |
static String getMessage(String key, Object... args) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
827 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
828 |
return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
829 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
830 |
throw new InternalError("Missing message: " + key); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
831 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
832 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
833 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
834 |
private static class Options { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
835 |
boolean help; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
836 |
boolean version; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
837 |
boolean fullVersion; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
838 |
boolean showProfile; |
38524 | 839 |
boolean showModule = true; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
840 |
boolean showSummary; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
841 |
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
|
842 |
boolean showLabel; |
22007
907f7054db16
8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents:
21503
diff
changeset
|
843 |
boolean findJDKInternals; |
36526 | 844 |
boolean nowarning = false; |
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
845 |
// default is to show package-level dependencies |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
846 |
// and filter references from same package |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
847 |
Analyzer.Type verbose = PACKAGE; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
848 |
boolean filterSamePackage = true; |
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
22163
diff
changeset
|
849 |
boolean filterSameArchive = false; |
36526 | 850 |
Pattern filterRegex; |
38524 | 851 |
Path dotOutputDir; |
852 |
Path genModuleInfo; |
|
853 |
String classpath; |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
854 |
int depth = 1; |
36526 | 855 |
Set<String> requires = new HashSet<>(); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16560
diff
changeset
|
856 |
Set<String> packageNames = new HashSet<>(); |
36526 | 857 |
Pattern regex; // apply to the dependences |
38524 | 858 |
Pattern includePattern; |
859 |
Pattern includeSystemModulePattern; |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
860 |
boolean inverse = false; |
36526 | 861 |
boolean compileTimeView = false; |
38524 | 862 |
Set<String> checkModuleDeps; |
863 |
String systemModulePath = System.getProperty("java.home"); |
|
36526 | 864 |
String upgradeModulePath; |
865 |
String modulePath; |
|
866 |
String rootModule; |
|
38524 | 867 |
Set<String> addmods = new HashSet<>(); |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
868 |
Runtime.Version multiRelease; |
36526 | 869 |
|
870 |
boolean hasFilter() { |
|
871 |
return numFilters() > 0; |
|
872 |
} |
|
873 |
||
874 |
int numFilters() { |
|
875 |
int count = 0; |
|
876 |
if (requires.size() > 0) count++; |
|
877 |
if (regex != null) count++; |
|
878 |
if (packageNames.size() > 0) count++; |
|
879 |
return count; |
|
880 |
} |
|
38524 | 881 |
} |
36526 | 882 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
883 |
private static class ResourceBundleHelper { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
884 |
static final ResourceBundle versionRB; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
885 |
static final ResourceBundle bundle; |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
886 |
static final ResourceBundle jdkinternals; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
887 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
888 |
static { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
889 |
Locale locale = Locale.getDefault(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
890 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
891 |
bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
892 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
893 |
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
|
894 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
895 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
896 |
versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
897 |
} catch (MissingResourceException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
898 |
throw new InternalError("version.resource.missing"); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
899 |
} |
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
900 |
try { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
901 |
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
|
902 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
903 |
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
|
904 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
905 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
906 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
907 |
|
25692
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
908 |
/** |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
909 |
* 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
|
910 |
* 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
|
911 |
*/ |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
912 |
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
|
913 |
String name = cn; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
914 |
String value = null; |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
915 |
while (value == null && name != null) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
916 |
try { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
917 |
value = ResourceBundleHelper.jdkinternals.getString(name); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
918 |
} catch (MissingResourceException e) { |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
919 |
// go up one subpackage level |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
920 |
int i = name.lastIndexOf('.'); |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
921 |
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
|
922 |
} |
39537fdca12c
8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents:
25442
diff
changeset
|
923 |
} |
39101
fd8a6392b7ea
8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
38532
diff
changeset
|
924 |
return Optional.ofNullable(value); |
36526 | 925 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff
changeset
|
926 |
} |