193 return result; |
195 return result; |
194 } |
196 } |
195 |
197 |
196 public static String getJDKVersion(Map<String, ? super Object> params) { |
198 public static String getJDKVersion(Map<String, ? super Object> params) { |
197 String result = ""; |
199 String result = ""; |
198 List<Path> modulePath = StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
200 List<Path> modulePath = |
199 Set<String> limitModules = StandardBundlerParam.LIMIT_MODULES.fetchFrom(params); |
201 StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
|
202 Set<String> limitModules = |
|
203 StandardBundlerParam.LIMIT_MODULES.fetchFrom(params); |
200 Path javaBasePath = findPathOfModule(modulePath, "java.base.jmod"); |
204 Path javaBasePath = findPathOfModule(modulePath, "java.base.jmod"); |
201 Set<String> addModules = getRedistributableModules(modulePath, |
205 Set<String> addModules = getRedistributableModules(modulePath, |
202 StandardBundlerParam.ADD_MODULES.fetchFrom(params), |
206 StandardBundlerParam.ADD_MODULES.fetchFrom(params), |
203 limitModules, JRE_MODULES_FILENAME); |
207 limitModules, JRE_MODULES_FILENAME); |
204 |
208 |
205 if (javaBasePath != null && javaBasePath.toFile().exists()) { |
209 if (javaBasePath != null && javaBasePath.toFile().exists()) { |
206 result = RedistributableModules.getModuleVersion(javaBasePath.toFile(), |
210 result = RedistributableModules.getModuleVersion( |
207 modulePath, addModules, limitModules); |
211 javaBasePath.toFile(), modulePath, addModules, limitModules); |
208 } |
212 } |
209 |
213 |
210 return result; |
214 return result; |
211 } |
215 } |
212 |
216 |
213 public static Path getJDKHome(Map<String, ? super Object> params) { |
217 public static Path getJDKHome(Map<String, ? super Object> params) { |
214 Path result = null; |
218 Path result = null; |
215 List<Path> modulePath = StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
219 List<Path> modulePath = |
|
220 StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
216 Path javaBasePath = findPathOfModule(modulePath, "java.base.jmod"); |
221 Path javaBasePath = findPathOfModule(modulePath, "java.base.jmod"); |
217 |
222 |
218 if (javaBasePath != null && javaBasePath.toFile().exists()) { |
223 if (javaBasePath != null && javaBasePath.toFile().exists()) { |
219 result = javaBasePath.getParent(); |
224 result = javaBasePath.getParent(); |
220 |
225 |
243 return result; |
250 return result; |
244 } |
251 } |
245 |
252 |
246 private static Set<String> getRedistributableModules(List<Path> modulePath, |
253 private static Set<String> getRedistributableModules(List<Path> modulePath, |
247 Set<String> addModules, Set<String> limitModules, String filename) { |
254 Set<String> addModules, Set<String> limitModules, String filename) { |
248 ModuleHelper moduleHelper = new ModuleHelper(modulePath, addModules, limitModules, filename); |
255 ModuleHelper moduleHelper = new ModuleHelper( |
|
256 modulePath, addModules, limitModules, filename); |
249 return removeInvalidModules(modulePath, moduleHelper.modules()); |
257 return removeInvalidModules(modulePath, moduleHelper.modules()); |
250 } |
258 } |
251 |
259 |
252 public static void execute(Map<String, ? super Object> params, |
260 public static void execute(Map<String, ? super Object> params, |
253 AbstractAppImageBuilder imageBuilder) throws IOException, Exception { |
261 AbstractAppImageBuilder imageBuilder) |
254 List<Path> modulePath = StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
262 throws IOException, Exception { |
255 Set<String> addModules = StandardBundlerParam.ADD_MODULES.fetchFrom(params); |
263 List<Path> modulePath = |
256 Set<String> limitModules = StandardBundlerParam.LIMIT_MODULES.fetchFrom(params); |
264 StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
257 boolean stripNativeCommands = StandardBundlerParam.STRIP_NATIVE_COMMANDS.fetchFrom(params); |
265 Set<String> addModules = |
|
266 StandardBundlerParam.ADD_MODULES.fetchFrom(params); |
|
267 Set<String> limitModules = |
|
268 StandardBundlerParam.LIMIT_MODULES.fetchFrom(params); |
|
269 boolean stripNativeCommands = |
|
270 StandardBundlerParam.STRIP_NATIVE_COMMANDS.fetchFrom(params); |
258 Path outputDir = imageBuilder.getRoot(); |
271 Path outputDir = imageBuilder.getRoot(); |
259 String excludeFileList = imageBuilder.getExcludeFileList(); |
272 String excludeFileList = imageBuilder.getExcludeFileList(); |
260 File mainJar = getMainJar(params); |
273 File mainJar = getMainJar(params); |
261 Module.ModuleType mainJarType = Module.ModuleType.Unknown; |
274 Module.ModuleType mainJarType = Module.ModuleType.Unknown; |
262 |
275 |
263 if (mainJar != null) { |
276 if (mainJar != null) { |
264 mainJarType = new Module(mainJar).getModuleType(); |
277 mainJarType = new Module(mainJar).getModuleType(); |
265 } else if (mainJar == null && StandardBundlerParam.MODULE.fetchFrom(params) == null) { |
278 } else if (mainJar == null && |
|
279 StandardBundlerParam.MODULE.fetchFrom(params) == null) { |
266 // user specified only main class, all jars will be on the classpath |
280 // user specified only main class, all jars will be on the classpath |
267 mainJarType = Module.ModuleType.UnnamedJar; |
281 mainJarType = Module.ModuleType.UnnamedJar; |
268 } |
282 } |
269 |
283 |
270 // Modules |
284 // Modules |
271 |
285 |
272 // The default for an unnamed jar is ALL_DEFAULT with the |
286 // The default for an unnamed jar is ALL_DEFAULT with the |
273 // non-redistributable modules removed. |
287 // non-redistributable modules removed. |
274 if (mainJarType == Module.ModuleType.UnnamedJar) { |
288 if (mainJarType == Module.ModuleType.UnnamedJar) { |
275 addModules.add(ModuleHelper.ALL_RUNTIME); |
289 addModules.add(ModuleHelper.ALL_RUNTIME); |
276 } else if (mainJarType == Module.ModuleType.Unknown || mainJarType == Module.ModuleType.ModularJar) { |
290 } else if (mainJarType == Module.ModuleType.Unknown || |
|
291 mainJarType == Module.ModuleType.ModularJar) { |
277 String mainModule = getMainModule(params); |
292 String mainModule = getMainModule(params); |
278 addModules.add(mainModule); |
293 addModules.add(mainModule); |
279 |
294 |
280 // Error if any of the srcfiles are modular jars. |
295 // Error if any of the srcfiles are modular jars. |
281 Set<String> modularJars = getResourceFileJarList(params, Module.JarType.ModularJar); |
296 Set<String> modularJars = |
|
297 getResourceFileJarList(params, Module.JarType.ModularJar); |
282 |
298 |
283 if (!modularJars.isEmpty()) { |
299 if (!modularJars.isEmpty()) { |
284 throw new Exception(MessageFormat.format(I18N.getString( |
300 throw new Exception(MessageFormat.format(I18N.getString( |
285 "error.srcfiles.contain.modules"), modularJars.toString())); |
301 "error.srcfiles.contain.modules"), |
|
302 modularJars.toString())); |
286 } |
303 } |
287 } |
304 } |
288 |
305 |
289 Set<String> redistModules = getRedistributableModules( |
306 Set<String> redistModules = getRedistributableModules( |
290 modulePath, addModules, limitModules, JRE_MODULES_FILENAME); |
307 modulePath, addModules, limitModules, JRE_MODULES_FILENAME); |
291 addModules.addAll(redistModules); |
308 addModules.addAll(redistModules); |
292 |
309 |
293 if (imageBuilder.getPlatformSpecificModulesFile() != null) { |
310 if (imageBuilder.getPlatformSpecificModulesFile() != null) { |
294 Set<String> platformModules = RedistributableModules.getRedistributableModules( |
311 Set<String> platformModules = |
|
312 RedistributableModules.getRedistributableModules( |
295 modulePath, imageBuilder.getPlatformSpecificModulesFile()); |
313 modulePath, imageBuilder.getPlatformSpecificModulesFile()); |
296 addModules.addAll(platformModules); |
314 addModules.addAll(platformModules); |
297 } |
315 } |
298 |
316 |
299 Log.info(MessageFormat.format(I18N.getString("message.modules"), addModules.toString())); |
317 Log.info(MessageFormat.format( |
|
318 I18N.getString("message.modules"), addModules.toString())); |
300 |
319 |
301 if (StandardBundlerParam.ECHO_MODE.fetchFrom(params)) { |
320 if (StandardBundlerParam.ECHO_MODE.fetchFrom(params)) { |
302 Log.info("\nECHO-MODE: Running jlink [ "); |
321 Log.info("\nECHO-MODE: Running jlink [ "); |
303 Log.info("--output = " + outputDir.toString()); |
322 Log.info("--output = " + outputDir.toString()); |
304 Log.info("--module-path = " + modulePath.toString()); |
323 Log.info("--module-path = " + modulePath.toString()); |
321 appRuntimeBuilder.build(); |
340 appRuntimeBuilder.build(); |
322 imageBuilder.prepareApplicationFiles(); |
341 imageBuilder.prepareApplicationFiles(); |
323 } |
342 } |
324 |
343 |
325 public static void generateServerJre(Map<String, ? super Object> params, |
344 public static void generateServerJre(Map<String, ? super Object> params, |
326 AbstractAppImageBuilder imageBuilder) throws IOException, Exception { |
345 AbstractAppImageBuilder imageBuilder) |
327 List<Path> modulePath = StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
346 throws IOException, Exception { |
328 Set<String> addModules = StandardBundlerParam.ADD_MODULES.fetchFrom(params); |
347 List<Path> modulePath = |
329 Set<String> limitModules = StandardBundlerParam.LIMIT_MODULES.fetchFrom(params); |
348 StandardBundlerParam.MODULE_PATH.fetchFrom(params); |
330 boolean stripNativeCommands = StandardBundlerParam.STRIP_NATIVE_COMMANDS.fetchFrom(params); |
349 Set<String> addModules = |
|
350 StandardBundlerParam.ADD_MODULES.fetchFrom(params); |
|
351 Set<String> limitModules = |
|
352 StandardBundlerParam.LIMIT_MODULES.fetchFrom(params); |
|
353 boolean stripNativeCommands = |
|
354 StandardBundlerParam.STRIP_NATIVE_COMMANDS.fetchFrom(params); |
331 Path outputDir = imageBuilder.getRoot(); |
355 Path outputDir = imageBuilder.getRoot(); |
332 addModules.add(ModuleHelper.ALL_RUNTIME); |
356 addModules.add(ModuleHelper.ALL_RUNTIME); |
333 Set<String> redistModules = getRedistributableModules( |
357 Set<String> redistModules = getRedistributableModules(modulePath, |
334 modulePath, addModules, limitModules, SERVER_JRE_MODULES_FILENAME); |
358 addModules, limitModules, SERVER_JRE_MODULES_FILENAME); |
335 addModules.addAll(redistModules); |
359 addModules.addAll(redistModules); |
336 |
360 |
337 if (imageBuilder.getPlatformSpecificModulesFile() != null) { |
361 if (imageBuilder.getPlatformSpecificModulesFile() != null) { |
338 Set<String> platformModules = RedistributableModules.getRedistributableModules( |
362 Set<String> platformModules = |
339 modulePath, imageBuilder.getPlatformSpecificModulesFile()); |
363 RedistributableModules.getRedistributableModules( |
|
364 modulePath, imageBuilder.getPlatformSpecificModulesFile()); |
340 addModules.addAll(platformModules); |
365 addModules.addAll(platformModules); |
341 } |
366 } |
342 |
367 |
343 Log.info(MessageFormat.format(I18N.getString("message.modules"), addModules.toString())); |
368 Log.info(MessageFormat.format( |
|
369 I18N.getString("message.modules"), addModules.toString())); |
344 |
370 |
345 if (StandardBundlerParam.ECHO_MODE.fetchFrom(params)) { |
371 if (StandardBundlerParam.ECHO_MODE.fetchFrom(params)) { |
346 Log.info("\nECHO-MODE: Running jlink [ "); |
372 Log.info("\nECHO-MODE: Running jlink [ "); |
347 Log.info("--output = " + outputDir.toString()); |
373 Log.info("--output = " + outputDir.toString()); |
348 Log.info("--module-path = " + modulePath.toString()); |
374 Log.info("--module-path = " + modulePath.toString()); |
419 } |
449 } |
420 |
450 |
421 return files; |
451 return files; |
422 } |
452 } |
423 |
453 |
424 private static Set<String> removeInvalidModules(List<Path> modulePath, Set<String> modules) { |
454 private static Set<String> removeInvalidModules( |
|
455 List<Path> modulePath, Set<String> modules) { |
425 Set<String> result = new LinkedHashSet(); |
456 Set<String> result = new LinkedHashSet(); |
426 ModuleManager mm = new ModuleManager(modulePath); |
457 ModuleManager mm = new ModuleManager(modulePath); |
427 List<Module> lmodules = mm.getModules(EnumSet.of(ModuleManager.SearchType.ModularJar, |
458 List<Module> lmodules = |
428 ModuleManager.SearchType.Jmod, |
459 mm.getModules(EnumSet.of(ModuleManager.SearchType.ModularJar, |
429 ModuleManager.SearchType.ExplodedModule)); |
460 ModuleManager.SearchType.Jmod, |
|
461 ModuleManager.SearchType.ExplodedModule)); |
430 |
462 |
431 HashMap<String, Module> validModules = new HashMap<>(); |
463 HashMap<String, Module> validModules = new HashMap<>(); |
432 |
464 |
433 for (Module module : lmodules) { |
465 for (Module module : lmodules) { |
434 validModules.put(module.getModuleName(), module); |
466 validModules.put(module.getModuleName(), module); |