80 return m; 81 } 82 } 83 } 84 return null; 85 } 86 87 /** 88 * Returns JAR files in $java.home/lib. This is for transition until 89 * all components are linked into jimage. 90 */ 91 static List<Archive> getJarFiles() throws IOException { 92 Path home = Paths.get(System.getProperty("java.home"), "lib"); 93 return Files.find(home, 1, (Path p, BasicFileAttributes attr) 94 -> p.getFileName().toString().endsWith(".jar")) 95 .map(Archive::getInstance) 96 .collect(Collectors.toList()); 97 } 98 99 static class ImageHelper { 100 static ImageHelper getInstance(Path mpath) throws IOException { 101 if (mpath != null) { 102 return new ImageHelper(mpath); 103 } 104 Path home = Paths.get(System.getProperty("java.home")); 105 Path mlib = home.resolve("lib").resolve("modules"); 106 if (Files.isDirectory(mlib)) { 107 // jimage 108 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); 109 return new ImageHelper(fs, fs.getPath("/")); 110 } else { 111 // exploded modules 112 mlib = home.resolve("modules"); 113 if (!Files.isDirectory(mlib)) { 114 throw new InternalError(home + " not a modular image"); 115 } 116 return new ImageHelper(mlib); 117 } 118 } 119 120 private final FileSystem fs; 121 private final Path mpath; 122 123 ImageHelper(Path path) throws IOException { 124 this(FileSystems.getDefault(), path); 125 } 126 127 ImageHelper(FileSystem fs, Path path) throws IOException { 128 this.fs = fs; 129 this.mpath = path; 130 } 131 132 /** 133 * Returns a ModuleClassReader that only reads classes for the given modulename. 134 */ 135 public ModuleClassReader getModuleClassReader(String modulename) 136 throws IOException | 80 return m; 81 } 82 } 83 } 84 return null; 85 } 86 87 /** 88 * Returns JAR files in $java.home/lib. This is for transition until 89 * all components are linked into jimage. 90 */ 91 static List<Archive> getJarFiles() throws IOException { 92 Path home = Paths.get(System.getProperty("java.home"), "lib"); 93 return Files.find(home, 1, (Path p, BasicFileAttributes attr) 94 -> p.getFileName().toString().endsWith(".jar")) 95 .map(Archive::getInstance) 96 .collect(Collectors.toList()); 97 } 98 99 static class ImageHelper { 100 private static boolean isJrtAvailable() { 101 try { 102 FileSystems.getFileSystem(URI.create("jrt:/")); 103 return true; 104 } catch (ProviderNotFoundException | FileSystemNotFoundException e) { 105 return false; 106 } 107 } 108 109 static ImageHelper getInstance(Path mpath) throws IOException { 110 if (mpath != null) { 111 return new ImageHelper(mpath); 112 } 113 114 if (isJrtAvailable()) { 115 // jrt file system 116 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); 117 return new ImageHelper(fs, fs.getPath("/modules")); 118 } else { 119 // exploded modules 120 String home = System.getProperty("java.home"); 121 Path exploded = Paths.get(home, "modules"); 122 if (!Files.isDirectory(exploded)) { 123 throw new InternalError(home + " not a modular image"); 124 } 125 return new ImageHelper(exploded); 126 } 127 } 128 129 private final FileSystem fs; 130 private final Path mpath; 131 132 ImageHelper(Path path) throws IOException { 133 this(FileSystems.getDefault(), path); 134 } 135 136 ImageHelper(FileSystem fs, Path path) throws IOException { 137 this.fs = fs; 138 this.mpath = path; 139 } 140 141 /** 142 * Returns a ModuleClassReader that only reads classes for the given modulename. 143 */ 144 public ModuleClassReader getModuleClassReader(String modulename) 145 throws IOException |