53 import java.nio.file.Paths;
54 import java.util.ArrayList;
55 import java.util.Collections;
56 import java.util.HashMap;
57 import java.util.HashSet;
58 import java.util.LinkedHashMap;
59 import java.util.LinkedHashSet;
60 import java.util.List;
61 import java.util.Map;
62 import java.util.Objects;
63 import java.util.Optional;
64 import java.util.Set;
65 import java.util.function.Function;
66 import java.util.function.Supplier;
67 import java.util.stream.Stream;
68
69 public class JdepsConfiguration implements AutoCloseable {
70 // the token for "all modules on the module path"
71 public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
72 public static final String ALL_DEFAULT = "ALL-DEFAULT";
73 public static final String MODULE_INFO = "module-info.class";
74
75 private final SystemModuleFinder system;
76 private final ModuleFinder finder;
77
78 private final Map<String, Module> nameToModule = new LinkedHashMap<>();
79 private final Map<String, Module> packageToModule = new HashMap<>();
80 private final Map<String, List<Archive>> packageToUnnamedModule = new HashMap<>();
81
82 private final List<Archive> classpathArchives = new ArrayList<>();
83 private final List<Archive> initialArchives = new ArrayList<>();
84 private final Set<Module> rootModules = new HashSet<>();
85 private final Configuration configuration;
86 private final Runtime.Version version;
87
88 private JdepsConfiguration(SystemModuleFinder systemModulePath,
89 ModuleFinder finder,
90 Set<String> roots,
91 List<Path> classpaths,
92 List<Archive> initialArchives,
182 }
183
184 private String toPackageName(String name) {
185 int i = name.lastIndexOf('/');
186 return i > 0 ? name.replace('/', '.').substring(0, i) : "";
187 }
188
189 public Optional<Module> findModule(String name) {
190 Objects.requireNonNull(name);
191 Module m = nameToModule.get(name);
192 return m!= null ? Optional.of(m) : Optional.empty();
193
194 }
195
196 public Optional<ModuleDescriptor> findModuleDescriptor(String name) {
197 Objects.requireNonNull(name);
198 Module m = nameToModule.get(name);
199 return m!= null ? Optional.of(m.descriptor()) : Optional.empty();
200 }
201
202 boolean isSystem(Module m) {
203 return system.find(m.name()).isPresent();
204 }
205
206 boolean isValidToken(String name) {
207 return ALL_MODULE_PATH.equals(name) || ALL_DEFAULT.equals(name);
208 }
209
210 /**
211 * Returns the modules that the given module can read
212 */
213 public Stream<Module> reads(Module module) {
214 return configuration.findModule(module.name()).get()
215 .reads().stream()
216 .map(ResolvedModule::name)
217 .map(nameToModule::get);
218 }
219
220 /**
221 * Returns the list of packages that split between resolved module and
222 * unnamed module
223 */
224 public Map<String, Set<String>> splitPackages() {
225 Set<String> splitPkgs = packageToModule.keySet().stream()
226 .filter(packageToUnnamedModule::containsKey)
227 .collect(toSet());
517
518 public Builder upgradeModulePath(String upgradeModulePath) {
519 this.upgradeModulePath = createModulePathFinder(upgradeModulePath);
520 return this;
521 }
522
523 public Builder appModulePath(String modulePath) {
524 this.appModulePath = createModulePathFinder(modulePath);
525 return this;
526 }
527
528 public Builder addmods(Set<String> addmods) {
529 for (String mn : addmods) {
530 switch (mn) {
531 case ALL_MODULE_PATH:
532 this.addAllApplicationModules = true;
533 break;
534 case ALL_DEFAULT:
535 this.addAllDefaultModules = true;
536 break;
537 default:
538 this.rootModules.add(mn);
539 }
540 }
541 return this;
542 }
543
544 /*
545 * This method is for --check option to find all target modules specified
546 * in qualified exports.
547 *
548 * Include all system modules and modules found on modulepath
549 */
550 public Builder allModules() {
551 this.addAllSystemModules = true;
552 this.addAllApplicationModules = true;
553 return this;
554 }
555
556 public Builder multiRelease(Runtime.Version version) {
|
53 import java.nio.file.Paths;
54 import java.util.ArrayList;
55 import java.util.Collections;
56 import java.util.HashMap;
57 import java.util.HashSet;
58 import java.util.LinkedHashMap;
59 import java.util.LinkedHashSet;
60 import java.util.List;
61 import java.util.Map;
62 import java.util.Objects;
63 import java.util.Optional;
64 import java.util.Set;
65 import java.util.function.Function;
66 import java.util.function.Supplier;
67 import java.util.stream.Stream;
68
69 public class JdepsConfiguration implements AutoCloseable {
70 // the token for "all modules on the module path"
71 public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
72 public static final String ALL_DEFAULT = "ALL-DEFAULT";
73 public static final String ALL_SYSTEM = "ALL-SYSTEM";
74 public static final String MODULE_INFO = "module-info.class";
75
76 private final SystemModuleFinder system;
77 private final ModuleFinder finder;
78
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<>();
86 private final Configuration configuration;
87 private final Runtime.Version version;
88
89 private JdepsConfiguration(SystemModuleFinder systemModulePath,
90 ModuleFinder finder,
91 Set<String> roots,
92 List<Path> classpaths,
93 List<Archive> initialArchives,
183 }
184
185 private String toPackageName(String name) {
186 int i = name.lastIndexOf('/');
187 return i > 0 ? name.replace('/', '.').substring(0, i) : "";
188 }
189
190 public Optional<Module> findModule(String name) {
191 Objects.requireNonNull(name);
192 Module m = nameToModule.get(name);
193 return m!= null ? Optional.of(m) : Optional.empty();
194
195 }
196
197 public Optional<ModuleDescriptor> findModuleDescriptor(String name) {
198 Objects.requireNonNull(name);
199 Module m = nameToModule.get(name);
200 return m!= null ? Optional.of(m.descriptor()) : Optional.empty();
201 }
202
203 boolean isValidToken(String name) {
204 return ALL_MODULE_PATH.equals(name) ||
205 ALL_DEFAULT.equals(name) ||
206 ALL_SYSTEM.equals(name);
207 }
208
209 /**
210 * Returns the modules that the given module can read
211 */
212 public Stream<Module> reads(Module module) {
213 return configuration.findModule(module.name()).get()
214 .reads().stream()
215 .map(ResolvedModule::name)
216 .map(nameToModule::get);
217 }
218
219 /**
220 * Returns the list of packages that split between resolved module and
221 * unnamed module
222 */
223 public Map<String, Set<String>> splitPackages() {
224 Set<String> splitPkgs = packageToModule.keySet().stream()
225 .filter(packageToUnnamedModule::containsKey)
226 .collect(toSet());
516
517 public Builder upgradeModulePath(String upgradeModulePath) {
518 this.upgradeModulePath = createModulePathFinder(upgradeModulePath);
519 return this;
520 }
521
522 public Builder appModulePath(String modulePath) {
523 this.appModulePath = createModulePathFinder(modulePath);
524 return this;
525 }
526
527 public Builder addmods(Set<String> addmods) {
528 for (String mn : addmods) {
529 switch (mn) {
530 case ALL_MODULE_PATH:
531 this.addAllApplicationModules = true;
532 break;
533 case ALL_DEFAULT:
534 this.addAllDefaultModules = true;
535 break;
536 case ALL_SYSTEM:
537 this.addAllSystemModules = true;
538 break;
539 default:
540 this.rootModules.add(mn);
541 }
542 }
543 return this;
544 }
545
546 /*
547 * This method is for --check option to find all target modules specified
548 * in qualified exports.
549 *
550 * Include all system modules and modules found on modulepath
551 */
552 public Builder allModules() {
553 this.addAllSystemModules = true;
554 this.addAllApplicationModules = true;
555 return this;
556 }
557
558 public Builder multiRelease(Runtime.Version version) {
|