347 if (hasModule) { 348 if (!hasModulePath && !hasRuntimeImage && !hasAppImage) { 349 throw new PackagerException("ERR_MissingArgument", 350 "--runtime-image, --module-path or --app-image"); 351 } 352 } else { 353 if (!hasInput && !hasAppImage) { 354 throw new PackagerException("ERR_MissingArgument", 355 "--input or --app-image"); 356 } 357 } 358 } 359 } 360 361 // if bundling non-modular image, or installer without app-image 362 // then we need some resources and a main class 363 if (!hasModule && !hasAppImage && !runtimeInstaller) { 364 if (resources.isEmpty()) { 365 throw new PackagerException("ERR_MissingAppResources"); 366 } 367 if (!hasClass) { 368 throw new PackagerException("ERR_MissingArgument", 369 "--main-class"); 370 } 371 if (!hasMain) { 372 throw new PackagerException("ERR_MissingArgument", 373 "--main-jar"); 374 } 375 } 376 377 String name = (String)bundlerArguments.get( 378 Arguments.CLIOptions.NAME.getId()); 379 validateName(name, true); 380 381 // Validate app image if set 382 String appImage = (String)bundlerArguments.get( 383 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()); 384 if (appImage != null) { 385 File appImageDir = new File(appImage); 386 if (!appImageDir.exists() || appImageDir.list().length == 0) { 387 throw new PackagerException("ERR_AppImageNotExist", appImage); 388 } 389 } 390 438 } 439 440 String getTargetFormat() { 441 return targetFormat; 442 } 443 444 private String getArch() { 445 String arch = System.getProperty("os.arch").toLowerCase(); 446 447 if ("x86".equals(arch) || "i386".equals(arch) || "i486".equals(arch) 448 || "i586".equals(arch) || "i686".equals(arch)) { 449 arch = "x86"; 450 } else if ("x86_64".equals(arch) || "amd64".equals("arch")) { 451 arch = "x86_64"; 452 } 453 454 return arch; 455 } 456 457 static final Set<String> multi_args = new TreeSet<>(Arrays.asList( 458 StandardBundlerParam.JVM_OPTIONS.getID(), 459 StandardBundlerParam.ARGUMENTS.getID(), 460 StandardBundlerParam.MODULE_PATH.getID(), 461 StandardBundlerParam.ADD_MODULES.getID(), 462 StandardBundlerParam.LIMIT_MODULES.getID(), 463 StandardBundlerParam.FILE_ASSOCIATIONS.getID() 464 )); 465 466 @SuppressWarnings("unchecked") 467 public void addBundleArgument(String key, Object value) { 468 // special hack for multi-line arguments 469 if (multi_args.contains(key)) { 470 Object existingValue = bundlerArguments.get(key); 471 if (existingValue instanceof String && value instanceof String) { 472 bundlerArguments.put(key, existingValue + "\n\n" + value); 473 } else if (existingValue instanceof List && value instanceof List) { 474 ((List)existingValue).addAll((List)value); 475 } else if (existingValue instanceof Map && 476 value instanceof String && ((String)value).contains("=")) { 477 String[] mapValues = ((String)value).split("=", 2); 478 ((Map)existingValue).put(mapValues[0], mapValues[1]); 479 } else { 480 bundlerArguments.put(key, value); 481 } 482 } else { 483 bundlerArguments.put(key, value); 484 } 485 } 486 487 BundleParams getBundleParams() { 488 BundleParams bundleParams = new BundleParams(); 489 490 // construct app resources relative to output folder! 491 bundleParams.setAppResourcesList(resources); 492 493 bundleParams.setIdentifier(id); 494 495 bundleParams.setApplicationClass(applicationClass); 496 bundleParams.setAppVersion(version); 497 bundleParams.setType(bundleType); 498 bundleParams.setBundleFormat(targetFormat); 499 bundleParams.setVendor(vendor); 500 bundleParams.setEmail(email); 501 bundleParams.setInstalldirChooser(installdirChooser); 502 bundleParams.setCopyright(copyright); 503 bundleParams.setDescription(description); 504 505 bundleParams.setJvmargs(jvmargs); 506 bundleParams.setArguments(arguments); 507 508 if (addModules != null && !addModules.isEmpty()) { 509 bundleParams.setAddModules(addModules); 510 } 511 512 if (limitModules != null && !limitModules.isEmpty()) { 513 bundleParams.setLimitModules(limitModules); | 347 if (hasModule) { 348 if (!hasModulePath && !hasRuntimeImage && !hasAppImage) { 349 throw new PackagerException("ERR_MissingArgument", 350 "--runtime-image, --module-path or --app-image"); 351 } 352 } else { 353 if (!hasInput && !hasAppImage) { 354 throw new PackagerException("ERR_MissingArgument", 355 "--input or --app-image"); 356 } 357 } 358 } 359 } 360 361 // if bundling non-modular image, or installer without app-image 362 // then we need some resources and a main class 363 if (!hasModule && !hasAppImage && !runtimeInstaller) { 364 if (resources.isEmpty()) { 365 throw new PackagerException("ERR_MissingAppResources"); 366 } 367 if (!hasMain) { 368 throw new PackagerException("ERR_MissingArgument", 369 "--main-jar"); 370 } 371 } 372 373 String name = (String)bundlerArguments.get( 374 Arguments.CLIOptions.NAME.getId()); 375 validateName(name, true); 376 377 // Validate app image if set 378 String appImage = (String)bundlerArguments.get( 379 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()); 380 if (appImage != null) { 381 File appImageDir = new File(appImage); 382 if (!appImageDir.exists() || appImageDir.list().length == 0) { 383 throw new PackagerException("ERR_AppImageNotExist", appImage); 384 } 385 } 386 434 } 435 436 String getTargetFormat() { 437 return targetFormat; 438 } 439 440 private String getArch() { 441 String arch = System.getProperty("os.arch").toLowerCase(); 442 443 if ("x86".equals(arch) || "i386".equals(arch) || "i486".equals(arch) 444 || "i586".equals(arch) || "i686".equals(arch)) { 445 arch = "x86"; 446 } else if ("x86_64".equals(arch) || "amd64".equals("arch")) { 447 arch = "x86_64"; 448 } 449 450 return arch; 451 } 452 453 static final Set<String> multi_args = new TreeSet<>(Arrays.asList( 454 StandardBundlerParam.JAVA_OPTIONS.getID(), 455 StandardBundlerParam.ARGUMENTS.getID(), 456 StandardBundlerParam.MODULE_PATH.getID(), 457 StandardBundlerParam.ADD_MODULES.getID(), 458 StandardBundlerParam.LIMIT_MODULES.getID(), 459 StandardBundlerParam.FILE_ASSOCIATIONS.getID() 460 )); 461 462 @SuppressWarnings("unchecked") 463 public void addBundleArgument(String key, Object value) { 464 // special hack for multi-line arguments 465 if (multi_args.contains(key)) { 466 Object existingValue = bundlerArguments.get(key); 467 if (existingValue instanceof String && value instanceof String) { 468 String delim = "\n\n"; 469 if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) { 470 delim = File.pathSeparator; 471 } else if (key.equals( 472 StandardBundlerParam.ADD_MODULES.getID())) { 473 delim = ","; 474 } 475 bundlerArguments.put(key, existingValue + delim + value); 476 } else if (existingValue instanceof List && value instanceof List) { 477 ((List)existingValue).addAll((List)value); 478 } else if (existingValue instanceof Map && 479 value instanceof String && ((String)value).contains("=")) { 480 String[] mapValues = ((String)value).split("=", 2); 481 ((Map)existingValue).put(mapValues[0], mapValues[1]); 482 } else { 483 bundlerArguments.put(key, value); 484 } 485 } else { 486 bundlerArguments.put(key, value); 487 } 488 } 489 490 BundleParams getBundleParams() { 491 BundleParams bundleParams = new BundleParams(); 492 493 // construct app resources relative to output folder! 494 bundleParams.setAppResourcesList(resources); 495 496 bundleParams.setApplicationClass(applicationClass); 497 bundleParams.setAppVersion(version); 498 bundleParams.setType(bundleType); 499 bundleParams.setBundleFormat(targetFormat); 500 bundleParams.setVendor(vendor); 501 bundleParams.setEmail(email); 502 bundleParams.setInstalldirChooser(installdirChooser); 503 bundleParams.setCopyright(copyright); 504 bundleParams.setDescription(description); 505 506 bundleParams.setJvmargs(jvmargs); 507 bundleParams.setArguments(arguments); 508 509 if (addModules != null && !addModules.isEmpty()) { 510 bundleParams.setAddModules(addModules); 511 } 512 513 if (limitModules != null && !limitModules.isEmpty()) { 514 bundleParams.setLimitModules(limitModules); |