author | mchung |
Wed, 21 Nov 2018 22:34:01 -0800 | |
changeset 52650 | c16b6cc93272 |
parent 50738 | 6cc2dc161c64 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
36526 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.jdeps; |
|
27 |
||
38524 | 28 |
import static com.sun.tools.jdeps.Module.trace; |
29 |
import static java.util.stream.Collectors.*; |
|
30 |
||
31 |
import com.sun.tools.classfile.Dependency; |
|
32 |
||
33 |
import java.io.BufferedInputStream; |
|
36526 | 34 |
import java.io.File; |
35 |
import java.io.FileNotFoundException; |
|
36 |
import java.io.IOException; |
|
38524 | 37 |
import java.io.InputStream; |
36526 | 38 |
import java.io.UncheckedIOException; |
39 |
import java.lang.module.Configuration; |
|
40 |
import java.lang.module.ModuleDescriptor; |
|
41 |
import java.lang.module.ModuleFinder; |
|
38524 | 42 |
import java.lang.module.ModuleReader; |
36526 | 43 |
import java.lang.module.ModuleReference; |
44 |
import java.lang.module.ResolvedModule; |
|
45 |
import java.net.URI; |
|
38524 | 46 |
import java.nio.file.DirectoryStream; |
36526 | 47 |
import java.nio.file.FileSystem; |
48 |
import java.nio.file.FileSystems; |
|
49 |
import java.nio.file.Files; |
|
50 |
import java.nio.file.Path; |
|
51 |
import java.nio.file.Paths; |
|
38524 | 52 |
import java.util.ArrayList; |
53 |
import java.util.Collections; |
|
54 |
import java.util.HashMap; |
|
55 |
import java.util.HashSet; |
|
56 |
import java.util.LinkedHashMap; |
|
57 |
import java.util.LinkedHashSet; |
|
58 |
import java.util.List; |
|
59 |
import java.util.Map; |
|
60 |
import java.util.Objects; |
|
61 |
import java.util.Optional; |
|
62 |
import java.util.Set; |
|
63 |
import java.util.function.Function; |
|
64 |
import java.util.function.Supplier; |
|
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
65 |
import java.util.stream.Collectors; |
38524 | 66 |
import java.util.stream.Stream; |
67 |
||
38530 | 68 |
public class JdepsConfiguration implements AutoCloseable { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
69 |
// the token for "all modules on the module path" |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
70 |
public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH"; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
71 |
public static final String ALL_DEFAULT = "ALL-DEFAULT"; |
42840
dfe1a03d4db4
8171418: Remove jdeps internal --include-system-modules option
mchung
parents:
42827
diff
changeset
|
72 |
public static final String ALL_SYSTEM = "ALL-SYSTEM"; |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
73 |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
74 |
public static final String MODULE_INFO = "module-info.class"; |
38524 | 75 |
|
76 |
private final SystemModuleFinder system; |
|
77 |
private final ModuleFinder finder; |
|
36526 | 78 |
|
38524 | 79 |
private final Map<String, Module> nameToModule = new LinkedHashMap<>(); |
80 |
private final Map<String, Module> packageToModule = new HashMap<>(); |
|
81 |
private final Map<String, List<Archive>> packageToUnnamedModule = new HashMap<>(); |
|
82 |
||
83 |
private final List<Archive> classpathArchives = new ArrayList<>(); |
|
84 |
private final List<Archive> initialArchives = new ArrayList<>(); |
|
85 |
private final Set<Module> rootModules = new HashSet<>(); |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
86 |
private final Runtime.Version version; |
38524 | 87 |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
88 |
private JdepsConfiguration(Configuration config, |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
89 |
SystemModuleFinder systemModulePath, |
38524 | 90 |
ModuleFinder finder, |
91 |
Set<String> roots, |
|
92 |
List<Path> classpaths, |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
93 |
List<Archive> initialArchives, |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
94 |
Runtime.Version version) |
38524 | 95 |
throws IOException |
96 |
{ |
|
97 |
trace("root: %s%n", roots); |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
98 |
trace("initial archives: %s%n", initialArchives); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
99 |
trace("class path: %s%n", classpaths); |
38524 | 100 |
this.system = systemModulePath; |
101 |
this.finder = finder; |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
102 |
this.version = version; |
36526 | 103 |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
104 |
config.modules().stream() |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
105 |
.map(ResolvedModule::reference) |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
106 |
.forEach(this::addModuleReference); |
36526 | 107 |
|
38524 | 108 |
// packages in unnamed module |
109 |
initialArchives.forEach(archive -> { |
|
110 |
addPackagesInUnnamedModule(archive); |
|
111 |
this.initialArchives.add(archive); |
|
112 |
}); |
|
113 |
||
114 |
// classpath archives |
|
115 |
for (Path p : classpaths) { |
|
116 |
if (Files.exists(p)) { |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
117 |
Archive archive = Archive.getInstance(p, version); |
38524 | 118 |
addPackagesInUnnamedModule(archive); |
119 |
classpathArchives.add(archive); |
|
120 |
} |
|
121 |
} |
|
122 |
||
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
123 |
// all roots specified in --add-modules or -m are included |
38524 | 124 |
// as the initial set for analysis. |
125 |
roots.stream() |
|
126 |
.map(nameToModule::get) |
|
127 |
.forEach(this.rootModules::add); |
|
128 |
||
129 |
initProfiles(); |
|
130 |
||
131 |
trace("resolved modules: %s%n", nameToModule.keySet().stream() |
|
132 |
.sorted().collect(joining("\n", "\n", ""))); |
|
36526 | 133 |
} |
134 |
||
38524 | 135 |
private void initProfiles() { |
136 |
// other system modules are not observed and not added in nameToModule map |
|
137 |
Map<String, Module> systemModules = |
|
138 |
system.moduleNames() |
|
139 |
.collect(toMap(Function.identity(), (mn) -> { |
|
140 |
Module m = nameToModule.get(mn); |
|
141 |
if (m == null) { |
|
142 |
ModuleReference mref = finder.find(mn).get(); |
|
143 |
m = toModule(mref); |
|
144 |
} |
|
145 |
return m; |
|
146 |
})); |
|
147 |
Profile.init(systemModules); |
|
148 |
} |
|
149 |
||
150 |
private void addModuleReference(ModuleReference mref) { |
|
151 |
Module module = toModule(mref); |
|
152 |
nameToModule.put(mref.descriptor().name(), module); |
|
153 |
mref.descriptor().packages() |
|
154 |
.forEach(pn -> packageToModule.putIfAbsent(pn, module)); |
|
155 |
} |
|
156 |
||
157 |
private void addPackagesInUnnamedModule(Archive archive) { |
|
158 |
archive.reader().entries().stream() |
|
159 |
.filter(e -> e.endsWith(".class") && !e.equals(MODULE_INFO)) |
|
160 |
.map(this::toPackageName) |
|
161 |
.distinct() |
|
162 |
.forEach(pn -> packageToUnnamedModule |
|
163 |
.computeIfAbsent(pn, _n -> new ArrayList<>()).add(archive)); |
|
164 |
} |
|
165 |
||
166 |
private String toPackageName(String name) { |
|
167 |
int i = name.lastIndexOf('/'); |
|
168 |
return i > 0 ? name.replace('/', '.').substring(0, i) : ""; |
|
169 |
} |
|
170 |
||
171 |
public Optional<Module> findModule(String name) { |
|
172 |
Objects.requireNonNull(name); |
|
173 |
Module m = nameToModule.get(name); |
|
174 |
return m!= null ? Optional.of(m) : Optional.empty(); |
|
175 |
||
176 |
} |
|
177 |
||
178 |
public Optional<ModuleDescriptor> findModuleDescriptor(String name) { |
|
179 |
Objects.requireNonNull(name); |
|
180 |
Module m = nameToModule.get(name); |
|
181 |
return m!= null ? Optional.of(m.descriptor()) : Optional.empty(); |
|
182 |
} |
|
183 |
||
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
184 |
public static boolean isToken(String name) { |
42840
dfe1a03d4db4
8171418: Remove jdeps internal --include-system-modules option
mchung
parents:
42827
diff
changeset
|
185 |
return ALL_MODULE_PATH.equals(name) || |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
186 |
ALL_DEFAULT.equals(name) || |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
187 |
ALL_SYSTEM.equals(name); |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
188 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
189 |
|
38524 | 190 |
/** |
191 |
* Returns the list of packages that split between resolved module and |
|
192 |
* unnamed module |
|
193 |
*/ |
|
194 |
public Map<String, Set<String>> splitPackages() { |
|
195 |
Set<String> splitPkgs = packageToModule.keySet().stream() |
|
196 |
.filter(packageToUnnamedModule::containsKey) |
|
197 |
.collect(toSet()); |
|
198 |
if (splitPkgs.isEmpty()) |
|
199 |
return Collections.emptyMap(); |
|
200 |
||
201 |
return splitPkgs.stream().collect(toMap(Function.identity(), (pn) -> { |
|
202 |
Set<String> sources = new LinkedHashSet<>(); |
|
203 |
sources.add(packageToModule.get(pn).getModule().location().toString()); |
|
204 |
packageToUnnamedModule.get(pn).stream() |
|
205 |
.map(Archive::getPathName) |
|
206 |
.forEach(sources::add); |
|
207 |
return sources; |
|
208 |
})); |
|
209 |
} |
|
210 |
||
211 |
/** |
|
212 |
* Returns an optional archive containing the given Location |
|
213 |
*/ |
|
214 |
public Optional<Archive> findClass(Dependency.Location location) { |
|
215 |
String name = location.getName(); |
|
216 |
int i = name.lastIndexOf('/'); |
|
217 |
String pn = i > 0 ? name.substring(0, i).replace('/', '.') : ""; |
|
218 |
Archive archive = packageToModule.get(pn); |
|
219 |
if (archive != null) { |
|
220 |
return archive.contains(name + ".class") |
|
221 |
? Optional.of(archive) |
|
222 |
: Optional.empty(); |
|
36526 | 223 |
} |
38524 | 224 |
|
225 |
if (packageToUnnamedModule.containsKey(pn)) { |
|
226 |
return packageToUnnamedModule.get(pn).stream() |
|
227 |
.filter(a -> a.contains(name + ".class")) |
|
228 |
.findFirst(); |
|
36526 | 229 |
} |
38524 | 230 |
return Optional.empty(); |
36526 | 231 |
} |
232 |
||
233 |
/** |
|
234 |
* Returns the list of Modules that can be found in the specified |
|
235 |
* module paths. |
|
236 |
*/ |
|
38524 | 237 |
public Map<String, Module> getModules() { |
238 |
return nameToModule; |
|
36526 | 239 |
} |
240 |
||
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
241 |
/** |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
242 |
* Returns Configuration with the given roots |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
243 |
*/ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
244 |
public Configuration resolve(Set<String> roots) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
245 |
if (roots.isEmpty()) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
246 |
throw new IllegalArgumentException("empty roots"); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
247 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
248 |
return Configuration.empty() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43767
diff
changeset
|
249 |
.resolve(finder, ModuleFinder.of(), roots); |
36526 | 250 |
} |
251 |
||
38524 | 252 |
public List<Archive> classPathArchives() { |
253 |
return classpathArchives; |
|
254 |
} |
|
255 |
||
256 |
public List<Archive> initialArchives() { |
|
257 |
return initialArchives; |
|
258 |
} |
|
259 |
||
260 |
public Set<Module> rootModules() { |
|
261 |
return rootModules; |
|
36526 | 262 |
} |
263 |
||
38524 | 264 |
public Module toModule(ModuleReference mref) { |
265 |
try { |
|
266 |
String mn = mref.descriptor().name(); |
|
267 |
URI location = mref.location().orElseThrow(FileNotFoundException::new); |
|
268 |
ModuleDescriptor md = mref.descriptor(); |
|
47239
2088dbaa2282
8187449: jdeps fails when an upgradeable module is upgraded with an automatic module
mchung
parents:
47216
diff
changeset
|
269 |
// is this module from the system module path? |
2088dbaa2282
8187449: jdeps fails when an upgradeable module is upgraded with an automatic module
mchung
parents:
47216
diff
changeset
|
270 |
URI loc = system.find(mn).flatMap(ModuleReference::location).orElse(null); |
2088dbaa2282
8187449: jdeps fails when an upgradeable module is upgraded with an automatic module
mchung
parents:
47216
diff
changeset
|
271 |
boolean isSystem = location.equals(loc); |
36526 | 272 |
|
38524 | 273 |
final ClassFileReader reader; |
274 |
if (location.getScheme().equals("jrt")) { |
|
275 |
reader = system.getClassReader(mn); |
|
276 |
} else { |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
277 |
reader = ClassFileReader.newInstance(Paths.get(location), version); |
38524 | 278 |
} |
47239
2088dbaa2282
8187449: jdeps fails when an upgradeable module is upgraded with an automatic module
mchung
parents:
47216
diff
changeset
|
279 |
Module.Builder builder = new Module.Builder(md, isSystem); |
38524 | 280 |
builder.classes(reader); |
36526 | 281 |
builder.location(location); |
38524 | 282 |
|
283 |
return builder.build(); |
|
36526 | 284 |
} catch (IOException e) { |
285 |
throw new UncheckedIOException(e); |
|
286 |
} |
|
287 |
} |
|
288 |
||
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
289 |
public Runtime.Version getVersion() { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
290 |
return version; |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
291 |
} |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
292 |
|
38530 | 293 |
/* |
294 |
* Close all archives e.g. JarFile |
|
295 |
*/ |
|
296 |
@Override |
|
297 |
public void close() throws IOException { |
|
298 |
for (Archive archive : initialArchives) |
|
299 |
archive.close(); |
|
300 |
for (Archive archive : classpathArchives) |
|
301 |
archive.close(); |
|
302 |
for (Module module : nameToModule.values()) |
|
303 |
module.close(); |
|
304 |
} |
|
305 |
||
38524 | 306 |
static class SystemModuleFinder implements ModuleFinder { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
307 |
private static final String JAVA_HOME = System.getProperty("java.home"); |
38524 | 308 |
|
309 |
private final FileSystem fileSystem; |
|
310 |
private final Path root; |
|
311 |
private final Map<String, ModuleReference> systemModules; |
|
36526 | 312 |
|
38524 | 313 |
SystemModuleFinder() { |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
314 |
if (Files.isRegularFile(Paths.get(JAVA_HOME, "lib", "modules"))) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
315 |
// jrt file system |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
316 |
this.fileSystem = FileSystems.getFileSystem(URI.create("jrt:/")); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
317 |
this.root = fileSystem.getPath("/modules"); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
318 |
this.systemModules = walk(root); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
319 |
} else { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
320 |
// exploded image |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
321 |
this.fileSystem = FileSystems.getDefault(); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
322 |
root = Paths.get(JAVA_HOME, "modules"); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
323 |
this.systemModules = ModuleFinder.ofSystem().findAll().stream() |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
324 |
.collect(toMap(mref -> mref.descriptor().name(), Function.identity())); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
325 |
} |
38524 | 326 |
} |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
327 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
328 |
SystemModuleFinder(String javaHome) throws IOException { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
329 |
if (javaHome == null) { |
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
330 |
// --system none |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
331 |
this.fileSystem = null; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
332 |
this.root = null; |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
333 |
this.systemModules = Collections.emptyMap(); |
36526 | 334 |
} else { |
50598 | 335 |
if (!Files.isRegularFile(Paths.get(javaHome, "lib", "modules"))) |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
336 |
throw new IllegalArgumentException("Invalid java.home: " + javaHome); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
337 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
338 |
// alternate java.home |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
339 |
Map<String, String> env = new HashMap<>(); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
340 |
env.put("java.home", javaHome); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
341 |
// a remote run-time image |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
342 |
this.fileSystem = FileSystems.newFileSystem(URI.create("jrt:/"), env); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
343 |
this.root = fileSystem.getPath("/modules"); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
344 |
this.systemModules = walk(root); |
36526 | 345 |
} |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
346 |
} |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
347 |
|
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
348 |
private Map<String, ModuleReference> walk(Path root) { |
38529
58cf7e51c16d
8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents:
38525
diff
changeset
|
349 |
try (Stream<Path> stream = Files.walk(root, 1)) { |
58cf7e51c16d
8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents:
38525
diff
changeset
|
350 |
return stream.filter(path -> !path.equals(root)) |
58cf7e51c16d
8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents:
38525
diff
changeset
|
351 |
.map(this::toModuleReference) |
58cf7e51c16d
8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents:
38525
diff
changeset
|
352 |
.collect(toMap(mref -> mref.descriptor().name(), |
58cf7e51c16d
8152502: tools/jdeps/modules/GenModuleInfo.java and TransitiveDeps fails on windows
mchung
parents:
38525
diff
changeset
|
353 |
Function.identity())); |
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
354 |
} catch (IOException e) { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
355 |
throw new UncheckedIOException(e); |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
356 |
} |
36526 | 357 |
} |
358 |
||
38524 | 359 |
private ModuleReference toModuleReference(Path path) { |
360 |
Path minfo = path.resolve(MODULE_INFO); |
|
361 |
try (InputStream in = Files.newInputStream(minfo); |
|
362 |
BufferedInputStream bin = new BufferedInputStream(in)) { |
|
363 |
||
364 |
ModuleDescriptor descriptor = dropHashes(ModuleDescriptor.read(bin)); |
|
365 |
String mn = descriptor.name(); |
|
366 |
URI uri = URI.create("jrt:/" + path.getFileName().toString()); |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
367 |
Supplier<ModuleReader> readerSupplier = () -> new ModuleReader() { |
38524 | 368 |
@Override |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
369 |
public Optional<URI> find(String name) throws IOException { |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
370 |
return name.equals(mn) |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
371 |
? Optional.of(uri) : Optional.empty(); |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
372 |
} |
38524 | 373 |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
374 |
@Override |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
375 |
public Stream<String> list() { |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
376 |
return Stream.empty(); |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
377 |
} |
41859
85710a227743
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41164
diff
changeset
|
378 |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
379 |
@Override |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
380 |
public void close() { |
38524 | 381 |
} |
382 |
}; |
|
383 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
384 |
return new ModuleReference(descriptor, uri) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
385 |
@Override |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
386 |
public ModuleReader open() { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
387 |
return readerSupplier.get(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
388 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
389 |
}; |
38524 | 390 |
} catch (IOException e) { |
391 |
throw new UncheckedIOException(e); |
|
36526 | 392 |
} |
393 |
} |
|
394 |
||
38524 | 395 |
private ModuleDescriptor dropHashes(ModuleDescriptor md) { |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43026
diff
changeset
|
396 |
ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(md.name()); |
38524 | 397 |
md.requires().forEach(builder::requires); |
398 |
md.exports().forEach(builder::exports); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
399 |
md.opens().forEach(builder::opens); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41998
diff
changeset
|
400 |
md.provides().stream().forEach(builder::provides); |
38524 | 401 |
md.uses().stream().forEach(builder::uses); |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43026
diff
changeset
|
402 |
builder.packages(md.packages()); |
38524 | 403 |
return builder.build(); |
404 |
} |
|
405 |
||
406 |
@Override |
|
407 |
public Set<ModuleReference> findAll() { |
|
408 |
return systemModules.values().stream().collect(toSet()); |
|
36526 | 409 |
} |
410 |
||
38524 | 411 |
@Override |
412 |
public Optional<ModuleReference> find(String mn) { |
|
413 |
return systemModules.containsKey(mn) |
|
414 |
? Optional.of(systemModules.get(mn)) : Optional.empty(); |
|
36526 | 415 |
} |
416 |
||
38524 | 417 |
public Stream<String> moduleNames() { |
418 |
return systemModules.values().stream() |
|
419 |
.map(mref -> mref.descriptor().name()); |
|
420 |
} |
|
421 |
||
422 |
public ClassFileReader getClassReader(String modulename) throws IOException { |
|
36526 | 423 |
Path mp = root.resolve(modulename); |
424 |
if (Files.exists(mp) && Files.isDirectory(mp)) { |
|
38524 | 425 |
return ClassFileReader.newInstance(fileSystem, mp); |
36526 | 426 |
} else { |
427 |
throw new FileNotFoundException(mp.toString()); |
|
428 |
} |
|
429 |
} |
|
38524 | 430 |
|
431 |
public Set<String> defaultSystemRoots() { |
|
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
432 |
return systemModules.values().stream() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
433 |
.map(ModuleReference::descriptor) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
434 |
.filter(descriptor -> descriptor.exports() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
435 |
.stream() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
436 |
.filter(e -> !e.isQualified()) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
437 |
.findAny() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
438 |
.isPresent()) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
439 |
.map(ModuleDescriptor::name) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50598
diff
changeset
|
440 |
.collect(Collectors.toSet()); |
38524 | 441 |
} |
36526 | 442 |
} |
443 |
||
38524 | 444 |
public static class Builder { |
445 |
||
446 |
final SystemModuleFinder systemModulePath; |
|
447 |
final Set<String> rootModules = new HashSet<>(); |
|
448 |
final List<Archive> initialArchives = new ArrayList<>(); |
|
449 |
final List<Path> paths = new ArrayList<>(); |
|
450 |
final List<Path> classPaths = new ArrayList<>(); |
|
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
451 |
final Set<String> tokens = new HashSet<>(); |
38524 | 452 |
|
453 |
ModuleFinder upgradeModulePath; |
|
454 |
ModuleFinder appModulePath; |
|
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
455 |
Runtime.Version version; |
38524 | 456 |
|
457 |
public Builder() { |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
458 |
this.systemModulePath = new SystemModuleFinder(); |
38524 | 459 |
} |
460 |
||
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
461 |
public Builder(String javaHome) throws IOException { |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
462 |
this.systemModulePath = SystemModuleFinder.JAVA_HOME.equals(javaHome) |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
463 |
? new SystemModuleFinder() |
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
464 |
: new SystemModuleFinder(javaHome); |
38524 | 465 |
} |
466 |
||
467 |
public Builder upgradeModulePath(String upgradeModulePath) { |
|
468 |
this.upgradeModulePath = createModulePathFinder(upgradeModulePath); |
|
469 |
return this; |
|
470 |
} |
|
471 |
||
472 |
public Builder appModulePath(String modulePath) { |
|
473 |
this.appModulePath = createModulePathFinder(modulePath); |
|
474 |
return this; |
|
475 |
} |
|
476 |
||
477 |
public Builder addmods(Set<String> addmods) { |
|
478 |
for (String mn : addmods) { |
|
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
479 |
if (isToken(mn)) { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
480 |
tokens.add(mn); |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
481 |
} else { |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
482 |
rootModules.add(mn); |
38524 | 483 |
} |
484 |
} |
|
485 |
return this; |
|
486 |
} |
|
487 |
||
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
488 |
public Builder multiRelease(Runtime.Version version) { |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
489 |
this.version = version; |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
490 |
return this; |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
491 |
} |
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
492 |
|
38524 | 493 |
public Builder addRoot(Path path) { |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
494 |
Archive archive = Archive.getInstance(path, version); |
38524 | 495 |
if (archive.contains(MODULE_INFO)) { |
496 |
paths.add(path); |
|
497 |
} else { |
|
498 |
initialArchives.add(archive); |
|
499 |
} |
|
500 |
return this; |
|
501 |
} |
|
502 |
||
503 |
public Builder addClassPath(String classPath) { |
|
504 |
this.classPaths.addAll(getClassPaths(classPath)); |
|
505 |
return this; |
|
506 |
} |
|
507 |
||
508 |
public JdepsConfiguration build() throws IOException { |
|
509 |
ModuleFinder finder = systemModulePath; |
|
510 |
if (upgradeModulePath != null) { |
|
511 |
finder = ModuleFinder.compose(upgradeModulePath, systemModulePath); |
|
512 |
} |
|
513 |
if (appModulePath != null) { |
|
514 |
finder = ModuleFinder.compose(finder, appModulePath); |
|
515 |
} |
|
516 |
if (!paths.isEmpty()) { |
|
517 |
ModuleFinder otherModulePath = ModuleFinder.of(paths.toArray(new Path[0])); |
|
518 |
||
519 |
finder = ModuleFinder.compose(finder, otherModulePath); |
|
520 |
// add modules specified on command-line (convenience) as root set |
|
521 |
otherModulePath.findAll().stream() |
|
522 |
.map(mref -> mref.descriptor().name()) |
|
523 |
.forEach(rootModules::add); |
|
524 |
} |
|
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
525 |
|
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
526 |
// no archive is specified for analysis |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
527 |
// add all system modules as root if --add-modules ALL-SYSTEM is specified |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
528 |
if (tokens.contains(ALL_SYSTEM) && rootModules.isEmpty() && |
43026
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
529 |
initialArchives.isEmpty() && classPaths.isEmpty()) { |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
530 |
systemModulePath.findAll() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
531 |
.stream() |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
532 |
.map(mref -> mref.descriptor().name()) |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
533 |
.forEach(rootModules::add); |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
534 |
} |
8e8b50c7491d
8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents:
42840
diff
changeset
|
535 |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
536 |
// add all modules on app module path as roots if ALL-MODULE-PATH is specified |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
537 |
if ((tokens.contains(ALL_MODULE_PATH)) && appModulePath != null) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
538 |
appModulePath.findAll().stream() |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
539 |
.map(mref -> mref.descriptor().name()) |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
540 |
.forEach(rootModules::add); |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
541 |
} |
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47239
diff
changeset
|
542 |
|
52650
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
543 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
544 |
// build root set for module resolution |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
545 |
Set<String> mods = new HashSet<>(rootModules); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
546 |
// if archives are specified for analysis, then consider as unnamed module |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
547 |
boolean unnamed = !initialArchives.isEmpty() || !classPaths.isEmpty(); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
548 |
if (tokens.contains(ALL_DEFAULT)) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
549 |
mods.addAll(systemModulePath.defaultSystemRoots()); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
550 |
} else if (tokens.contains(ALL_SYSTEM) || unnamed) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
551 |
// resolve all system modules as unnamed module may reference any class |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
552 |
systemModulePath.findAll().stream() |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
553 |
.map(mref -> mref.descriptor().name()) |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
554 |
.forEach(mods::add); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
555 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
556 |
if (unnamed && appModulePath != null) { |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
557 |
// resolve all modules on module path as unnamed module may reference any class |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
558 |
appModulePath.findAll().stream() |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
559 |
.map(mref -> mref.descriptor().name()) |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
560 |
.forEach(mods::add); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
561 |
} |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
562 |
|
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
563 |
// resolve the module graph |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
564 |
Configuration config = Configuration.empty().resolve(finder, ModuleFinder.of(), mods); |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
565 |
return new JdepsConfiguration(config, |
c16b6cc93272
8213909: jdeps --print-module-deps should report missing dependences
mchung
parents:
50738
diff
changeset
|
566 |
systemModulePath, |
38524 | 567 |
finder, |
568 |
rootModules, |
|
569 |
classPaths, |
|
38525
a2169f8fa712
8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents:
38524
diff
changeset
|
570 |
initialArchives, |
41164
69167c89e68f
8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
40762
diff
changeset
|
571 |
version); |
38524 | 572 |
} |
573 |
||
574 |
private static ModuleFinder createModulePathFinder(String mpaths) { |
|
575 |
if (mpaths == null) { |
|
576 |
return null; |
|
577 |
} else { |
|
578 |
String[] dirs = mpaths.split(File.pathSeparator); |
|
579 |
Path[] paths = new Path[dirs.length]; |
|
580 |
int i = 0; |
|
581 |
for (String dir : dirs) { |
|
582 |
paths[i++] = Paths.get(dir); |
|
583 |
} |
|
584 |
return ModuleFinder.of(paths); |
|
585 |
} |
|
586 |
} |
|
587 |
||
588 |
/* |
|
589 |
* Returns the list of Archive specified in cpaths and not included |
|
590 |
* initialArchives |
|
591 |
*/ |
|
592 |
private List<Path> getClassPaths(String cpaths) { |
|
593 |
if (cpaths.isEmpty()) { |
|
594 |
return Collections.emptyList(); |
|
595 |
} |
|
596 |
List<Path> paths = new ArrayList<>(); |
|
597 |
for (String p : cpaths.split(File.pathSeparator)) { |
|
598 |
if (p.length() > 0) { |
|
599 |
// wildcard to parse all JAR files e.g. -classpath dir/* |
|
600 |
int i = p.lastIndexOf(".*"); |
|
601 |
if (i > 0) { |
|
602 |
Path dir = Paths.get(p.substring(0, i)); |
|
603 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.jar")) { |
|
604 |
for (Path entry : stream) { |
|
605 |
paths.add(entry); |
|
606 |
} |
|
607 |
} catch (IOException e) { |
|
608 |
throw new UncheckedIOException(e); |
|
609 |
} |
|
610 |
} else { |
|
611 |
paths.add(Paths.get(p)); |
|
612 |
} |
|
613 |
} |
|
614 |
} |
|
615 |
return paths; |
|
36526 | 616 |
} |
617 |
} |
|
38524 | 618 |
|
36526 | 619 |
} |