< prev index next >

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

Print this page




  66 import java.util.stream.Stream;
  67 
  68 public class JdepsConfiguration implements AutoCloseable {
  69     // the token for "all modules on the module path"
  70     public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
  71     public static final String ALL_DEFAULT = "ALL-DEFAULT";
  72     public static final String ALL_SYSTEM = "ALL-SYSTEM";
  73 
  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,
  94                                Set<String> tokens,
  95                                Runtime.Version version)
  96         throws IOException
  97     {
  98         trace("root: %s%n", roots);
  99 
 100         this.system = systemModulePath;
 101         this.finder = finder;
 102         this.version = version;
 103 
 104         // build root set for resolution
 105         Set<String> mods = new HashSet<>(roots);
 106         if (tokens.contains(ALL_SYSTEM)) {
 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 
 123         // packages in unnamed module
 124         initialArchives.forEach(archive -> {
 125             addPackagesInUnnamedModule(archive);
 126             this.initialArchives.add(archive);
 127         });
 128 
 129         // classpath archives
 130         for (Path p : classpaths) {
 131             if (Files.exists(p)) {
 132                 Archive archive = Archive.getInstance(p, version);
 133                 addPackagesInUnnamedModule(archive);
 134                 classpathArchives.add(archive);
 135             }
 136         }
 137 
 138         // all roots specified in --add-modules or -m are included
 139         // as the initial set for analysis.


 521         }
 522 
 523         public JdepsConfiguration build() throws  IOException {
 524             ModuleFinder finder = systemModulePath;
 525             if (upgradeModulePath != null) {
 526                 finder = ModuleFinder.compose(upgradeModulePath, systemModulePath);
 527             }
 528             if (appModulePath != null) {
 529                 finder = ModuleFinder.compose(finder, appModulePath);
 530             }
 531             if (!paths.isEmpty()) {
 532                 ModuleFinder otherModulePath = ModuleFinder.of(paths.toArray(new Path[0]));
 533 
 534                 finder = ModuleFinder.compose(finder, otherModulePath);
 535                 // add modules specified on command-line (convenience) as root set
 536                 otherModulePath.findAll().stream()
 537                         .map(mref -> mref.descriptor().name())
 538                         .forEach(rootModules::add);
 539             }
 540 
 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
 550             // add all system modules as root if --add-modules ALL-SYSTEM is specified
 551             if (tokens.contains(ALL_SYSTEM) && rootModules.isEmpty() &&
 552                     initialArchives.isEmpty() && classPaths.isEmpty()) {
 553                 systemModulePath.findAll()
 554                     .stream()
 555                     .map(mref -> mref.descriptor().name())
 556                     .forEach(rootModules::add);
 557             }
 558 
 559             if (unnamed && !tokens.contains(ALL_DEFAULT)) {
 560                 tokens.add(ALL_SYSTEM);























 561             }
 562 
 563             return new JdepsConfiguration(systemModulePath,



 564                                           finder,
 565                                           rootModules,
 566                                           classPaths,
 567                                           initialArchives,
 568                                           tokens,
 569                                           version);
 570         }
 571 
 572         private static ModuleFinder createModulePathFinder(String mpaths) {
 573             if (mpaths == null) {
 574                 return null;
 575             } else {
 576                 String[] dirs = mpaths.split(File.pathSeparator);
 577                 Path[] paths = new Path[dirs.length];
 578                 int i = 0;
 579                 for (String dir : dirs) {
 580                     paths[i++] = Paths.get(dir);
 581                 }
 582                 return ModuleFinder.of(paths);
 583             }
 584         }
 585 
 586         /*
 587          * Returns the list of Archive specified in cpaths and not included
 588          * initialArchives




  66 import java.util.stream.Stream;
  67 
  68 public class JdepsConfiguration implements AutoCloseable {
  69     // the token for "all modules on the module path"
  70     public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
  71     public static final String ALL_DEFAULT = "ALL-DEFAULT";
  72     public static final String ALL_SYSTEM = "ALL-SYSTEM";
  73 
  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 Runtime.Version version;
  87 
  88     private JdepsConfiguration(Configuration config,
  89                                SystemModuleFinder systemModulePath,
  90                                ModuleFinder finder,
  91                                Set<String> roots,
  92                                List<Path> classpaths,
  93                                List<Archive> initialArchives,

  94                                Runtime.Version version)
  95         throws IOException
  96     {
  97         trace("root: %s%n", roots);

  98         this.system = systemModulePath;
  99         this.finder = finder;
 100         this.version = version;
 101 
 102         config.modules().stream()















 103               .map(ResolvedModule::reference)
 104               .forEach(this::addModuleReference);
 105 
 106         // packages in unnamed module
 107         initialArchives.forEach(archive -> {
 108             addPackagesInUnnamedModule(archive);
 109             this.initialArchives.add(archive);
 110         });
 111 
 112         // classpath archives
 113         for (Path p : classpaths) {
 114             if (Files.exists(p)) {
 115                 Archive archive = Archive.getInstance(p, version);
 116                 addPackagesInUnnamedModule(archive);
 117                 classpathArchives.add(archive);
 118             }
 119         }
 120 
 121         // all roots specified in --add-modules or -m are included
 122         // as the initial set for analysis.


 504         }
 505 
 506         public JdepsConfiguration build() throws  IOException {
 507             ModuleFinder finder = systemModulePath;
 508             if (upgradeModulePath != null) {
 509                 finder = ModuleFinder.compose(upgradeModulePath, systemModulePath);
 510             }
 511             if (appModulePath != null) {
 512                 finder = ModuleFinder.compose(finder, appModulePath);
 513             }
 514             if (!paths.isEmpty()) {
 515                 ModuleFinder otherModulePath = ModuleFinder.of(paths.toArray(new Path[0]));
 516 
 517                 finder = ModuleFinder.compose(finder, otherModulePath);
 518                 // add modules specified on command-line (convenience) as root set
 519                 otherModulePath.findAll().stream()
 520                         .map(mref -> mref.descriptor().name())
 521                         .forEach(rootModules::add);
 522             }
 523 








 524             // no archive is specified for analysis
 525             // add all system modules as root if --add-modules ALL-SYSTEM is specified
 526             if (tokens.contains(ALL_SYSTEM) && rootModules.isEmpty() &&
 527                     initialArchives.isEmpty() && classPaths.isEmpty()) {
 528                 systemModulePath.findAll()
 529                     .stream()
 530                     .map(mref -> mref.descriptor().name())
 531                     .forEach(rootModules::add);
 532             }
 533 
 534             // add all modules on app module path as roots if ALL-MODULE-PATH is specified
 535             if ((tokens.contains(ALL_MODULE_PATH)) && appModulePath != null) {
 536                 appModulePath.findAll().stream()
 537                     .map(mref -> mref.descriptor().name())
 538                     .forEach(rootModules::add);
 539             }
 540 
 541 
 542             // build root set for module resolution
 543             Set<String> mods = new HashSet<>(rootModules);
 544             // if archives are specified for analysis, then consider as unnamed module
 545             boolean unnamed = !initialArchives.isEmpty() || !classPaths.isEmpty();
 546             if (tokens.contains(ALL_DEFAULT)) {
 547                 mods.addAll(systemModulePath.defaultSystemRoots());
 548             } else if (tokens.contains(ALL_SYSTEM) || unnamed) {
 549                 // resolve all system modules as unnamed module may reference any class
 550                 systemModulePath.findAll().stream()
 551                     .map(mref -> mref.descriptor().name())
 552                     .forEach(mods::add);
 553             }
 554             if (unnamed && appModulePath != null) {
 555                 // resolve all modules on module path as unnamed module may reference any class
 556                 appModulePath.findAll().stream()
 557                     .map(mref -> mref.descriptor().name())
 558                     .forEach(mods::add);
 559             }
 560 
 561             // resolve the module graph
 562             Configuration config = Configuration.empty().resolve(finder, ModuleFinder.of(), mods);
 563             return new JdepsConfiguration(config,
 564                                           systemModulePath,
 565                                           finder,
 566                                           rootModules,
 567                                           classPaths,
 568                                           initialArchives,

 569                                           version);
 570         }
 571 
 572         private static ModuleFinder createModulePathFinder(String mpaths) {
 573             if (mpaths == null) {
 574                 return null;
 575             } else {
 576                 String[] dirs = mpaths.split(File.pathSeparator);
 577                 Path[] paths = new Path[dirs.length];
 578                 int i = 0;
 579                 for (String dir : dirs) {
 580                     paths[i++] = Paths.get(dir);
 581                 }
 582                 return ModuleFinder.of(paths);
 583             }
 584         }
 585 
 586         /*
 587          * Returns the list of Archive specified in cpaths and not included
 588          * initialArchives


< prev index next >