< prev index next >

src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java

Print this page




  35 import java.util.Collection;
  36 import java.util.LinkedHashMap;
  37 import java.util.LinkedHashSet;
  38 import java.util.LinkedList;
  39 import java.util.List;
  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 vendor;
  57     String email;
  58     String description;
  59     String licenseType;
  60     String copyright;
  61     String version;
  62     Boolean systemWide;
  63     Boolean serviceHint;
  64     Boolean signBundle;
  65     Boolean installdirChooser;
  66 
  67     String applicationClass;
  68 
  69     List<Param> params;
  70 
  71     // Java modules support
  72     String addModules = null;
  73     String limitModules = null;
  74     String modulePath = null;
  75     String module = null;
  76 
  77     File outdir = null;
  78 
  79     String appId = null;
  80 
  81     // list of jvm args
  82     // (in theory string can contain spaces and need to be escaped
  83     List<String> jvmargs = new LinkedList<>();
  84 
  85     // raw arguments to the bundler
  86     Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
  87 
  88     void setLicenseType(String licenseType) {
  89         this.licenseType = licenseType;
  90     }
  91 
  92     void setCopyright(String copyright) {
  93         this.copyright = copyright;
  94     }
  95 
  96     void setVersion(String version) {
  97         this.version = version;
  98     }
  99 
 100     void setSystemWide(Boolean systemWide) {
 101         this.systemWide = systemWide;
 102     }
 103 
 104     void setInstalldirChooser(Boolean installdirChooser) {
 105         this.installdirChooser = installdirChooser;
 106     }
 107 
 108     void setSignBundle(Boolean signBundle) {
 109         this.signBundle = signBundle;
 110     }
 111 
 112     void addJvmArg(String v) {
 113         jvmargs.add(v);
 114     }
 115 
 116     void addAddModule(String value) {
 117         if (addModules == null) {
 118             addModules = value;
 119         }
 120         else {
 121             addModules += "," + value;
 122         }
 123     }
 124 
 125     void addLimitModule(String value) {
 126         if (limitModules == null) {
 127             limitModules = value;
 128         }
 129         else {
 130             limitModules += "," + value;
 131         }
 132     }
 133 
 134     String getModulePath() {
 135         return this.modulePath;
 136     }
 137 
 138     void setModulePath(String value) {
 139         this.modulePath = value;
 140     }
 141 
 142     void setModule(String value) {
 143         this.module = value;
 144     }
 145 
 146     void setDescription(String description) {
 147         this.description = description;
 148     }
 149 
 150     public void setAppId(String id) {
 151         appId = id;
 152     }
 153 
 154     void setParams(List<Param> params) {
 155         this.params = params;
 156     }
 157 
 158     void setVendor(String vendor) {
 159         this.vendor = vendor;
 160     }
 161 
 162     void setEmail(String email) {
 163         this.email = email;
 164     }
 165 
 166     void setApplicationClass(String applicationClass) {
 167         this.applicationClass = applicationClass;
 168     }
 169 
 170     File getOutput() {
 171         return outdir;
 172     }
 173 
 174     public void setOutput(File output) {
 175         outdir = output;
 176     }
 177 
 178     static class Template {
 179         File in;
 180         File out;
 181 
 182         Template(File in, File out) {
 183             this.in = in;
 184             this.out = out;
 185         }


 220         if (baseDir == null) {
 221             baseDir = file.getParentFile();
 222         }
 223         resources.add(new RelativeFileSet(
 224                 baseDir, new LinkedHashSet<>(expandFileset(file))));
 225     }
 226 
 227     void setClasspath() {
 228         String classpath = "";
 229         for (RelativeFileSet resource : resources) {
 230              for (String file : resource.getIncludedFiles()) {
 231                  if (file.endsWith(".jar")) {
 232                      classpath += file + File.pathSeparator;
 233                  }
 234              }
 235         }
 236         addBundleArgument(
 237                 StandardBundlerParam.CLASSPATH.getID(), classpath);
 238     }
 239 
 240     private static File createFile(final File baseDir, final String path) {
 241         final File testFile = new File(path);
 242         return testFile.isAbsolute() ?
 243                 testFile : new File(baseDir == null ?
 244                         null : baseDir.getAbsolutePath(), path);
 245     }
 246 
 247     static void validateName(String s, boolean forApp)
 248             throws PackagerException {
 249 
 250         String exceptionKey = forApp ?
 251             "ERR_InvalidAppName" : "ERR_InvalidSLName";
 252 
 253         if (s == null) {
 254             if (forApp) {
 255                 return;
 256             } else {
 257                 throw new PackagerException(exceptionKey, s);
 258             }
 259         }
 260         if (s.length() == 0 || s.charAt(s.length() - 1) == '\\') {
 261             throw new PackagerException(exceptionKey, s);
 262         }
 263         try {
 264             // name must be valid path element for this file system
 265             Path p = (new File(s)).toPath();
 266             // and it must be a single name element in a path


 383         if (license != null) {
 384             File licenseFile = new File(license);
 385             if (!licenseFile.exists()) {
 386                 throw new PackagerException("ERR_LicenseFileNotExit");
 387             }
 388         }
 389     }
 390 
 391     boolean validateForBundle() {
 392         boolean result = false;
 393 
 394         // Success
 395         if (((applicationClass != null && !applicationClass.isEmpty()) ||
 396             (module != null && !module.isEmpty()))) {
 397             result = true;
 398         }
 399 
 400         return result;
 401     }
 402 
 403     BundlerType bundleType = BundlerType.NONE;
 404     String targetFormat = null; //means any
 405 
 406     void setBundleType(BundlerType type) {
 407         bundleType = type;
 408     }
 409 
 410     BundlerType getBundleType() {
 411         return bundleType;
 412     }
 413 
 414     void setTargetFormat(String t) {
 415         targetFormat = t;
 416     }
 417 
 418     String getTargetFormat() {
 419         return targetFormat;
 420     }
 421 
 422     private String getArch() {
 423         String arch = System.getProperty("os.arch").toLowerCase();
 424 
 425         if ("x86".equals(arch) || "i386".equals(arch) || "i486".equals(arch)
 426                 || "i586".equals(arch) || "i686".equals(arch)) {
 427             arch = "x86";
 428         } else if ("x86_64".equals(arch) || "amd64".equals("arch")) {
 429             arch = "x86_64";
 430         }
 431 
 432         return arch;
 433     }
 434 
 435     static final Set<String> multi_args = new TreeSet<>(Arrays.asList(
 436             StandardBundlerParam.JAVA_OPTIONS.getID(),
 437             StandardBundlerParam.ARGUMENTS.getID(),
 438             StandardBundlerParam.MODULE_PATH.getID(),
 439             StandardBundlerParam.ADD_MODULES.getID(),
 440             StandardBundlerParam.LIMIT_MODULES.getID(),
 441             StandardBundlerParam.FILE_ASSOCIATIONS.getID()
 442     ));
 443 
 444     @SuppressWarnings("unchecked")
 445     public void addBundleArgument(String key, Object value) {
 446         // special hack for multi-line arguments
 447         if (multi_args.contains(key)) {
 448             Object existingValue = bundlerArguments.get(key);
 449             if (existingValue instanceof String && value instanceof String) {
 450                 String delim = "\n\n";
 451                 if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
 452                     delim = File.pathSeparator;
 453                 } else if (key.equals(
 454                         StandardBundlerParam.ADD_MODULES.getID())) {
 455                     delim = ",";


 462                 String[] mapValues = ((String)value).split("=", 2);
 463                 ((Map)existingValue).put(mapValues[0], mapValues[1]);
 464             } else {
 465                 bundlerArguments.put(key, value);
 466             }
 467         } else {
 468             bundlerArguments.put(key, value);
 469         }
 470     }
 471 
 472     BundleParams getBundleParams() {
 473         BundleParams bundleParams = new BundleParams();
 474 
 475         // construct app resources relative to output folder!
 476         bundleParams.setAppResourcesList(resources);
 477 
 478         bundleParams.setApplicationClass(applicationClass);
 479         bundleParams.setAppVersion(version);
 480         bundleParams.setType(bundleType);
 481         bundleParams.setBundleFormat(targetFormat);
 482         bundleParams.setVendor(vendor);
 483         bundleParams.setEmail(email);
 484         bundleParams.setInstalldirChooser(installdirChooser);
 485         bundleParams.setCopyright(copyright);
 486         bundleParams.setDescription(description);
 487 
 488         bundleParams.setJvmargs(jvmargs);
 489 
 490         if (addModules != null && !addModules.isEmpty()) {
 491             bundleParams.setAddModules(addModules);
 492         }
 493 
 494         if (limitModules != null && !limitModules.isEmpty()) {
 495             bundleParams.setLimitModules(limitModules);
 496         }
 497 
 498         if (modulePath != null && !modulePath.isEmpty()) {
 499             bundleParams.setModulePath(modulePath);
 500         }
 501 
 502         if (module != null && !module.isEmpty()) {
 503             bundleParams.setMainModule(module);
 504         }
 505 
 506         Map<String, String> paramsMap = new TreeMap<>();
 507         if (params != null) {
 508             for (Param p : params) {
 509                 paramsMap.put(p.name, p.value);
 510             }
 511         }
 512 
 513         Map<String, String> unescapedHtmlParams = new TreeMap<>();
 514         Map<String, String> escapedHtmlParams = new TreeMap<>();
 515 
 516         // check for collisions
 517         TreeSet<String> keys = new TreeSet<>(bundlerArguments.keySet());
 518         keys.retainAll(bundleParams.getBundleParamsAsMap().keySet());
 519 
 520         if (!keys.isEmpty()) {
 521             throw new RuntimeException("Deploy Params and Bundler Arguments "
 522                     + "overlap in the following values:" + keys.toString());
 523         }
 524 
 525         bundleParams.addAllBundleParams(bundlerArguments);
 526 
 527         return bundleParams;
 528     }
 529 
 530     Map<String, ? super Object> getBundlerArguments() {
 531         return this.bundlerArguments;
 532     }
 533 
 534     void putUnlessNull(String param, Object value) {
 535         if (value != null) {
 536             bundlerArguments.put(param, value);
 537         }
 538     }
 539 
 540     void putUnlessNullOrEmpty(String param, Map<?, ?> value) {
 541         if (value != null && !value.isEmpty()) {
 542             bundlerArguments.put(param, value);
 543         }
 544     }
 545 
 546     void putUnlessNullOrEmpty(String param, Collection<?> value) {
 547         if (value != null && !value.isEmpty()) {
 548             bundlerArguments.put(param, value);
 549         }
 550     }
 551 
 552     @Override
 553     public String toString() {
 554         return "DeployParams {" + "output: " + outdir
 555                 + " resources: {" + resources + "}}";
 556     }
 557 
 558 }


  35 import java.util.Collection;
  36 import java.util.LinkedHashMap;
  37 import java.util.LinkedHashSet;
  38 import java.util.LinkedList;
  39 import java.util.List;
  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     BundlerType bundleType = BundlerType.NONE;
  56     String targetFormat = null; //means any


  57     String licenseType;
  58     String copyright;
  59     String version;





  60     String applicationClass;
  61 


  62     // Java modules support
  63     String addModules = null;
  64     String limitModules = null;

  65     String module = null;
  66 
  67     File outdir = null;
  68 

  69 
  70     // list of jvm args
  71     // (in theory string can contain spaces and need to be escaped
  72     List<String> jvmargs = new LinkedList<>();
  73 
  74     // raw arguments to the bundler
  75     Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
  76 
  77     void setLicenseType(String licenseType) {
  78         this.licenseType = licenseType;
  79     }
  80 
  81     void setCopyright(String copyright) {
  82         this.copyright = copyright;
  83     }
  84 
  85     void setVersion(String version) {
  86         this.version = version;
  87     }
  88 












  89     void addJvmArg(String v) {
  90         jvmargs.add(v);
  91     }
  92 
  93     void addAddModule(String value) {
  94         if (addModules == null) {
  95             addModules = value;
  96         }
  97         else {
  98             addModules += "," + value;
  99         }
 100     }
 101 
 102     void addLimitModule(String value) {
 103         if (limitModules == null) {
 104             limitModules = value;
 105         }
 106         else {
 107             limitModules += "," + value;
 108         }
 109     }
 110 








 111     void setModule(String value) {
 112         this.module = value;
 113     }
 114 




















 115     void setApplicationClass(String applicationClass) {
 116         this.applicationClass = applicationClass;
 117     }
 118 
 119     File getOutput() {
 120         return outdir;
 121     }
 122 
 123     public void setOutput(File output) {
 124         outdir = output;
 125     }
 126 
 127     static class Template {
 128         File in;
 129         File out;
 130 
 131         Template(File in, File out) {
 132             this.in = in;
 133             this.out = out;
 134         }


 169         if (baseDir == null) {
 170             baseDir = file.getParentFile();
 171         }
 172         resources.add(new RelativeFileSet(
 173                 baseDir, new LinkedHashSet<>(expandFileset(file))));
 174     }
 175 
 176     void setClasspath() {
 177         String classpath = "";
 178         for (RelativeFileSet resource : resources) {
 179              for (String file : resource.getIncludedFiles()) {
 180                  if (file.endsWith(".jar")) {
 181                      classpath += file + File.pathSeparator;
 182                  }
 183              }
 184         }
 185         addBundleArgument(
 186                 StandardBundlerParam.CLASSPATH.getID(), classpath);
 187     }
 188 







 189     static void validateName(String s, boolean forApp)
 190             throws PackagerException {
 191 
 192         String exceptionKey = forApp ?
 193             "ERR_InvalidAppName" : "ERR_InvalidSLName";
 194 
 195         if (s == null) {
 196             if (forApp) {
 197                 return;
 198             } else {
 199                 throw new PackagerException(exceptionKey, s);
 200             }
 201         }
 202         if (s.length() == 0 || s.charAt(s.length() - 1) == '\\') {
 203             throw new PackagerException(exceptionKey, s);
 204         }
 205         try {
 206             // name must be valid path element for this file system
 207             Path p = (new File(s)).toPath();
 208             // and it must be a single name element in a path


 325         if (license != null) {
 326             File licenseFile = new File(license);
 327             if (!licenseFile.exists()) {
 328                 throw new PackagerException("ERR_LicenseFileNotExit");
 329             }
 330         }
 331     }
 332 
 333     boolean validateForBundle() {
 334         boolean result = false;
 335 
 336         // Success
 337         if (((applicationClass != null && !applicationClass.isEmpty()) ||
 338             (module != null && !module.isEmpty()))) {
 339             result = true;
 340         }
 341 
 342         return result;
 343     }
 344 



 345     void setBundleType(BundlerType type) {
 346         bundleType = type;
 347     }
 348 
 349     BundlerType getBundleType() {
 350         return bundleType;
 351     }
 352 
 353     void setTargetFormat(String t) {
 354         targetFormat = t;
 355     }
 356 
 357     String getTargetFormat() {
 358         return targetFormat;
 359     }
 360 
 361     private static final Set<String> multi_args = new TreeSet<>(Arrays.asList(













 362             StandardBundlerParam.JAVA_OPTIONS.getID(),
 363             StandardBundlerParam.ARGUMENTS.getID(),
 364             StandardBundlerParam.MODULE_PATH.getID(),
 365             StandardBundlerParam.ADD_MODULES.getID(),
 366             StandardBundlerParam.LIMIT_MODULES.getID(),
 367             StandardBundlerParam.FILE_ASSOCIATIONS.getID()
 368     ));
 369 
 370     @SuppressWarnings("unchecked")
 371     public void addBundleArgument(String key, Object value) {
 372         // special hack for multi-line arguments
 373         if (multi_args.contains(key)) {
 374             Object existingValue = bundlerArguments.get(key);
 375             if (existingValue instanceof String && value instanceof String) {
 376                 String delim = "\n\n";
 377                 if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
 378                     delim = File.pathSeparator;
 379                 } else if (key.equals(
 380                         StandardBundlerParam.ADD_MODULES.getID())) {
 381                     delim = ",";


 388                 String[] mapValues = ((String)value).split("=", 2);
 389                 ((Map)existingValue).put(mapValues[0], mapValues[1]);
 390             } else {
 391                 bundlerArguments.put(key, value);
 392             }
 393         } else {
 394             bundlerArguments.put(key, value);
 395         }
 396     }
 397 
 398     BundleParams getBundleParams() {
 399         BundleParams bundleParams = new BundleParams();
 400 
 401         // construct app resources relative to output folder!
 402         bundleParams.setAppResourcesList(resources);
 403 
 404         bundleParams.setApplicationClass(applicationClass);
 405         bundleParams.setAppVersion(version);
 406         bundleParams.setType(bundleType);
 407         bundleParams.setBundleFormat(targetFormat);



 408         bundleParams.setCopyright(copyright);

 409 
 410         bundleParams.setJvmargs(jvmargs);
 411 
 412         if (addModules != null && !addModules.isEmpty()) {
 413             bundleParams.setAddModules(addModules);
 414         }
 415 
 416         if (limitModules != null && !limitModules.isEmpty()) {
 417             bundleParams.setLimitModules(limitModules);
 418         }
 419 




 420         if (module != null && !module.isEmpty()) {
 421             bundleParams.setMainModule(module);
 422         }
 423 







 424         Map<String, String> unescapedHtmlParams = new TreeMap<>();
 425         Map<String, String> escapedHtmlParams = new TreeMap<>();
 426 
 427         // check for collisions
 428         TreeSet<String> keys = new TreeSet<>(bundlerArguments.keySet());
 429         keys.retainAll(bundleParams.getBundleParamsAsMap().keySet());
 430 
 431         if (!keys.isEmpty()) {
 432             throw new RuntimeException("Deploy Params and Bundler Arguments "
 433                     + "overlap in the following values:" + keys.toString());
 434         }
 435 
 436         bundleParams.addAllBundleParams(bundlerArguments);
 437 
 438         return bundleParams;
 439     }
 440 
 441     Map<String, ? super Object> getBundlerArguments() {
 442         return this.bundlerArguments;


















 443     }
 444 
 445     @Override
 446     public String toString() {
 447         return "DeployParams {" + "output: " + outdir
 448                 + " resources: {" + resources + "}}";
 449     }
 450 
 451 }
< prev index next >