< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleInfoBuilder.java

Print this page

        

*** 41,54 **** --- 41,56 ---- import java.nio.file.Paths; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; + import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.Function; + import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.stream.Collectors.*; public class ModuleInfoBuilder {
*** 58,69 **** final DependencyFinder dependencyFinder; final Analyzer analyzer; // an input JAR file (loaded as an automatic module for analysis) ! // maps to an explicit module to generate module-info.java ! final Map<Module, Module> automaticToExplicitModule; public ModuleInfoBuilder(JdepsConfiguration configuration, List<String> args, Path outputdir, boolean open) { this.configuration = configuration; --- 60,71 ---- final DependencyFinder dependencyFinder; final Analyzer analyzer; // an input JAR file (loaded as an automatic module for analysis) ! // maps to a normal module to generate module-info.java ! final Map<Module, Module> automaticToNormalModule; public ModuleInfoBuilder(JdepsConfiguration configuration, List<String> args, Path outputdir, boolean open) { this.configuration = configuration;
*** 76,99 **** // add targets to modulepath if it has module-info.class List<Path> paths = args.stream() .map(fn -> Paths.get(fn)) .collect(toList()); ! // automatic module to convert to explicit module ! this.automaticToExplicitModule = ModuleFinder.of(paths.toArray(new Path[0])) .findAll().stream() .map(configuration::toModule) .collect(toMap(Function.identity(), Function.identity())); ! Optional<Module> om = automaticToExplicitModule.keySet().stream() .filter(m -> !m.descriptor().isAutomatic()) .findAny(); if (om.isPresent()) { throw new UncheckedBadArgs(new BadArgs("err.genmoduleinfo.not.jarfile", om.get().getPathName())); } ! if (automaticToExplicitModule.isEmpty()) { throw new UncheckedBadArgs(new BadArgs("err.invalid.path", args)); } } public boolean run() throws IOException { --- 78,101 ---- // add targets to modulepath if it has module-info.class List<Path> paths = args.stream() .map(fn -> Paths.get(fn)) .collect(toList()); ! // automatic module to convert to normal module ! this.automaticToNormalModule = ModuleFinder.of(paths.toArray(new Path[0])) .findAll().stream() .map(configuration::toModule) .collect(toMap(Function.identity(), Function.identity())); ! Optional<Module> om = automaticToNormalModule.keySet().stream() .filter(m -> !m.descriptor().isAutomatic()) .findAny(); if (om.isPresent()) { throw new UncheckedBadArgs(new BadArgs("err.genmoduleinfo.not.jarfile", om.get().getPathName())); } ! if (automaticToNormalModule.isEmpty()) { throw new UncheckedBadArgs(new BadArgs("err.invalid.path", args)); } } public boolean run() throws IOException {
*** 113,129 **** : Collections.emptySet(); Path file = outputdir.resolve(m.name()).resolve("module-info.java"); // computes requires and requires transitive ! Module explicitModule = toExplicitModule(m, apiDeps); ! if (explicitModule != null) { ! automaticToExplicitModule.put(m, explicitModule); // generate module-info.java System.out.format("writing to %s%n", file); ! writeModuleInfo(file, explicitModule.descriptor()); } else { // find missing dependences System.out.format("Missing dependence: %s not generated%n", file); missingDeps = true; } --- 115,131 ---- : Collections.emptySet(); Path file = outputdir.resolve(m.name()).resolve("module-info.java"); // computes requires and requires transitive ! Module normalModule = toNormalModule(m, apiDeps); ! if (normalModule != null) { ! automaticToNormalModule.put(m, normalModule); // generate module-info.java System.out.format("writing to %s%n", file); ! writeModuleInfo(file, normalModule.descriptor()); } else { // find missing dependences System.out.format("Missing dependence: %s not generated%n", file); missingDeps = true; }
*** 137,147 **** boolean notFound(Archive m) { return m == NOT_FOUND || m == REMOVED_JDK_INTERNALS; } ! private Module toExplicitModule(Module module, Set<Archive> requiresTransitive) throws IOException { // done analysis module.close(); --- 139,149 ---- boolean notFound(Archive m) { return m == NOT_FOUND || m == REMOVED_JDK_INTERNALS; } ! private Module toNormalModule(Module module, Set<Archive> requiresTransitive) throws IOException { // done analysis module.close();
*** 157,181 **** analyzer.requires(module) .map(Archive::getModule) .forEach(d -> requires.putIfAbsent(d.name(), Boolean.FALSE)); ! return module.toStrictModule(requires); } /** * Returns the stream of resulting modules */ Stream<Module> modules() { ! return automaticToExplicitModule.values().stream(); } /** * Returns the stream of resulting ModuleDescriptors */ public Stream<ModuleDescriptor> descriptors() { ! return automaticToExplicitModule.entrySet().stream() .map(Map.Entry::getValue) .map(Module::descriptor); } void visitMissingDeps(Analyzer.Visitor visitor) { --- 159,183 ---- analyzer.requires(module) .map(Archive::getModule) .forEach(d -> requires.putIfAbsent(d.name(), Boolean.FALSE)); ! return module.toNormalModule(requires); } /** * Returns the stream of resulting modules */ Stream<Module> modules() { ! return automaticToNormalModule.values().stream(); } /** * Returns the stream of resulting ModuleDescriptors */ public Stream<ModuleDescriptor> descriptors() { ! return automaticToNormalModule.entrySet().stream() .map(Map.Entry::getValue) .map(Module::descriptor); } void visitMissingDeps(Analyzer.Visitor visitor) {
*** 203,213 **** Map<String, Module> modules = configuration.getModules(); // first print the JDK modules md.requires().stream() .filter(req -> !req.name().equals("java.base")) // implicit requires .sorted(Comparator.comparing(Requires::name)) ! .forEach(req -> writer.format(" requires %s;%n", req)); if (!open) { md.exports().stream() .peek(exp -> { if (exp.targets().size() > 0) --- 205,216 ---- Map<String, Module> modules = configuration.getModules(); // first print the JDK modules md.requires().stream() .filter(req -> !req.name().equals("java.base")) // implicit requires .sorted(Comparator.comparing(Requires::name)) ! .forEach(req -> writer.format(" requires %s;%n", ! toString(req.modifiers(), req.name()))); if (!open) { md.exports().stream() .peek(exp -> { if (exp.targets().size() > 0)
*** 229,239 **** writer.println("}"); } private Set<Module> automaticModules() { ! return automaticToExplicitModule.keySet(); } /** * Compute 'requires transitive' dependences by analyzing API dependencies */ --- 232,251 ---- writer.println("}"); } private Set<Module> automaticModules() { ! return automaticToNormalModule.keySet(); ! } ! ! /** ! * Returns a string containing the given set of modifiers and label. ! */ ! private static <M> String toString(Set<M> mods, String what) { ! return (Stream.concat(mods.stream().map(e -> e.toString().toLowerCase(Locale.US)), ! Stream.of(what))) ! .collect(Collectors.joining(" ")); } /** * Compute 'requires transitive' dependences by analyzing API dependencies */
< prev index next >