110
111 this.configuration.modules().stream()
112 .map(ResolvedModule::reference)
113 .forEach(this::addModuleReference);
114
115 // packages in unnamed module
116 initialArchives.forEach(archive -> {
117 addPackagesInUnnamedModule(archive);
118 this.initialArchives.add(archive);
119 });
120
121 // classpath archives
122 for (Path p : classpaths) {
123 if (Files.exists(p)) {
124 Archive archive = Archive.getInstance(p);
125 addPackagesInUnnamedModule(archive);
126 classpathArchives.add(archive);
127 }
128 }
129
130 // all roots specified in -addmods or -m are included
131 // as the initial set for analysis.
132 roots.stream()
133 .map(nameToModule::get)
134 .forEach(this.rootModules::add);
135
136 initProfiles();
137
138 trace("resolved modules: %s%n", nameToModule.keySet().stream()
139 .sorted().collect(joining("\n", "\n", "")));
140 }
141
142 private void initProfiles() {
143 // other system modules are not observed and not added in nameToModule map
144 Map<String, Module> systemModules =
145 system.moduleNames()
146 .collect(toMap(Function.identity(), (mn) -> {
147 Module m = nameToModule.get(mn);
148 if (m == null) {
149 ModuleReference mref = finder.find(mn).get();
150 m = toModule(mref);
325 private final Path root;
326 private final Map<String, ModuleReference> systemModules;
327
328 SystemModuleFinder() {
329 if (Files.isRegularFile(Paths.get(JAVA_HOME, "lib", "modules"))) {
330 // jrt file system
331 this.fileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
332 this.root = fileSystem.getPath("/modules");
333 this.systemModules = walk(root);
334 } else {
335 // exploded image
336 this.fileSystem = FileSystems.getDefault();
337 root = Paths.get(JAVA_HOME, "modules");
338 this.systemModules = ModuleFinder.ofSystem().findAll().stream()
339 .collect(toMap(mref -> mref.descriptor().name(), Function.identity()));
340 }
341 }
342
343 SystemModuleFinder(String javaHome) throws IOException {
344 if (javaHome == null) {
345 // -system none
346 this.fileSystem = null;
347 this.root = null;
348 this.systemModules = Collections.emptyMap();
349 } else {
350 if (Files.isRegularFile(Paths.get(javaHome, "lib", "modules")))
351 throw new IllegalArgumentException("Invalid java.home: " + javaHome);
352
353 // alternate java.home
354 Map<String, String> env = new HashMap<>();
355 env.put("java.home", javaHome);
356 // a remote run-time image
357 this.fileSystem = FileSystems.newFileSystem(URI.create("jrt:/"), env);
358 this.root = fileSystem.getPath("/modules");
359 this.systemModules = walk(root);
360 }
361 }
362
363 private Map<String, ModuleReference> walk(Path root) {
364 try (Stream<Path> stream = Files.walk(root, 1)) {
365 return stream.filter(path -> !path.equals(root))
|
110
111 this.configuration.modules().stream()
112 .map(ResolvedModule::reference)
113 .forEach(this::addModuleReference);
114
115 // packages in unnamed module
116 initialArchives.forEach(archive -> {
117 addPackagesInUnnamedModule(archive);
118 this.initialArchives.add(archive);
119 });
120
121 // classpath archives
122 for (Path p : classpaths) {
123 if (Files.exists(p)) {
124 Archive archive = Archive.getInstance(p);
125 addPackagesInUnnamedModule(archive);
126 classpathArchives.add(archive);
127 }
128 }
129
130 // all roots specified in --add-modules or -m are included
131 // as the initial set for analysis.
132 roots.stream()
133 .map(nameToModule::get)
134 .forEach(this.rootModules::add);
135
136 initProfiles();
137
138 trace("resolved modules: %s%n", nameToModule.keySet().stream()
139 .sorted().collect(joining("\n", "\n", "")));
140 }
141
142 private void initProfiles() {
143 // other system modules are not observed and not added in nameToModule map
144 Map<String, Module> systemModules =
145 system.moduleNames()
146 .collect(toMap(Function.identity(), (mn) -> {
147 Module m = nameToModule.get(mn);
148 if (m == null) {
149 ModuleReference mref = finder.find(mn).get();
150 m = toModule(mref);
325 private final Path root;
326 private final Map<String, ModuleReference> systemModules;
327
328 SystemModuleFinder() {
329 if (Files.isRegularFile(Paths.get(JAVA_HOME, "lib", "modules"))) {
330 // jrt file system
331 this.fileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
332 this.root = fileSystem.getPath("/modules");
333 this.systemModules = walk(root);
334 } else {
335 // exploded image
336 this.fileSystem = FileSystems.getDefault();
337 root = Paths.get(JAVA_HOME, "modules");
338 this.systemModules = ModuleFinder.ofSystem().findAll().stream()
339 .collect(toMap(mref -> mref.descriptor().name(), Function.identity()));
340 }
341 }
342
343 SystemModuleFinder(String javaHome) throws IOException {
344 if (javaHome == null) {
345 // --system none
346 this.fileSystem = null;
347 this.root = null;
348 this.systemModules = Collections.emptyMap();
349 } else {
350 if (Files.isRegularFile(Paths.get(javaHome, "lib", "modules")))
351 throw new IllegalArgumentException("Invalid java.home: " + javaHome);
352
353 // alternate java.home
354 Map<String, String> env = new HashMap<>();
355 env.put("java.home", javaHome);
356 // a remote run-time image
357 this.fileSystem = FileSystems.newFileSystem(URI.create("jrt:/"), env);
358 this.root = fileSystem.getPath("/modules");
359 this.systemModules = walk(root);
360 }
361 }
362
363 private Map<String, ModuleReference> walk(Path root) {
364 try (Stream<Path> stream = Files.walk(root, 1)) {
365 return stream.filter(path -> !path.equals(root))
|