< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java

Print this page




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.tools.jmod;
  27 
  28 import java.io.ByteArrayInputStream;
  29 import java.io.ByteArrayOutputStream;
  30 import java.io.File;
  31 import java.io.IOException;
  32 import java.io.InputStream;
  33 import java.io.OutputStream;
  34 import java.io.PrintWriter;
  35 import java.io.UncheckedIOException;
  36 import java.lang.module.Configuration;

  37 import java.lang.module.ModuleReader;
  38 import java.lang.module.ModuleReference;
  39 import java.lang.module.ModuleFinder;
  40 import java.lang.module.ModuleDescriptor;
  41 import java.lang.module.ModuleDescriptor.Exports;
  42 import java.lang.module.ModuleDescriptor.Opens;
  43 import java.lang.module.ModuleDescriptor.Provides;
  44 import java.lang.module.ModuleDescriptor.Requires;
  45 import java.lang.module.ModuleDescriptor.Version;
  46 import java.lang.module.ResolutionException;
  47 import java.lang.module.ResolvedModule;
  48 import java.net.URI;
  49 import java.nio.file.FileSystems;
  50 import java.nio.file.FileVisitOption;
  51 import java.nio.file.FileVisitResult;
  52 import java.nio.file.Files;
  53 import java.nio.file.InvalidPathException;
  54 import java.nio.file.Path;
  55 import java.nio.file.PathMatcher;
  56 import java.nio.file.Paths;


 834          */
 835         Hasher(String name, ModuleFinder finder) {
 836             // Determine the modules that matches the pattern {@code modulesToHash}
 837             Set<String> roots = finder.findAll().stream()
 838                 .map(mref -> mref.descriptor().name())
 839                 .filter(mn -> options.modulesToHash.matcher(mn).find())
 840                 .collect(Collectors.toSet());
 841 
 842             // use system module path unless it creates a JMOD file for
 843             // a module that is present in the system image e.g. upgradeable
 844             // module
 845             ModuleFinder system;
 846             if (name != null && ModuleFinder.ofSystem().find(name).isPresent()) {
 847                 system = ModuleFinder.of();
 848             } else {
 849                 system = ModuleFinder.ofSystem();
 850             }
 851             // get a resolved module graph
 852             Configuration config = null;
 853             try {
 854                 config = Configuration.empty().resolveRequires(system, finder, roots);
 855             } catch (ResolutionException e) {
 856                 throw new CommandException("err.module.resolution.fail", e.getMessage());
 857             }
 858 
 859             this.moduleName = name;
 860             this.configuration = config;
 861 
 862             // filter modules resolved from the system module finder
 863             this.modules = config.modules().stream()
 864                 .map(ResolvedModule::name)
 865                 .filter(mn -> roots.contains(mn) && !system.find(mn).isPresent())
 866                 .collect(Collectors.toSet());
 867 
 868             this.hashesBuilder = new ModuleHashesBuilder(config, modules);
 869         }
 870 
 871         /**
 872          * Returns a map of a module M to record hashes of the modules
 873          * that depend upon M directly or indirectly.
 874          *
 875          * For jmod hash command, the returned map contains one entry




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.tools.jmod;
  27 
  28 import java.io.ByteArrayInputStream;
  29 import java.io.ByteArrayOutputStream;
  30 import java.io.File;
  31 import java.io.IOException;
  32 import java.io.InputStream;
  33 import java.io.OutputStream;
  34 import java.io.PrintWriter;
  35 import java.io.UncheckedIOException;
  36 import java.lang.module.Configuration;
  37 import java.lang.module.FindException;
  38 import java.lang.module.ModuleReader;
  39 import java.lang.module.ModuleReference;
  40 import java.lang.module.ModuleFinder;
  41 import java.lang.module.ModuleDescriptor;
  42 import java.lang.module.ModuleDescriptor.Exports;
  43 import java.lang.module.ModuleDescriptor.Opens;
  44 import java.lang.module.ModuleDescriptor.Provides;
  45 import java.lang.module.ModuleDescriptor.Requires;
  46 import java.lang.module.ModuleDescriptor.Version;
  47 import java.lang.module.ResolutionException;
  48 import java.lang.module.ResolvedModule;
  49 import java.net.URI;
  50 import java.nio.file.FileSystems;
  51 import java.nio.file.FileVisitOption;
  52 import java.nio.file.FileVisitResult;
  53 import java.nio.file.Files;
  54 import java.nio.file.InvalidPathException;
  55 import java.nio.file.Path;
  56 import java.nio.file.PathMatcher;
  57 import java.nio.file.Paths;


 835          */
 836         Hasher(String name, ModuleFinder finder) {
 837             // Determine the modules that matches the pattern {@code modulesToHash}
 838             Set<String> roots = finder.findAll().stream()
 839                 .map(mref -> mref.descriptor().name())
 840                 .filter(mn -> options.modulesToHash.matcher(mn).find())
 841                 .collect(Collectors.toSet());
 842 
 843             // use system module path unless it creates a JMOD file for
 844             // a module that is present in the system image e.g. upgradeable
 845             // module
 846             ModuleFinder system;
 847             if (name != null && ModuleFinder.ofSystem().find(name).isPresent()) {
 848                 system = ModuleFinder.of();
 849             } else {
 850                 system = ModuleFinder.ofSystem();
 851             }
 852             // get a resolved module graph
 853             Configuration config = null;
 854             try {
 855                 config = Configuration.empty().resolve(system, finder, roots);
 856             } catch (FindException | ResolutionException e) {
 857                 throw new CommandException("err.module.resolution.fail", e.getMessage());
 858             }
 859 
 860             this.moduleName = name;
 861             this.configuration = config;
 862 
 863             // filter modules resolved from the system module finder
 864             this.modules = config.modules().stream()
 865                 .map(ResolvedModule::name)
 866                 .filter(mn -> roots.contains(mn) && !system.find(mn).isPresent())
 867                 .collect(Collectors.toSet());
 868 
 869             this.hashesBuilder = new ModuleHashesBuilder(config, modules);
 870         }
 871 
 872         /**
 873          * Returns a map of a module M to record hashes of the modules
 874          * that depend upon M directly or indirectly.
 875          *
 876          * For jmod hash command, the returned map contains one entry


< prev index next >