src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java
changeset 52650 c16b6cc93272
parent 50738 6cc2dc161c64
equal deleted inserted replaced
52649:e00cf18e2593 52650:c16b6cc93272
    81     private final Map<String, List<Archive>> packageToUnnamedModule = new HashMap<>();
    81     private final Map<String, List<Archive>> packageToUnnamedModule = new HashMap<>();
    82 
    82 
    83     private final List<Archive> classpathArchives = new ArrayList<>();
    83     private final List<Archive> classpathArchives = new ArrayList<>();
    84     private final List<Archive> initialArchives = new ArrayList<>();
    84     private final List<Archive> initialArchives = new ArrayList<>();
    85     private final Set<Module> rootModules = new HashSet<>();
    85     private final Set<Module> rootModules = new HashSet<>();
    86     private final Configuration configuration;
       
    87     private final Runtime.Version version;
    86     private final Runtime.Version version;
    88 
    87 
    89     private JdepsConfiguration(SystemModuleFinder systemModulePath,
    88     private JdepsConfiguration(Configuration config,
       
    89                                SystemModuleFinder systemModulePath,
    90                                ModuleFinder finder,
    90                                ModuleFinder finder,
    91                                Set<String> roots,
    91                                Set<String> roots,
    92                                List<Path> classpaths,
    92                                List<Path> classpaths,
    93                                List<Archive> initialArchives,
    93                                List<Archive> initialArchives,
    94                                Set<String> tokens,
       
    95                                Runtime.Version version)
    94                                Runtime.Version version)
    96         throws IOException
    95         throws IOException
    97     {
    96     {
    98         trace("root: %s%n", roots);
    97         trace("root: %s%n", roots);
    99 
    98         trace("initial archives: %s%n", initialArchives);
       
    99         trace("class path: %s%n", classpaths);
   100         this.system = systemModulePath;
   100         this.system = systemModulePath;
   101         this.finder = finder;
   101         this.finder = finder;
   102         this.version = version;
   102         this.version = version;
   103 
   103 
   104         // build root set for resolution
   104         config.modules().stream()
   105         Set<String> mods = new HashSet<>(roots);
   105               .map(ResolvedModule::reference)
   106         if (tokens.contains(ALL_SYSTEM)) {
   106               .forEach(this::addModuleReference);
   107             systemModulePath.findAll().stream()
       
   108                 .map(mref -> mref.descriptor().name())
       
   109                 .forEach(mods::add);
       
   110         }
       
   111 
       
   112         if (tokens.contains(ALL_DEFAULT)) {
       
   113             mods.addAll(systemModulePath.defaultSystemRoots());
       
   114         }
       
   115 
       
   116         this.configuration = Configuration.empty()
       
   117                 .resolve(finder, ModuleFinder.of(), mods);
       
   118 
       
   119         this.configuration.modules().stream()
       
   120                 .map(ResolvedModule::reference)
       
   121                 .forEach(this::addModuleReference);
       
   122 
   107 
   123         // packages in unnamed module
   108         // packages in unnamed module
   124         initialArchives.forEach(archive -> {
   109         initialArchives.forEach(archive -> {
   125             addPackagesInUnnamedModule(archive);
   110             addPackagesInUnnamedModule(archive);
   126             this.initialArchives.add(archive);
   111             this.initialArchives.add(archive);
   536                 otherModulePath.findAll().stream()
   521                 otherModulePath.findAll().stream()
   537                         .map(mref -> mref.descriptor().name())
   522                         .map(mref -> mref.descriptor().name())
   538                         .forEach(rootModules::add);
   523                         .forEach(rootModules::add);
   539             }
   524             }
   540 
   525 
   541             // add all modules to the root set for unnamed module or set explicitly
       
   542             boolean unnamed = !initialArchives.isEmpty() || !classPaths.isEmpty();
       
   543             if ((unnamed || tokens.contains(ALL_MODULE_PATH)) && appModulePath != null) {
       
   544                 appModulePath.findAll().stream()
       
   545                     .map(mref -> mref.descriptor().name())
       
   546                     .forEach(rootModules::add);
       
   547             }
       
   548 
       
   549             // no archive is specified for analysis
   526             // no archive is specified for analysis
   550             // add all system modules as root if --add-modules ALL-SYSTEM is specified
   527             // add all system modules as root if --add-modules ALL-SYSTEM is specified
   551             if (tokens.contains(ALL_SYSTEM) && rootModules.isEmpty() &&
   528             if (tokens.contains(ALL_SYSTEM) && rootModules.isEmpty() &&
   552                     initialArchives.isEmpty() && classPaths.isEmpty()) {
   529                     initialArchives.isEmpty() && classPaths.isEmpty()) {
   553                 systemModulePath.findAll()
   530                 systemModulePath.findAll()
   554                     .stream()
   531                     .stream()
   555                     .map(mref -> mref.descriptor().name())
   532                     .map(mref -> mref.descriptor().name())
   556                     .forEach(rootModules::add);
   533                     .forEach(rootModules::add);
   557             }
   534             }
   558 
   535 
   559             if (unnamed && !tokens.contains(ALL_DEFAULT)) {
   536             // add all modules on app module path as roots if ALL-MODULE-PATH is specified
   560                 tokens.add(ALL_SYSTEM);
   537             if ((tokens.contains(ALL_MODULE_PATH)) && appModulePath != null) {
   561             }
   538                 appModulePath.findAll().stream()
   562 
   539                     .map(mref -> mref.descriptor().name())
   563             return new JdepsConfiguration(systemModulePath,
   540                     .forEach(rootModules::add);
       
   541             }
       
   542 
       
   543 
       
   544             // build root set for module resolution
       
   545             Set<String> mods = new HashSet<>(rootModules);
       
   546             // if archives are specified for analysis, then consider as unnamed module
       
   547             boolean unnamed = !initialArchives.isEmpty() || !classPaths.isEmpty();
       
   548             if (tokens.contains(ALL_DEFAULT)) {
       
   549                 mods.addAll(systemModulePath.defaultSystemRoots());
       
   550             } else if (tokens.contains(ALL_SYSTEM) || unnamed) {
       
   551                 // resolve all system modules as unnamed module may reference any class
       
   552                 systemModulePath.findAll().stream()
       
   553                     .map(mref -> mref.descriptor().name())
       
   554                     .forEach(mods::add);
       
   555             }
       
   556             if (unnamed && appModulePath != null) {
       
   557                 // resolve all modules on module path as unnamed module may reference any class
       
   558                 appModulePath.findAll().stream()
       
   559                     .map(mref -> mref.descriptor().name())
       
   560                     .forEach(mods::add);
       
   561             }
       
   562 
       
   563             // resolve the module graph
       
   564             Configuration config = Configuration.empty().resolve(finder, ModuleFinder.of(), mods);
       
   565             return new JdepsConfiguration(config,
       
   566                                           systemModulePath,
   564                                           finder,
   567                                           finder,
   565                                           rootModules,
   568                                           rootModules,
   566                                           classPaths,
   569                                           classPaths,
   567                                           initialArchives,
   570                                           initialArchives,
   568                                           tokens,
       
   569                                           version);
   571                                           version);
   570         }
   572         }
   571 
   573 
   572         private static ModuleFinder createModulePathFinder(String mpaths) {
   574         private static ModuleFinder createModulePathFinder(String mpaths) {
   573             if (mpaths == null) {
   575             if (mpaths == null) {