40 import java.util.Map; 41 import java.util.Set; 42 import java.util.TreeMap; 43 import java.util.TreeSet; 44 45 /** 46 * DeployParams 47 * 48 * This class is generated and used in Arguments.processArguments() as 49 * intermediate step in generating the BundleParams and ultimately the Bundles 50 */ 51 public class DeployParams { 52 53 final List<RelativeFileSet> resources = new ArrayList<>(); 54 55 String id; 56 String title; 57 String vendor; 58 String email; 59 String description; 60 String category; 61 String licenseType; 62 String copyright; 63 String version; 64 Boolean systemWide; 65 Boolean serviceHint; 66 Boolean signBundle; 67 Boolean installdirChooser; 68 69 String applicationClass; 70 71 List<Param> params; 72 List<String> arguments; //unnamed arguments 73 74 // Java 9 modules support 75 String addModules = null; 76 String limitModules = null; 77 Boolean stripNativeCommands = null; 78 String modulePath = null; 79 String module = null; 80 String debugPort = null; 81 82 File outdir = null; 83 84 String appId = null; 85 86 // list of jvm args 87 // (in theory string can contain spaces and need to be escaped 88 List<String> jvmargs = new LinkedList<>(); 89 90 // raw arguments to the bundler 91 Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>(); 92 93 void setCategory(String category) { 94 this.category = category; 95 } 96 97 void setLicenseType(String licenseType) { 98 this.licenseType = licenseType; 99 } 100 101 void setCopyright(String copyright) { 102 this.copyright = copyright; 103 } 104 105 void setVersion(String version) { 106 this.version = version; 107 } 108 109 void setSystemWide(Boolean systemWide) { 110 this.systemWide = systemWide; 111 } 112 113 void setInstalldirChooser(Boolean installdirChooser) { 114 this.installdirChooser = installdirChooser; 115 } 116 151 limitModules += "," + value; 152 } 153 } 154 155 String getModulePath() { 156 return this.modulePath; 157 } 158 159 void setModulePath(String value) { 160 this.modulePath = value; 161 } 162 163 void setModule(String value) { 164 this.module = value; 165 } 166 167 void setDebug(String value) { 168 this.debugPort = value; 169 } 170 171 void setStripNativeCommands(boolean value) { 172 this.stripNativeCommands = value; 173 } 174 175 void setDescription(String description) { 176 this.description = description; 177 } 178 179 public void setAppId(String id) { 180 appId = id; 181 } 182 183 void setParams(List<Param> params) { 184 this.params = params; 185 } 186 187 void setTitle(String title) { 188 this.title = title; 189 } 190 191 void setVendor(String vendor) { 192 this.vendor = vendor; 193 } 194 322 // Accept anything else including special chars like copyright 323 // symbols. Note: space will be included by ASCII check above, 324 // but other whitespace like tabs or new line will be rejected. 325 if (Character.isISOControl(a) || 326 Character.isWhitespace(a)) { 327 throw new PackagerException(exceptionKey, s); 328 } 329 } else if (a == '"' || a == '%') { 330 throw new PackagerException(exceptionKey, s); 331 } 332 } 333 } 334 335 public void validate() throws PackagerException { 336 if (outdir == null) { 337 throw new PackagerException("ERR_MissingArgument", "--output"); 338 } 339 340 boolean hasModule = (bundlerArguments.get( 341 Arguments.CLIOptions.MODULE.getId()) != null); 342 boolean hasImage = (bundlerArguments.get( 343 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null); 344 boolean hasClass = (bundlerArguments.get( 345 Arguments.CLIOptions.APPCLASS.getId()) != null); 346 boolean hasMain = (bundlerArguments.get( 347 Arguments.CLIOptions.MAIN_JAR.getId()) != null); 348 boolean hasRuntimeImage = (bundlerArguments.get( 349 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null); 350 boolean hasInput = (bundlerArguments.get( 351 Arguments.CLIOptions.INPUT.getId()) != null); 352 boolean hasModulePath = (bundlerArguments.get( 353 Arguments.CLIOptions.MODULE_PATH.getId()) != null); 354 boolean hasAppImage = (bundlerArguments.get( 355 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null); 356 boolean runtimeInstaller = (bundlerArguments.get( 357 Arguments.CLIOptions.RUNTIME_INSTALLER.getId()) != null); 358 359 if (getBundleType() == BundlerType.IMAGE) { 360 // Module application requires --runtime-image or --module-path 361 if (hasModule) { 362 if (!hasModulePath && !hasRuntimeImage) { 363 throw new PackagerException("ERR_MissingArgument", 364 "--runtime-image or --module-path"); 365 } 366 } else { 367 if (!hasInput) { 368 throw new PackagerException( 369 "ERR_MissingArgument", "--input"); 370 } 371 } 372 } else if (getBundleType() == BundlerType.INSTALLER) { 373 if (!runtimeInstaller) { 374 if (hasModule) { 375 if (!hasModulePath && !hasRuntimeImage && !hasAppImage) { 376 throw new PackagerException("ERR_MissingArgument", 377 "--runtime-image, --module-path or --app-image"); 378 } 379 } else { 380 if (!hasInput && !hasAppImage) { 381 throw new PackagerException("ERR_MissingArgument", 382 "--input or --app-image"); 383 } 384 } 385 } 386 } 387 388 // if bundling non-modular image, or installer without app-image 389 // then we need some resources and a main class 390 if (!hasModule && !hasImage && !runtimeInstaller) { 391 if (resources.isEmpty()) { 392 throw new PackagerException("ERR_MissingAppResources"); 393 } 394 if (!hasClass) { 395 throw new PackagerException("ERR_MissingArgument", 396 "--main-class"); 397 } 398 if (!hasMain) { 399 throw new PackagerException("ERR_MissingArgument", 400 "--main-jar"); 401 } 402 } 403 404 String name = (String)bundlerArguments.get( 405 Arguments.CLIOptions.NAME.getId()); 406 validateName(name, true); 407 408 // Validate app image if set 409 String appImage = (String)bundlerArguments.get( 410 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()); 411 if (appImage != null) { 412 File appImageDir = new File(appImage); 413 if (!appImageDir.exists() || appImageDir.list().length == 0) { 414 throw new PackagerException("ERR_AppImageNotExist", appImage); 415 } 416 } 417 418 // Validate build-root 419 String root = (String)bundlerArguments.get( 420 Arguments.CLIOptions.BUILD_ROOT.getId()); 421 if (root != null) { 422 String [] contents = (new File(root)).list(); 423 424 if (contents != null && contents.length > 0) { 425 throw new PackagerException("ERR_BuildRootInvalid", root); 426 } 427 } 428 429 // Validate license file if set 430 String license = (String)bundlerArguments.get( 431 Arguments.CLIOptions.LICENSE_FILE.getId()); 432 if (license != null) { 433 File licenseFile = new File(license); 434 if (!licenseFile.exists()) { 435 throw new PackagerException("ERR_LicenseFileNotExit"); 436 } 437 } 438 } 439 440 boolean validateForBundle() { 510 bundlerArguments.put(key, value); 511 } 512 } 513 514 BundleParams getBundleParams() { 515 BundleParams bundleParams = new BundleParams(); 516 517 // construct app resources relative to output folder! 518 bundleParams.setAppResourcesList(resources); 519 520 bundleParams.setIdentifier(id); 521 522 bundleParams.setApplicationClass(applicationClass); 523 bundleParams.setAppVersion(version); 524 bundleParams.setType(bundleType); 525 bundleParams.setBundleFormat(targetFormat); 526 bundleParams.setVendor(vendor); 527 bundleParams.setEmail(email); 528 bundleParams.setInstalldirChooser(installdirChooser); 529 bundleParams.setCopyright(copyright); 530 bundleParams.setApplicationCategory(category); 531 bundleParams.setDescription(description); 532 bundleParams.setTitle(title); 533 534 bundleParams.setJvmargs(jvmargs); 535 bundleParams.setArguments(arguments); 536 537 if (addModules != null && !addModules.isEmpty()) { 538 bundleParams.setAddModules(addModules); 539 } 540 541 if (limitModules != null && !limitModules.isEmpty()) { 542 bundleParams.setLimitModules(limitModules); 543 } 544 545 if (stripNativeCommands != null) { 546 bundleParams.setStripNativeCommands(stripNativeCommands); 547 } 548 549 if (modulePath != null && !modulePath.isEmpty()) { 550 bundleParams.setModulePath(modulePath); 551 } 552 553 if (module != null && !module.isEmpty()) { 554 bundleParams.setMainModule(module); 555 } 556 557 if (debugPort != null && !debugPort.isEmpty()) { 558 bundleParams.setDebug(debugPort); 559 } 560 561 Map<String, String> paramsMap = new TreeMap<>(); 562 if (params != null) { 563 for (Param p : params) { 564 paramsMap.put(p.name, p.value); 565 } 566 } | 40 import java.util.Map; 41 import java.util.Set; 42 import java.util.TreeMap; 43 import java.util.TreeSet; 44 45 /** 46 * DeployParams 47 * 48 * This class is generated and used in Arguments.processArguments() as 49 * intermediate step in generating the BundleParams and ultimately the Bundles 50 */ 51 public class DeployParams { 52 53 final List<RelativeFileSet> resources = new ArrayList<>(); 54 55 String id; 56 String title; 57 String vendor; 58 String email; 59 String description; 60 String licenseType; 61 String copyright; 62 String version; 63 Boolean systemWide; 64 Boolean serviceHint; 65 Boolean signBundle; 66 Boolean installdirChooser; 67 68 String applicationClass; 69 70 List<Param> params; 71 List<String> arguments; //unnamed arguments 72 73 // Java 9 modules support 74 String addModules = null; 75 String limitModules = null; 76 String modulePath = null; 77 String module = null; 78 String debugPort = null; 79 80 File outdir = null; 81 82 String appId = null; 83 84 // list of jvm args 85 // (in theory string can contain spaces and need to be escaped 86 List<String> jvmargs = new LinkedList<>(); 87 88 // raw arguments to the bundler 89 Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>(); 90 91 void setLicenseType(String licenseType) { 92 this.licenseType = licenseType; 93 } 94 95 void setCopyright(String copyright) { 96 this.copyright = copyright; 97 } 98 99 void setVersion(String version) { 100 this.version = version; 101 } 102 103 void setSystemWide(Boolean systemWide) { 104 this.systemWide = systemWide; 105 } 106 107 void setInstalldirChooser(Boolean installdirChooser) { 108 this.installdirChooser = installdirChooser; 109 } 110 145 limitModules += "," + value; 146 } 147 } 148 149 String getModulePath() { 150 return this.modulePath; 151 } 152 153 void setModulePath(String value) { 154 this.modulePath = value; 155 } 156 157 void setModule(String value) { 158 this.module = value; 159 } 160 161 void setDebug(String value) { 162 this.debugPort = value; 163 } 164 165 void setDescription(String description) { 166 this.description = description; 167 } 168 169 public void setAppId(String id) { 170 appId = id; 171 } 172 173 void setParams(List<Param> params) { 174 this.params = params; 175 } 176 177 void setTitle(String title) { 178 this.title = title; 179 } 180 181 void setVendor(String vendor) { 182 this.vendor = vendor; 183 } 184 312 // Accept anything else including special chars like copyright 313 // symbols. Note: space will be included by ASCII check above, 314 // but other whitespace like tabs or new line will be rejected. 315 if (Character.isISOControl(a) || 316 Character.isWhitespace(a)) { 317 throw new PackagerException(exceptionKey, s); 318 } 319 } else if (a == '"' || a == '%') { 320 throw new PackagerException(exceptionKey, s); 321 } 322 } 323 } 324 325 public void validate() throws PackagerException { 326 if (outdir == null) { 327 throw new PackagerException("ERR_MissingArgument", "--output"); 328 } 329 330 boolean hasModule = (bundlerArguments.get( 331 Arguments.CLIOptions.MODULE.getId()) != null); 332 boolean hasAppImage = (bundlerArguments.get( 333 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null); 334 boolean hasClass = (bundlerArguments.get( 335 Arguments.CLIOptions.APPCLASS.getId()) != null); 336 boolean hasMain = (bundlerArguments.get( 337 Arguments.CLIOptions.MAIN_JAR.getId()) != null); 338 boolean hasRuntimeImage = (bundlerArguments.get( 339 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null); 340 boolean hasInput = (bundlerArguments.get( 341 Arguments.CLIOptions.INPUT.getId()) != null); 342 boolean hasModulePath = (bundlerArguments.get( 343 Arguments.CLIOptions.MODULE_PATH.getId()) != null); 344 boolean runtimeInstaller = (BundlerType.INSTALLER == getBundleType()) && 345 !hasAppImage && !hasModule && !hasMain && hasRuntimeImage; 346 347 if (getBundleType() == BundlerType.IMAGE) { 348 // Module application requires --runtime-image or --module-path 349 if (hasModule) { 350 if (!hasModulePath && !hasRuntimeImage) { 351 throw new PackagerException("ERR_MissingArgument", 352 "--runtime-image or --module-path"); 353 } 354 } else { 355 if (!hasInput) { 356 throw new PackagerException( 357 "ERR_MissingArgument", "--input"); 358 } 359 } 360 } else if (getBundleType() == BundlerType.INSTALLER) { 361 if (!runtimeInstaller) { 362 if (hasModule) { 363 if (!hasModulePath && !hasRuntimeImage && !hasAppImage) { 364 throw new PackagerException("ERR_MissingArgument", 365 "--runtime-image, --module-path or --app-image"); 366 } 367 } else { 368 if (!hasInput && !hasAppImage) { 369 throw new PackagerException("ERR_MissingArgument", 370 "--input or --app-image"); 371 } 372 } 373 } 374 } 375 376 // if bundling non-modular image, or installer without app-image 377 // then we need some resources and a main class 378 if (!hasModule && !hasAppImage && !runtimeInstaller) { 379 if (resources.isEmpty()) { 380 throw new PackagerException("ERR_MissingAppResources"); 381 } 382 if (!hasClass) { 383 throw new PackagerException("ERR_MissingArgument", 384 "--main-class"); 385 } 386 if (!hasMain) { 387 throw new PackagerException("ERR_MissingArgument", 388 "--main-jar"); 389 } 390 } 391 392 String name = (String)bundlerArguments.get( 393 Arguments.CLIOptions.NAME.getId()); 394 validateName(name, true); 395 396 // Validate app image if set 397 String appImage = (String)bundlerArguments.get( 398 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()); 399 if (appImage != null) { 400 File appImageDir = new File(appImage); 401 if (!appImageDir.exists() || appImageDir.list().length == 0) { 402 throw new PackagerException("ERR_AppImageNotExist", appImage); 403 } 404 } 405 406 // Validate temp-root 407 String root = (String)bundlerArguments.get( 408 Arguments.CLIOptions.TEMP_ROOT.getId()); 409 if (root != null) { 410 String [] contents = (new File(root)).list(); 411 412 if (contents != null && contents.length > 0) { 413 throw new PackagerException("ERR_BuildRootInvalid", root); 414 } 415 } 416 417 // Validate license file if set 418 String license = (String)bundlerArguments.get( 419 Arguments.CLIOptions.LICENSE_FILE.getId()); 420 if (license != null) { 421 File licenseFile = new File(license); 422 if (!licenseFile.exists()) { 423 throw new PackagerException("ERR_LicenseFileNotExit"); 424 } 425 } 426 } 427 428 boolean validateForBundle() { 498 bundlerArguments.put(key, value); 499 } 500 } 501 502 BundleParams getBundleParams() { 503 BundleParams bundleParams = new BundleParams(); 504 505 // construct app resources relative to output folder! 506 bundleParams.setAppResourcesList(resources); 507 508 bundleParams.setIdentifier(id); 509 510 bundleParams.setApplicationClass(applicationClass); 511 bundleParams.setAppVersion(version); 512 bundleParams.setType(bundleType); 513 bundleParams.setBundleFormat(targetFormat); 514 bundleParams.setVendor(vendor); 515 bundleParams.setEmail(email); 516 bundleParams.setInstalldirChooser(installdirChooser); 517 bundleParams.setCopyright(copyright); 518 bundleParams.setDescription(description); 519 bundleParams.setTitle(title); 520 521 bundleParams.setJvmargs(jvmargs); 522 bundleParams.setArguments(arguments); 523 524 if (addModules != null && !addModules.isEmpty()) { 525 bundleParams.setAddModules(addModules); 526 } 527 528 if (limitModules != null && !limitModules.isEmpty()) { 529 bundleParams.setLimitModules(limitModules); 530 } 531 532 if (modulePath != null && !modulePath.isEmpty()) { 533 bundleParams.setModulePath(modulePath); 534 } 535 536 if (module != null && !module.isEmpty()) { 537 bundleParams.setMainModule(module); 538 } 539 540 if (debugPort != null && !debugPort.isEmpty()) { 541 bundleParams.setDebug(debugPort); 542 } 543 544 Map<String, String> paramsMap = new TreeMap<>(); 545 if (params != null) { 546 for (Param p : params) { 547 paramsMap.put(p.name, p.value); 548 } 549 } |