206 String path = "/" + module + "/module-info.class";
207 ModuleData res = imageContent.get(path);
208 if (res == null) {
209 throw new IOException("module-info.class not found for " + module + " module");
210 }
211 Optional<String> mainClass;
212 ByteArrayInputStream stream = new ByteArrayInputStream(res.getBytes());
213 mainClass = ModuleDescriptor.read(stream).mainClass();
214 if (mainClass.isPresent()) {
215 Path cmd = root.resolve("bin").resolve(module);
216 if (!Files.exists(cmd)) {
217 StringBuilder sb = new StringBuilder();
218 sb.append("#!/bin/sh")
219 .append("\n");
220 sb.append("JLINK_VM_OPTIONS=")
221 .append("\n");
222 sb.append("DIR=`dirname $0`")
223 .append("\n");
224 sb.append("$DIR/java $JLINK_VM_OPTIONS -m ")
225 .append(module).append('/')
226 .append(mainClass.get())
227 .append(" $@\n");
228
229 try (BufferedWriter writer = Files.newBufferedWriter(cmd,
230 StandardCharsets.ISO_8859_1,
231 StandardOpenOption.CREATE_NEW)) {
232 writer.write(sb.toString());
233 }
234 if (Files.getFileStore(root.resolve("bin"))
235 .supportsFileAttributeView(PosixFileAttributeView.class)) {
236 setExecutable(cmd);
237 }
238 }
239 }
240 }
241 }
242
243 @Override
244 public DataOutputStream getJImageOutputStream() {
245 try {
246 Path jimageFile = mdir.resolve(BasicImageWriter.MODULES_IMAGE_NAME);
|
206 String path = "/" + module + "/module-info.class";
207 ModuleData res = imageContent.get(path);
208 if (res == null) {
209 throw new IOException("module-info.class not found for " + module + " module");
210 }
211 Optional<String> mainClass;
212 ByteArrayInputStream stream = new ByteArrayInputStream(res.getBytes());
213 mainClass = ModuleDescriptor.read(stream).mainClass();
214 if (mainClass.isPresent()) {
215 Path cmd = root.resolve("bin").resolve(module);
216 if (!Files.exists(cmd)) {
217 StringBuilder sb = new StringBuilder();
218 sb.append("#!/bin/sh")
219 .append("\n");
220 sb.append("JLINK_VM_OPTIONS=")
221 .append("\n");
222 sb.append("DIR=`dirname $0`")
223 .append("\n");
224 sb.append("$DIR/java $JLINK_VM_OPTIONS -m ")
225 .append(module).append('/')
226 .append(mainClass.getWhenPresent())
227 .append(" $@\n");
228
229 try (BufferedWriter writer = Files.newBufferedWriter(cmd,
230 StandardCharsets.ISO_8859_1,
231 StandardOpenOption.CREATE_NEW)) {
232 writer.write(sb.toString());
233 }
234 if (Files.getFileStore(root.resolve("bin"))
235 .supportsFileAttributeView(PosixFileAttributeView.class)) {
236 setExecutable(cmd);
237 }
238 }
239 }
240 }
241 }
242
243 @Override
244 public DataOutputStream getJImageOutputStream() {
245 try {
246 Path jimageFile = mdir.resolve(BasicImageWriter.MODULES_IMAGE_NAME);
|