134 private final Path mdir; 135 private final Set<String> modules = new HashSet<>(); 136 private String targetOsName; 137 138 /** 139 * Default image builder constructor. 140 * 141 * @param root The image root directory. 142 * @throws IOException 143 */ 144 public DefaultImageBuilder(Path root, Map<String, String> launchers) throws IOException { 145 this.root = Objects.requireNonNull(root); 146 this.launchers = Objects.requireNonNull(launchers); 147 this.mdir = root.resolve("lib"); 148 Files.createDirectories(mdir); 149 } 150 151 @Override 152 public void storeFiles(ResourcePool files) { 153 try { 154 // populate targetOsName field up-front because it's used elsewhere. 155 Optional<ResourcePoolModule> javaBase = files.moduleView().findModule("java.base"); 156 javaBase.ifPresent(mod -> { 157 // fill release information available from transformed "java.base" module! 158 ModuleDescriptor desc = mod.descriptor(); 159 desc.osName().ifPresent(s -> { 160 this.targetOsName = s; 161 }); 162 }); 163 164 if (this.targetOsName == null) { 165 throw new PluginException("ModuleTarget attribute is missing for java.base module"); 166 } 167 168 checkResourcePool(files); 169 170 Path bin = root.resolve(BIN_DIRNAME); 171 172 // write non-classes resource files to the image 173 files.entries() 174 .filter(f -> f.type() != ResourcePoolEntry.Type.CLASS_OR_RESOURCE) 175 .forEach(f -> { 176 try { 177 accept(f); 178 } catch (FileAlreadyExistsException e) { 179 // Should not happen! Duplicates checking already done! 180 throw new AssertionError("Duplicate entry!", e); 181 } catch (IOException ioExp) { 182 throw new UncheckedIOException(ioExp); 183 } | 134 private final Path mdir; 135 private final Set<String> modules = new HashSet<>(); 136 private String targetOsName; 137 138 /** 139 * Default image builder constructor. 140 * 141 * @param root The image root directory. 142 * @throws IOException 143 */ 144 public DefaultImageBuilder(Path root, Map<String, String> launchers) throws IOException { 145 this.root = Objects.requireNonNull(root); 146 this.launchers = Objects.requireNonNull(launchers); 147 this.mdir = root.resolve("lib"); 148 Files.createDirectories(mdir); 149 } 150 151 @Override 152 public void storeFiles(ResourcePool files) { 153 try { 154 this.targetOsName = files.moduleView(). 155 findModule("java.base").get().osName(); 156 if (this.targetOsName == null) { 157 throw new PluginException("ModuleTarget attribute is missing for java.base module"); 158 } 159 160 checkResourcePool(files); 161 162 Path bin = root.resolve(BIN_DIRNAME); 163 164 // write non-classes resource files to the image 165 files.entries() 166 .filter(f -> f.type() != ResourcePoolEntry.Type.CLASS_OR_RESOURCE) 167 .forEach(f -> { 168 try { 169 accept(f); 170 } catch (FileAlreadyExistsException e) { 171 // Should not happen! Duplicates checking already done! 172 throw new AssertionError("Duplicate entry!", e); 173 } catch (IOException ioExp) { 174 throw new UncheckedIOException(ioExp); 175 } |