36526
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
|
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;
|
|
65 |
import java.util.stream.Stream;
|
|
66 |
|
|
67 |
public class JdepsConfiguration {
|
|
68 |
private static final String MODULE_INFO = "module-info.class";
|
|
69 |
|
|
70 |
private final SystemModuleFinder system;
|
|
71 |
private final ModuleFinder finder;
|
36526
|
72 |
|
38524
|
73 |
private final Map<String, Module> nameToModule = new LinkedHashMap<>();
|
|
74 |
private final Map<String, Module> packageToModule = new HashMap<>();
|
|
75 |
private final Map<String, List<Archive>> packageToUnnamedModule = new HashMap<>();
|
|
76 |
|
|
77 |
private final List<Archive> classpathArchives = new ArrayList<>();
|
|
78 |
private final List<Archive> initialArchives = new ArrayList<>();
|
|
79 |
private final Set<Module> rootModules = new HashSet<>();
|
|
80 |
private final Configuration configuration;
|
|
81 |
|
|
82 |
private JdepsConfiguration(SystemModuleFinder systemModulePath,
|
|
83 |
ModuleFinder finder,
|
|
84 |
Set<String> roots,
|
|
85 |
List<Path> classpaths,
|
|
86 |
List<Archive> initialArchives)
|
|
87 |
throws IOException
|
|
88 |
{
|
|
89 |
trace("root: %s%n", roots);
|
|
90 |
|
|
91 |
this.system = systemModulePath;
|
|
92 |
this.finder = finder;
|
36526
|
93 |
|
38524
|
94 |
// build root set
|
|
95 |
Set<String> mods = new HashSet<>();
|
|
96 |
|
|
97 |
if (initialArchives.isEmpty() && classpaths.isEmpty() && !roots.isEmpty()) {
|
|
98 |
// named module as root. No initial unnamed module
|
|
99 |
mods.addAll(roots);
|
|
100 |
} else {
|
|
101 |
// unnamed module
|
|
102 |
mods.addAll(roots);
|
|
103 |
mods.addAll(systemModulePath.defaultSystemRoots());
|
|
104 |
}
|
|
105 |
|
|
106 |
this.configuration = Configuration.empty()
|
|
107 |
.resolveRequires(finder, ModuleFinder.of(), mods);
|
|
108 |
|
|
109 |
this.configuration.modules().stream()
|
|
110 |
.map(ResolvedModule::reference)
|
|
111 |
.forEach(this::addModuleReference);
|
36526
|
112 |
|
38524
|
113 |
// packages in unnamed module
|
|
114 |
initialArchives.forEach(archive -> {
|
|
115 |
addPackagesInUnnamedModule(archive);
|
|
116 |
this.initialArchives.add(archive);
|
|
117 |
});
|
|
118 |
|
|
119 |
// classpath archives
|
|
120 |
for (Path p : classpaths) {
|
|
121 |
if (Files.exists(p)) {
|
|
122 |
Archive archive = Archive.getInstance(p);
|
|
123 |
addPackagesInUnnamedModule(archive);
|
|
124 |
classpathArchives.add(archive);
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
// all roots specified in -addmods or -m are included
|
|
129 |
// as the initial set for analysis.
|
|
130 |
roots.stream()
|
|
131 |
.map(nameToModule::get)
|
|
132 |
.forEach(this.rootModules::add);
|
|
133 |
|
|
134 |
initProfiles();
|
|
135 |
|
|
136 |
trace("resolved modules: %s%n", nameToModule.keySet().stream()
|
|
137 |
.sorted().collect(joining("\n", "\n", "")));
|
36526
|
138 |
}
|
|
139 |
|
38524
|
140 |
private void initProfiles() {
|
|
141 |
// other system modules are not observed and not added in nameToModule map
|
|
142 |
Map<String, Module> systemModules =
|
|
143 |
system.moduleNames()
|
|
144 |
.collect(toMap(Function.identity(), (mn) -> {
|
|
145 |
Module m = nameToModule.get(mn);
|
|
146 |
if (m == null) {
|
|
147 |
ModuleReference mref = finder.find(mn).get();
|
|
148 |
m = toModule(mref);
|
|
149 |
}
|
|
150 |
return m;
|
|
151 |
}));
|
|
152 |
Profile.init(systemModules);
|
|
153 |
}
|
|
154 |
|
|
155 |
private void addModuleReference(ModuleReference mref) {
|
|
156 |
Module module = toModule(mref);
|
|
157 |
nameToModule.put(mref.descriptor().name(), module);
|
|
158 |
mref.descriptor().packages()
|
|
159 |
.forEach(pn -> packageToModule.putIfAbsent(pn, module));
|
|
160 |
}
|
|
161 |
|
|
162 |
private void addPackagesInUnnamedModule(Archive archive) {
|
|
163 |
archive.reader().entries().stream()
|
|
164 |
.filter(e -> e.endsWith(".class") && !e.equals(MODULE_INFO))
|
|
165 |
.map(this::toPackageName)
|
|
166 |
.distinct()
|
|
167 |
.forEach(pn -> packageToUnnamedModule
|
|
168 |
.computeIfAbsent(pn, _n -> new ArrayList<>()).add(archive));
|
|
169 |
}
|
|
170 |
|
|
171 |
private String toPackageName(String name) {
|
|
172 |
int i = name.lastIndexOf('/');
|
|
173 |
return i > 0 ? name.replace('/', '.').substring(0, i) : "";
|
|
174 |
}
|
|
175 |
|
|
176 |
public Optional<Module> findModule(String name) {
|
|
177 |
Objects.requireNonNull(name);
|
|
178 |
Module m = nameToModule.get(name);
|
|
179 |
return m!= null ? Optional.of(m) : Optional.empty();
|
|
180 |
|
|
181 |
}
|
|
182 |
|
|
183 |
public Optional<ModuleDescriptor> findModuleDescriptor(String name) {
|
|
184 |
Objects.requireNonNull(name);
|
|
185 |
Module m = nameToModule.get(name);
|
|
186 |
return m!= null ? Optional.of(m.descriptor()) : Optional.empty();
|
|
187 |
}
|
|
188 |
|
|
189 |
boolean isSystem(Module m) {
|
|
190 |
return system.find(m.name()).isPresent();
|
|
191 |
}
|
|
192 |
|
|
193 |
/**
|
|
194 |
* Returns the modules that the given module can read
|
|
195 |
*/
|
|
196 |
public Stream<Module> reads(Module module) {
|
|
197 |
return configuration.findModule(module.name()).get()
|
|
198 |
.reads().stream()
|
|
199 |
.map(ResolvedModule::name)
|
|
200 |
.map(nameToModule::get);
|
|
201 |
}
|
|
202 |
|
|
203 |
/**
|
|
204 |
* Returns the list of packages that split between resolved module and
|
|
205 |
* unnamed module
|
|
206 |
*/
|
|
207 |
public Map<String, Set<String>> splitPackages() {
|
|
208 |
Set<String> splitPkgs = packageToModule.keySet().stream()
|
|
209 |
.filter(packageToUnnamedModule::containsKey)
|
|
210 |
.collect(toSet());
|
|
211 |
if (splitPkgs.isEmpty())
|
|
212 |
return Collections.emptyMap();
|
|
213 |
|
|
214 |
return splitPkgs.stream().collect(toMap(Function.identity(), (pn) -> {
|
|
215 |
Set<String> sources = new LinkedHashSet<>();
|
|
216 |
sources.add(packageToModule.get(pn).getModule().location().toString());
|
|
217 |
packageToUnnamedModule.get(pn).stream()
|
|
218 |
.map(Archive::getPathName)
|
|
219 |
.forEach(sources::add);
|
|
220 |
return sources;
|
|
221 |
}));
|
|
222 |
}
|
|
223 |
|
|
224 |
/**
|
|
225 |
* Returns an optional archive containing the given Location
|
|
226 |
*/
|
|
227 |
public Optional<Archive> findClass(Dependency.Location location) {
|
|
228 |
String name = location.getName();
|
|
229 |
int i = name.lastIndexOf('/');
|
|
230 |
String pn = i > 0 ? name.substring(0, i).replace('/', '.') : "";
|
|
231 |
Archive archive = packageToModule.get(pn);
|
|
232 |
if (archive != null) {
|
|
233 |
return archive.contains(name + ".class")
|
|
234 |
? Optional.of(archive)
|
|
235 |
: Optional.empty();
|
36526
|
236 |
}
|
38524
|
237 |
|
|
238 |
if (packageToUnnamedModule.containsKey(pn)) {
|
|
239 |
return packageToUnnamedModule.get(pn).stream()
|
|
240 |
.filter(a -> a.contains(name + ".class"))
|
|
241 |
.findFirst();
|
36526
|
242 |
}
|
38524
|
243 |
return Optional.empty();
|
36526
|
244 |
}
|
|
245 |
|
|
246 |
/**
|
|
247 |
* Returns the list of Modules that can be found in the specified
|
|
248 |
* module paths.
|
|
249 |
*/
|
38524
|
250 |
public Map<String, Module> getModules() {
|
|
251 |
return nameToModule;
|
36526
|
252 |
}
|
|
253 |
|
38524
|
254 |
public Stream<Module> resolve(Set<String> roots) {
|
|
255 |
if (roots.isEmpty()) {
|
|
256 |
return nameToModule.values().stream();
|
36526
|
257 |
} else {
|
38524
|
258 |
return Configuration.empty()
|
|
259 |
.resolveRequires(finder, ModuleFinder.of(), roots)
|
|
260 |
.modules().stream()
|
|
261 |
.map(ResolvedModule::name)
|
|
262 |
.map(nameToModule::get);
|
36526
|
263 |
}
|
|
264 |
}
|
|
265 |
|
38524
|
266 |
public List<Archive> classPathArchives() {
|
|
267 |
return classpathArchives;
|
|
268 |
}
|
|
269 |
|
|
270 |
public List<Archive> initialArchives() {
|
|
271 |
return initialArchives;
|
|
272 |
}
|
|
273 |
|
|
274 |
public Set<Module> rootModules() {
|
|
275 |
return rootModules;
|
36526
|
276 |
}
|
|
277 |
|
38524
|
278 |
public Module toModule(ModuleReference mref) {
|
|
279 |
try {
|
|
280 |
String mn = mref.descriptor().name();
|
|
281 |
URI location = mref.location().orElseThrow(FileNotFoundException::new);
|
|
282 |
ModuleDescriptor md = mref.descriptor();
|
|
283 |
Module.Builder builder = new Module.Builder(md, system.find(mn).isPresent());
|
36526
|
284 |
|
38524
|
285 |
final ClassFileReader reader;
|
|
286 |
if (location.getScheme().equals("jrt")) {
|
|
287 |
reader = system.getClassReader(mn);
|
|
288 |
} else {
|
|
289 |
reader = ClassFileReader.newInstance(Paths.get(location));
|
|
290 |
}
|
|
291 |
|
|
292 |
builder.classes(reader);
|
36526
|
293 |
builder.location(location);
|
38524
|
294 |
|
|
295 |
return builder.build();
|
36526
|
296 |
} catch (IOException e) {
|
|
297 |
throw new UncheckedIOException(e);
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
38524
|
301 |
static class SystemModuleFinder implements ModuleFinder {
|
|
302 |
private static final String JAVA_SE = "java.se";
|
|
303 |
|
|
304 |
private final FileSystem fileSystem;
|
|
305 |
private final Path root;
|
|
306 |
private final Map<String, ModuleReference> systemModules;
|
36526
|
307 |
|
38524
|
308 |
SystemModuleFinder() {
|
|
309 |
this(System.getProperty("java.home"));
|
|
310 |
}
|
|
311 |
SystemModuleFinder(String javaHome) {
|
|
312 |
final FileSystem fs;
|
|
313 |
final Path root;
|
|
314 |
final Map<String, ModuleReference> systemModules;
|
|
315 |
if (javaHome != null) {
|
|
316 |
if (Files.isRegularFile(Paths.get(javaHome, "lib", "modules"))) {
|
|
317 |
try {
|
|
318 |
// jrt file system
|
|
319 |
fs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
|
320 |
root = fs.getPath("/modules");
|
|
321 |
systemModules = Files.walk(root, 1)
|
|
322 |
.filter(path -> !path.equals(root))
|
|
323 |
.map(this::toModuleReference)
|
|
324 |
.collect(toMap(mref -> mref.descriptor().name(),
|
|
325 |
Function.identity()));
|
|
326 |
} catch (IOException e) {
|
|
327 |
throw new UncheckedIOException(e);
|
|
328 |
}
|
|
329 |
} else {
|
|
330 |
// exploded image
|
|
331 |
fs = FileSystems.getDefault();
|
|
332 |
root = Paths.get(javaHome, "modules");
|
|
333 |
systemModules = ModuleFinder.ofSystem().findAll().stream()
|
|
334 |
.collect(toMap(mref -> mref.descriptor().name(), Function.identity()));
|
|
335 |
}
|
36526
|
336 |
} else {
|
38524
|
337 |
fs = null;
|
|
338 |
root = null;
|
|
339 |
systemModules = Collections.emptyMap();
|
36526
|
340 |
}
|
38524
|
341 |
this.fileSystem = fs;
|
|
342 |
this.root = root;
|
|
343 |
this.systemModules = systemModules;
|
36526
|
344 |
}
|
|
345 |
|
38524
|
346 |
private ModuleReference toModuleReference(Path path) {
|
|
347 |
Path minfo = path.resolve(MODULE_INFO);
|
|
348 |
try (InputStream in = Files.newInputStream(minfo);
|
|
349 |
BufferedInputStream bin = new BufferedInputStream(in)) {
|
|
350 |
|
|
351 |
ModuleDescriptor descriptor = dropHashes(ModuleDescriptor.read(bin));
|
|
352 |
String mn = descriptor.name();
|
|
353 |
URI uri = URI.create("jrt:/" + path.getFileName().toString());
|
|
354 |
Supplier<ModuleReader> readerSupplier = new Supplier<>() {
|
|
355 |
@Override
|
|
356 |
public ModuleReader get() {
|
|
357 |
return new ModuleReader() {
|
|
358 |
@Override
|
|
359 |
public Optional<URI> find(String name) throws IOException {
|
|
360 |
return name.equals(mn)
|
|
361 |
? Optional.of(uri) : Optional.empty();
|
|
362 |
}
|
|
363 |
|
|
364 |
@Override
|
|
365 |
public void close() throws IOException {
|
|
366 |
}
|
|
367 |
};
|
|
368 |
}
|
|
369 |
};
|
|
370 |
|
|
371 |
return new ModuleReference(descriptor, uri, readerSupplier);
|
|
372 |
} catch (IOException e) {
|
|
373 |
throw new UncheckedIOException(e);
|
36526
|
374 |
}
|
|
375 |
}
|
|
376 |
|
38524
|
377 |
private ModuleDescriptor dropHashes(ModuleDescriptor md) {
|
|
378 |
ModuleDescriptor.Builder builder = new ModuleDescriptor.Builder(md.name());
|
|
379 |
md.requires().forEach(builder::requires);
|
|
380 |
md.exports().forEach(builder::exports);
|
|
381 |
md.provides().values().stream().forEach(builder::provides);
|
|
382 |
md.uses().stream().forEach(builder::uses);
|
|
383 |
builder.conceals(md.conceals());
|
|
384 |
return builder.build();
|
|
385 |
}
|
|
386 |
|
|
387 |
@Override
|
|
388 |
public Set<ModuleReference> findAll() {
|
|
389 |
return systemModules.values().stream().collect(toSet());
|
36526
|
390 |
}
|
|
391 |
|
38524
|
392 |
@Override
|
|
393 |
public Optional<ModuleReference> find(String mn) {
|
|
394 |
return systemModules.containsKey(mn)
|
|
395 |
? Optional.of(systemModules.get(mn)) : Optional.empty();
|
36526
|
396 |
}
|
|
397 |
|
38524
|
398 |
public Stream<String> moduleNames() {
|
|
399 |
return systemModules.values().stream()
|
|
400 |
.map(mref -> mref.descriptor().name());
|
|
401 |
}
|
|
402 |
|
|
403 |
public ClassFileReader getClassReader(String modulename) throws IOException {
|
36526
|
404 |
Path mp = root.resolve(modulename);
|
|
405 |
if (Files.exists(mp) && Files.isDirectory(mp)) {
|
38524
|
406 |
return ClassFileReader.newInstance(fileSystem, mp);
|
36526
|
407 |
} else {
|
|
408 |
throw new FileNotFoundException(mp.toString());
|
|
409 |
}
|
|
410 |
}
|
38524
|
411 |
|
|
412 |
public Set<String> defaultSystemRoots() {
|
|
413 |
Set<String> roots = new HashSet<>();
|
|
414 |
boolean hasJava = false;
|
|
415 |
if (systemModules.containsKey(JAVA_SE)) {
|
|
416 |
// java.se is a system module
|
|
417 |
hasJava = true;
|
|
418 |
roots.add(JAVA_SE);
|
|
419 |
}
|
|
420 |
|
|
421 |
for (ModuleReference mref : systemModules.values()) {
|
|
422 |
String mn = mref.descriptor().name();
|
|
423 |
if (hasJava && mn.startsWith("java."))
|
|
424 |
continue;
|
|
425 |
|
|
426 |
// add as root if observable and exports at least one package
|
|
427 |
ModuleDescriptor descriptor = mref.descriptor();
|
|
428 |
for (ModuleDescriptor.Exports e : descriptor.exports()) {
|
|
429 |
if (!e.isQualified()) {
|
|
430 |
roots.add(mn);
|
|
431 |
break;
|
|
432 |
}
|
|
433 |
}
|
|
434 |
}
|
|
435 |
return roots;
|
|
436 |
}
|
36526
|
437 |
}
|
|
438 |
|
38524
|
439 |
public static class Builder {
|
|
440 |
// the token for "all modules on the module path"
|
|
441 |
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
|
|
442 |
|
|
443 |
final SystemModuleFinder systemModulePath;
|
|
444 |
final Set<String> rootModules = new HashSet<>();
|
|
445 |
final List<Archive> initialArchives = new ArrayList<>();
|
|
446 |
final List<Path> paths = new ArrayList<>();
|
|
447 |
final List<Path> classPaths = new ArrayList<>();
|
|
448 |
|
|
449 |
ModuleFinder upgradeModulePath;
|
|
450 |
ModuleFinder appModulePath;
|
|
451 |
boolean addAllApplicationModules;
|
|
452 |
|
|
453 |
public Builder() {
|
|
454 |
this(System.getProperty("java.home"));
|
|
455 |
}
|
|
456 |
|
|
457 |
public Builder(String systemModulePath) {
|
|
458 |
this.systemModulePath = new SystemModuleFinder(systemModulePath);;
|
|
459 |
}
|
|
460 |
|
|
461 |
public Builder upgradeModulePath(String upgradeModulePath) {
|
|
462 |
this.upgradeModulePath = createModulePathFinder(upgradeModulePath);
|
|
463 |
return this;
|
|
464 |
}
|
|
465 |
|
|
466 |
public Builder appModulePath(String modulePath) {
|
|
467 |
this.appModulePath = createModulePathFinder(modulePath);
|
|
468 |
return this;
|
|
469 |
}
|
|
470 |
|
|
471 |
public Builder addmods(Set<String> addmods) {
|
|
472 |
for (String mn : addmods) {
|
|
473 |
switch (mn) {
|
|
474 |
case ALL_MODULE_PATH:
|
|
475 |
this.addAllApplicationModules = true;
|
|
476 |
break;
|
|
477 |
default:
|
|
478 |
this.rootModules.add(mn);
|
|
479 |
}
|
|
480 |
}
|
|
481 |
return this;
|
|
482 |
}
|
|
483 |
|
|
484 |
/*
|
|
485 |
* This method is for -check option to find all target modules specified
|
|
486 |
* in qualified exports.
|
|
487 |
*
|
|
488 |
* Include all system modules and modules found on modulepath
|
|
489 |
*/
|
|
490 |
public Builder allModules() {
|
|
491 |
systemModulePath.moduleNames()
|
|
492 |
.forEach(this.rootModules::add);
|
|
493 |
this.addAllApplicationModules = true;
|
|
494 |
return this;
|
|
495 |
}
|
|
496 |
|
|
497 |
public Builder addRoot(Path path) {
|
|
498 |
Archive archive = Archive.getInstance(path);
|
|
499 |
if (archive.contains(MODULE_INFO)) {
|
|
500 |
paths.add(path);
|
|
501 |
} else {
|
|
502 |
initialArchives.add(archive);
|
|
503 |
}
|
|
504 |
return this;
|
|
505 |
}
|
|
506 |
|
|
507 |
public Builder addClassPath(String classPath) {
|
|
508 |
this.classPaths.addAll(getClassPaths(classPath));
|
|
509 |
return this;
|
|
510 |
}
|
|
511 |
|
|
512 |
public JdepsConfiguration build() throws IOException {
|
|
513 |
ModuleFinder finder = systemModulePath;
|
|
514 |
if (upgradeModulePath != null) {
|
|
515 |
finder = ModuleFinder.compose(upgradeModulePath, systemModulePath);
|
|
516 |
}
|
|
517 |
if (appModulePath != null) {
|
|
518 |
finder = ModuleFinder.compose(finder, appModulePath);
|
|
519 |
}
|
|
520 |
if (!paths.isEmpty()) {
|
|
521 |
ModuleFinder otherModulePath = ModuleFinder.of(paths.toArray(new Path[0]));
|
|
522 |
|
|
523 |
finder = ModuleFinder.compose(finder, otherModulePath);
|
|
524 |
// add modules specified on command-line (convenience) as root set
|
|
525 |
otherModulePath.findAll().stream()
|
|
526 |
.map(mref -> mref.descriptor().name())
|
|
527 |
.forEach(rootModules::add);
|
|
528 |
}
|
|
529 |
if (addAllApplicationModules && appModulePath != null) {
|
|
530 |
appModulePath.findAll().stream()
|
|
531 |
.map(mref -> mref.descriptor().name())
|
|
532 |
.forEach(rootModules::add);
|
|
533 |
}
|
|
534 |
return new JdepsConfiguration(systemModulePath,
|
|
535 |
finder,
|
|
536 |
rootModules,
|
|
537 |
classPaths,
|
|
538 |
initialArchives);
|
|
539 |
}
|
|
540 |
|
|
541 |
private static ModuleFinder createModulePathFinder(String mpaths) {
|
|
542 |
if (mpaths == null) {
|
|
543 |
return null;
|
|
544 |
} else {
|
|
545 |
String[] dirs = mpaths.split(File.pathSeparator);
|
|
546 |
Path[] paths = new Path[dirs.length];
|
|
547 |
int i = 0;
|
|
548 |
for (String dir : dirs) {
|
|
549 |
paths[i++] = Paths.get(dir);
|
|
550 |
}
|
|
551 |
return ModuleFinder.of(paths);
|
|
552 |
}
|
|
553 |
}
|
|
554 |
|
|
555 |
/*
|
|
556 |
* Returns the list of Archive specified in cpaths and not included
|
|
557 |
* initialArchives
|
|
558 |
*/
|
|
559 |
private List<Path> getClassPaths(String cpaths) {
|
|
560 |
if (cpaths.isEmpty()) {
|
|
561 |
return Collections.emptyList();
|
|
562 |
}
|
|
563 |
List<Path> paths = new ArrayList<>();
|
|
564 |
for (String p : cpaths.split(File.pathSeparator)) {
|
|
565 |
if (p.length() > 0) {
|
|
566 |
// wildcard to parse all JAR files e.g. -classpath dir/*
|
|
567 |
int i = p.lastIndexOf(".*");
|
|
568 |
if (i > 0) {
|
|
569 |
Path dir = Paths.get(p.substring(0, i));
|
|
570 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.jar")) {
|
|
571 |
for (Path entry : stream) {
|
|
572 |
paths.add(entry);
|
|
573 |
}
|
|
574 |
} catch (IOException e) {
|
|
575 |
throw new UncheckedIOException(e);
|
|
576 |
}
|
|
577 |
} else {
|
|
578 |
paths.add(Paths.get(p));
|
|
579 |
}
|
|
580 |
}
|
|
581 |
}
|
|
582 |
return paths;
|
36526
|
583 |
}
|
|
584 |
}
|
38524
|
585 |
|
36526
|
586 |
}
|