< 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 targetFormat = null; // means app-image
  56 
  57     File outdir = null;
  58 
  59     // raw arguments to the bundler
  60     Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
  61 
  62     public void setOutput(File output) {
  63         outdir = output;
  64     }
  65 
  66     static class Template {
  67         File in;
  68         File out;
  69 
  70         Template(File in, File out) {
  71             this.in = in;
  72             this.out = out;
  73         }
  74     }
  75 


 180 
 181     public void validate() throws PackagerException {
 182         if (outdir == null) {
 183             throw new PackagerException("ERR_MissingArgument", "--output");
 184         }
 185 
 186         boolean hasModule = (bundlerArguments.get(
 187                 Arguments.CLIOptions.MODULE.getId()) != null);
 188         boolean hasAppImage = (bundlerArguments.get(
 189                 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null);
 190         boolean hasClass = (bundlerArguments.get(
 191                 Arguments.CLIOptions.APPCLASS.getId()) != null);
 192         boolean hasMain = (bundlerArguments.get(
 193                 Arguments.CLIOptions.MAIN_JAR.getId()) != null);
 194         boolean hasRuntimeImage = (bundlerArguments.get(
 195                 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
 196         boolean hasInput = (bundlerArguments.get(
 197                 Arguments.CLIOptions.INPUT.getId()) != null);
 198         boolean hasModulePath = (bundlerArguments.get(
 199                 Arguments.CLIOptions.MODULE_PATH.getId()) != null);
 200         boolean runtimeInstaller = targetFormat != null &&
 201                 !hasAppImage && !hasModule && !hasMain && hasRuntimeImage;
 202 
 203         if (targetFormat == null) {
 204             // Module application requires --runtime-image or --module-path
 205             if (hasModule) {
 206                 if (!hasModulePath && !hasRuntimeImage) {
 207                     throw new PackagerException("ERR_MissingArgument",
 208                             "--runtime-image or --module-path");
 209                 }
 210             } else {
 211                 if (!hasInput) {
 212                     throw new PackagerException(
 213                            "ERR_MissingArgument", "--input");
 214                 }
 215             }
 216         } else {
 217             if (!runtimeInstaller) {
 218                 if (hasModule) {
 219                     if (!hasModulePath && !hasRuntimeImage && !hasAppImage) {
 220                         throw new PackagerException("ERR_MissingArgument",
 221                             "--runtime-image, --module-path or --app-image");
 222                     }
 223                 } else {


 266             }
 267         }
 268 
 269         // Validate license file if set
 270         String license = (String)bundlerArguments.get(
 271                 Arguments.CLIOptions.LICENSE_FILE.getId());
 272         if (license != null) {
 273             File licenseFile = new File(license);
 274             if (!licenseFile.exists()) {
 275                 throw new PackagerException("ERR_LicenseFileNotExit");
 276             }
 277         }
 278     }
 279 
 280     void setTargetFormat(String t) {
 281         targetFormat = t;
 282     }
 283 
 284     String getTargetFormat() {
 285         return targetFormat;




 286     }
 287 
 288     private static final Set<String> multi_args = new TreeSet<>(Arrays.asList(
 289             StandardBundlerParam.JAVA_OPTIONS.getID(),
 290             StandardBundlerParam.ARGUMENTS.getID(),
 291             StandardBundlerParam.MODULE_PATH.getID(),
 292             StandardBundlerParam.ADD_MODULES.getID(),
 293             StandardBundlerParam.LIMIT_MODULES.getID(),
 294             StandardBundlerParam.FILE_ASSOCIATIONS.getID()
 295     ));
 296 
 297     @SuppressWarnings("unchecked")
 298     public void addBundleArgument(String key, Object value) {
 299         // special hack for multi-line arguments
 300         if (multi_args.contains(key)) {
 301             Object existingValue = bundlerArguments.get(key);
 302             if (existingValue instanceof String && value instanceof String) {
 303                 String delim = "\n\n";
 304                 if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
 305                     delim = File.pathSeparator;




  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 targetFormat = null; // means default type for this platform
  56 
  57     File outdir = null;
  58 
  59     // raw arguments to the bundler
  60     Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
  61 
  62     public void setOutput(File output) {
  63         outdir = output;
  64     }
  65 
  66     static class Template {
  67         File in;
  68         File out;
  69 
  70         Template(File in, File out) {
  71             this.in = in;
  72             this.out = out;
  73         }
  74     }
  75 


 180 
 181     public void validate() throws PackagerException {
 182         if (outdir == null) {
 183             throw new PackagerException("ERR_MissingArgument", "--output");
 184         }
 185 
 186         boolean hasModule = (bundlerArguments.get(
 187                 Arguments.CLIOptions.MODULE.getId()) != null);
 188         boolean hasAppImage = (bundlerArguments.get(
 189                 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null);
 190         boolean hasClass = (bundlerArguments.get(
 191                 Arguments.CLIOptions.APPCLASS.getId()) != null);
 192         boolean hasMain = (bundlerArguments.get(
 193                 Arguments.CLIOptions.MAIN_JAR.getId()) != null);
 194         boolean hasRuntimeImage = (bundlerArguments.get(
 195                 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
 196         boolean hasInput = (bundlerArguments.get(
 197                 Arguments.CLIOptions.INPUT.getId()) != null);
 198         boolean hasModulePath = (bundlerArguments.get(
 199                 Arguments.CLIOptions.MODULE_PATH.getId()) != null);
 200         boolean runtimeInstaller = !isTargetAppImage() &&
 201                 !hasAppImage && !hasModule && !hasMain && hasRuntimeImage;
 202 
 203         if (isTargetAppImage()) {
 204             // Module application requires --runtime-image or --module-path
 205             if (hasModule) {
 206                 if (!hasModulePath && !hasRuntimeImage) {
 207                     throw new PackagerException("ERR_MissingArgument",
 208                             "--runtime-image or --module-path");
 209                 }
 210             } else {
 211                 if (!hasInput) {
 212                     throw new PackagerException(
 213                            "ERR_MissingArgument", "--input");
 214                 }
 215             }
 216         } else {
 217             if (!runtimeInstaller) {
 218                 if (hasModule) {
 219                     if (!hasModulePath && !hasRuntimeImage && !hasAppImage) {
 220                         throw new PackagerException("ERR_MissingArgument",
 221                             "--runtime-image, --module-path or --app-image");
 222                     }
 223                 } else {


 266             }
 267         }
 268 
 269         // Validate license file if set
 270         String license = (String)bundlerArguments.get(
 271                 Arguments.CLIOptions.LICENSE_FILE.getId());
 272         if (license != null) {
 273             File licenseFile = new File(license);
 274             if (!licenseFile.exists()) {
 275                 throw new PackagerException("ERR_LicenseFileNotExit");
 276             }
 277         }
 278     }
 279 
 280     void setTargetFormat(String t) {
 281         targetFormat = t;
 282     }
 283 
 284     String getTargetFormat() {
 285         return targetFormat;
 286     }
 287 
 288     boolean isTargetAppImage() {
 289         return ("app-image".equals(targetFormat));
 290     }
 291 
 292     private static final Set<String> multi_args = new TreeSet<>(Arrays.asList(
 293             StandardBundlerParam.JAVA_OPTIONS.getID(),
 294             StandardBundlerParam.ARGUMENTS.getID(),
 295             StandardBundlerParam.MODULE_PATH.getID(),
 296             StandardBundlerParam.ADD_MODULES.getID(),
 297             StandardBundlerParam.LIMIT_MODULES.getID(),
 298             StandardBundlerParam.FILE_ASSOCIATIONS.getID()
 299     ));
 300 
 301     @SuppressWarnings("unchecked")
 302     public void addBundleArgument(String key, Object value) {
 303         // special hack for multi-line arguments
 304         if (multi_args.contains(key)) {
 305             Object existingValue = bundlerArguments.get(key);
 306             if (existingValue instanceof String && value instanceof String) {
 307                 String delim = "\n\n";
 308                 if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
 309                     delim = File.pathSeparator;


< prev index next >