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) {
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() {
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 }
|
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 String modulePath = null;
78 String module = null;
79 String debugPort = null;
80
81 File outdir = null;
82
83 String appId = null;
84
85 // list of jvm args
86 // (in theory string can contain spaces and need to be escaped
87 List<String> jvmargs = new LinkedList<>();
88
89 // raw arguments to the bundler
90 Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
91
92 void setCategory(String category) {
93 this.category = category;
94 }
95
96 void setLicenseType(String licenseType) {
150 limitModules += "," + value;
151 }
152 }
153
154 String getModulePath() {
155 return this.modulePath;
156 }
157
158 void setModulePath(String value) {
159 this.modulePath = value;
160 }
161
162 void setModule(String value) {
163 this.module = value;
164 }
165
166 void setDebug(String value) {
167 this.debugPort = value;
168 }
169
170 void setDescription(String description) {
171 this.description = description;
172 }
173
174 public void setAppId(String id) {
175 appId = id;
176 }
177
178 void setParams(List<Param> params) {
179 this.params = params;
180 }
181
182 void setTitle(String title) {
183 this.title = title;
184 }
185
186 void setVendor(String vendor) {
187 this.vendor = vendor;
188 }
189
317 // Accept anything else including special chars like copyright
318 // symbols. Note: space will be included by ASCII check above,
319 // but other whitespace like tabs or new line will be rejected.
320 if (Character.isISOControl(a) ||
321 Character.isWhitespace(a)) {
322 throw new PackagerException(exceptionKey, s);
323 }
324 } else if (a == '"' || a == '%') {
325 throw new PackagerException(exceptionKey, s);
326 }
327 }
328 }
329
330 public void validate() throws PackagerException {
331 if (outdir == null) {
332 throw new PackagerException("ERR_MissingArgument", "--output");
333 }
334
335 boolean hasModule = (bundlerArguments.get(
336 Arguments.CLIOptions.MODULE.getId()) != null);
337 boolean hasAppImage = (bundlerArguments.get(
338 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null);
339 boolean hasClass = (bundlerArguments.get(
340 Arguments.CLIOptions.APPCLASS.getId()) != null);
341 boolean hasMain = (bundlerArguments.get(
342 Arguments.CLIOptions.MAIN_JAR.getId()) != null);
343 boolean hasRuntimeImage = (bundlerArguments.get(
344 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
345 boolean hasInput = (bundlerArguments.get(
346 Arguments.CLIOptions.INPUT.getId()) != null);
347 boolean hasModulePath = (bundlerArguments.get(
348 Arguments.CLIOptions.MODULE_PATH.getId()) != null);
349 boolean runtimeInstaller = (BundlerType.INSTALLER == getBundleType()) &&
350 !hasAppImage && !hasModule && !hasMain && hasRuntimeImage;
351
352 if (getBundleType() == BundlerType.IMAGE) {
353 // Module application requires --runtime-image or --module-path
354 if (hasModule) {
355 if (!hasModulePath && !hasRuntimeImage) {
356 throw new PackagerException("ERR_MissingArgument",
357 "--runtime-image or --module-path");
358 }
359 } else {
360 if (!hasInput) {
361 throw new PackagerException(
362 "ERR_MissingArgument", "--input");
363 }
364 }
365 } else if (getBundleType() == BundlerType.INSTALLER) {
366 if (!runtimeInstaller) {
367 if (hasModule) {
368 if (!hasModulePath && !hasRuntimeImage && !hasAppImage) {
369 throw new PackagerException("ERR_MissingArgument",
370 "--runtime-image, --module-path or --app-image");
371 }
372 } else {
373 if (!hasInput && !hasAppImage) {
374 throw new PackagerException("ERR_MissingArgument",
375 "--input or --app-image");
376 }
377 }
378 }
379 }
380
381 // if bundling non-modular image, or installer without app-image
382 // then we need some resources and a main class
383 if (!hasModule && !hasAppImage && !runtimeInstaller) {
384 if (resources.isEmpty()) {
385 throw new PackagerException("ERR_MissingAppResources");
386 }
387 if (!hasClass) {
388 throw new PackagerException("ERR_MissingArgument",
389 "--main-class");
390 }
391 if (!hasMain) {
392 throw new PackagerException("ERR_MissingArgument",
393 "--main-jar");
394 }
395 }
396
397 String name = (String)bundlerArguments.get(
398 Arguments.CLIOptions.NAME.getId());
399 validateName(name, true);
400
401 // Validate app image if set
402 String appImage = (String)bundlerArguments.get(
403 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
404 if (appImage != null) {
405 File appImageDir = new File(appImage);
406 if (!appImageDir.exists() || appImageDir.list().length == 0) {
407 throw new PackagerException("ERR_AppImageNotExist", appImage);
408 }
409 }
410
411 // Validate temp-root
412 String root = (String)bundlerArguments.get(
413 Arguments.CLIOptions.TEMP_ROOT.getId());
414 if (root != null) {
415 String [] contents = (new File(root)).list();
416
417 if (contents != null && contents.length > 0) {
418 throw new PackagerException("ERR_BuildRootInvalid", root);
419 }
420 }
421
422 // Validate license file if set
423 String license = (String)bundlerArguments.get(
424 Arguments.CLIOptions.LICENSE_FILE.getId());
425 if (license != null) {
426 File licenseFile = new File(license);
427 if (!licenseFile.exists()) {
428 throw new PackagerException("ERR_LicenseFileNotExit");
429 }
430 }
431 }
432
433 boolean validateForBundle() {
516 bundleParams.setAppVersion(version);
517 bundleParams.setType(bundleType);
518 bundleParams.setBundleFormat(targetFormat);
519 bundleParams.setVendor(vendor);
520 bundleParams.setEmail(email);
521 bundleParams.setInstalldirChooser(installdirChooser);
522 bundleParams.setCopyright(copyright);
523 bundleParams.setApplicationCategory(category);
524 bundleParams.setDescription(description);
525 bundleParams.setTitle(title);
526
527 bundleParams.setJvmargs(jvmargs);
528 bundleParams.setArguments(arguments);
529
530 if (addModules != null && !addModules.isEmpty()) {
531 bundleParams.setAddModules(addModules);
532 }
533
534 if (limitModules != null && !limitModules.isEmpty()) {
535 bundleParams.setLimitModules(limitModules);
536 }
537
538 if (modulePath != null && !modulePath.isEmpty()) {
539 bundleParams.setModulePath(modulePath);
540 }
541
542 if (module != null && !module.isEmpty()) {
543 bundleParams.setMainModule(module);
544 }
545
546 if (debugPort != null && !debugPort.isEmpty()) {
547 bundleParams.setDebug(debugPort);
548 }
549
550 Map<String, String> paramsMap = new TreeMap<>();
551 if (params != null) {
552 for (Param p : params) {
553 paramsMap.put(p.name, p.value);
554 }
555 }
|