src/jdk.packager/share/classes/jdk/packager/internal/DeployParams.java
branchJDK-8200758-branch
changeset 56982 e094d5483bd6
parent 56933 9f59eeb3cc0f
child 56985 5e6ced665587
equal deleted inserted replaced
56963:eaca4369b068 56982:e094d5483bd6
    25 
    25 
    26 package jdk.packager.internal;
    26 package jdk.packager.internal;
    27 
    27 
    28 import jdk.packager.internal.bundlers.*;
    28 import jdk.packager.internal.bundlers.*;
    29 import jdk.packager.internal.bundlers.Bundler.BundleType;
    29 import jdk.packager.internal.bundlers.Bundler.BundleType;
       
    30 
    30 import java.io.File;
    31 import java.io.File;
       
    32 import java.nio.file.Files;
    31 import java.util.ArrayList;
    33 import java.util.ArrayList;
    32 import java.util.Arrays;
    34 import java.util.Arrays;
    33 import java.util.Collection;
    35 import java.util.Collection;
    34 import java.util.LinkedHashMap;
    36 import java.util.LinkedHashMap;
    35 import java.util.LinkedHashSet;
    37 import java.util.LinkedHashSet;
    58     Boolean signBundle;
    60     Boolean signBundle;
    59     Boolean installdirChooser;
    61     Boolean installdirChooser;
    60     Boolean singleton;
    62     Boolean singleton;
    61 
    63 
    62     String applicationClass;
    64     String applicationClass;
    63     String preloader;
       
    64 
    65 
    65     List<Param> params;
    66     List<Param> params;
    66     List<String> arguments; //unnamed arguments
    67     List<String> arguments; //unnamed arguments
    67 
    68 
    68     // Java 9 modules support
    69     // Java 9 modules support
    69     String addModules = null;
    70     String addModules = null;
    70     String limitModules = null;
    71     String limitModules = null;
    71     Boolean stripNativeCommands = null;
    72     Boolean stripNativeCommands = null;
    72     Boolean detectmods = null;
       
    73     String modulePath = null;
    73     String modulePath = null;
    74     String module = null;
    74     String module = null;
    75     String debugPort = null;
    75     String debugPort = null;
    76     String srcdir;
       
    77 
       
    78     int width;
       
    79     int height;
       
    80     String embeddedWidth = null;
       
    81     String embeddedHeight = null;
       
    82 
       
    83     String appName;
       
    84     String codebase;
       
    85 
       
    86     @Deprecated final boolean embedCertificates = false;
       
    87     boolean allPermissions = false;
       
    88     String updateMode = "background";
       
    89     boolean isExtension = false;
       
    90     boolean isSwingApp = false;
       
    91 
    76 
    92     boolean jreInstaller = false;
    77     boolean jreInstaller = false;
    93 
    78 
    94     Boolean needShortcut = null;
       
    95     Boolean needMenu = null;
       
    96     Boolean needInstall = null;
       
    97 
       
    98     String outfile;
    79     String outfile;
    99     // if true then we cobundle js and image files needed
    80 
   100     // for web deployment with the application
       
   101     boolean includeDT;
       
   102 
       
   103     String placeholder = "'javafx-app-placeholder'";
       
   104     String appId = null;
    81     String appId = null;
   105 
       
   106     // didn't have a setter...
       
   107     boolean offlineAllowed = true;
       
   108 
       
   109     String jrePlatform = System.getProperty("java.version")+"+";
       
   110     File javaRuntimeToUse = null;
       
   111     boolean javaRuntimeWasSet = false;
       
   112 
    82 
   113     // list of jvm args
    83     // list of jvm args
   114     // (in theory string can contain spaces and need to be escaped
    84     // (in theory string can contain spaces and need to be escaped
   115     List<String> jvmargs = new LinkedList<>();
    85     List<String> jvmargs = new LinkedList<>();
   116 
    86 
   119     Map<String, String> properties = new LinkedHashMap<>();
    89     Map<String, String> properties = new LinkedHashMap<>();
   120 
    90 
   121     // raw arguments to the bundler
    91     // raw arguments to the bundler
   122     Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
    92     Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
   123 
    93 
   124     String fallbackApp = null;
       
   125 
       
   126     public void setJavaRuntimeSource(File src) {
       
   127         javaRuntimeToUse = src;
       
   128         javaRuntimeWasSet = true;
       
   129     }
       
   130 
       
   131     public void setCodebase(String codebase) {
       
   132         this.codebase = codebase;
       
   133     }
       
   134 
       
   135     public void setId(String id) {
    94     public void setId(String id) {
   136         this.id = id;
    95         this.id = id;
   137     }
    96     }
   138 
    97 
   139     public void setCategory(String category) {
    98     public void setCategory(String category) {
   170 
   129 
   171     public void setSignBundle(Boolean signBundle) {
   130     public void setSignBundle(Boolean signBundle) {
   172         this.signBundle = signBundle;
   131         this.signBundle = signBundle;
   173     }
   132     }
   174 
   133 
   175     public void setJRE(String v) {
       
   176         jrePlatform = v;
       
   177     }
       
   178 
       
   179     public void setSwingAppWithEmbeddedJavaFX(boolean v) {
       
   180         isSwingApp = v;
       
   181     }
       
   182 
       
   183     public void setNeedInstall(boolean b) {
       
   184         needInstall = b;
       
   185     }
       
   186 
       
   187     public void setOfflineAllowed(boolean b) {
       
   188         offlineAllowed = b;
       
   189     }
       
   190 
       
   191     public void setNeedShortcut(Boolean b) {
       
   192         needShortcut = b;
       
   193     }
       
   194 
       
   195     public void setEmbeddedDimensions(String w, String h) {
       
   196         embeddedWidth = w;
       
   197         embeddedHeight = h;
       
   198     }
       
   199 
       
   200     public void setFallback(String v) {
       
   201         if (v == null) {
       
   202             return;
       
   203         }
       
   204 
       
   205         if ("none".equals(v) || "null".equals(v)) {
       
   206             fallbackApp = null;
       
   207         } else {
       
   208             fallbackApp = v;
       
   209         }
       
   210     }
       
   211 
       
   212     public void addJvmArg(String v) {
   134     public void addJvmArg(String v) {
   213         jvmargs.add(v);
   135         jvmargs.add(v);
   214     }
   136     }
   215 
   137 
   216     public void addJvmProperty(String n, String v) {
   138     public void addJvmProperty(String n, String v) {
   217         properties.put(n, v);
   139         properties.put(n, v);
   218     }
       
   219 
       
   220     public void setAllPermissions(boolean allPermissions) {
       
   221         this.allPermissions = allPermissions;
       
   222     }
       
   223 
       
   224     public void setAppName(String appName) {
       
   225         this.appName = appName;
       
   226     }
   140     }
   227 
   141 
   228     public void setArguments(List<String> args) {
   142     public void setArguments(List<String> args) {
   229         this.arguments = args;
   143         this.arguments = args;
   230     }
   144     }
   257 
   171 
   258     public String getModulePath() {
   172     public String getModulePath() {
   259         return this.modulePath;
   173         return this.modulePath;
   260     }
   174     }
   261 
   175 
   262     public void setSrcdir(String srcdir) {
       
   263         this.srcdir = srcdir;
       
   264     }
       
   265 
       
   266     public void setModulePath(String value) {
   176     public void setModulePath(String value) {
   267         this.modulePath = value;
   177         this.modulePath = value;
   268     }
   178     }
   269 
   179 
   270     public void setModule(String value) {
   180     public void setModule(String value) {
   277 
   187 
   278     public void setStripNativeCommands(boolean value) {
   188     public void setStripNativeCommands(boolean value) {
   279         this.stripNativeCommands = value;
   189         this.stripNativeCommands = value;
   280     }
   190     }
   281 
   191 
   282     public void setDetectModules(boolean value) {
       
   283         this.detectmods = value;
       
   284     }
       
   285 
       
   286     public void setDescription(String description) {
   192     public void setDescription(String description) {
   287         this.description = description;
   193         this.description = description;
   288     }
   194     }
   289 
   195 
   290     public void setPlaceholder(String p) {
       
   291         placeholder = p;
       
   292     }
       
   293 
       
   294     public void setAppId(String id) {
   196     public void setAppId(String id) {
   295         appId = id;
   197         appId = id;
   296     }
   198     }
   297 
   199 
   298     public void setHeight(int height) {
       
   299         this.height = height;
       
   300     }
       
   301 
       
   302     public void setOutfile(String outfile) {
   200     public void setOutfile(String outfile) {
   303         this.outfile = outfile;
   201         this.outfile = outfile;
   304     }
   202     }
   305 
   203 
   306     public void setParams(List<Param> params) {
   204     public void setParams(List<Param> params) {
   307         this.params = params;
   205         this.params = params;
   308     }
   206     }
   309 
   207 
   310     public void setPreloader(String preloader) {
       
   311         this.preloader = preloader;
       
   312     }
       
   313 
       
   314     public void setTitle(String title) {
   208     public void setTitle(String title) {
   315         this.title = title;
   209         this.title = title;
   316     }
   210     }
   317 
   211 
   318     public void setUpdateMode(String updateMode) {
       
   319         this.updateMode = updateMode;
       
   320     }
       
   321 
       
   322     public void setVendor(String vendor) {
   212     public void setVendor(String vendor) {
   323         this.vendor = vendor;
   213         this.vendor = vendor;
   324     }
   214     }
   325 
   215 
   326     public void setEmail(String email) {
   216     public void setEmail(String email) {
   327         this.email = email;
   217         this.email = email;
   328     }
   218     }
   329 
   219 
   330     public void setWidth(int width) {
       
   331         this.width = width;
       
   332     }
       
   333 
       
   334     public void setExtension(boolean isExtension) {
       
   335         this.isExtension = isExtension;
       
   336     }
       
   337 
       
   338     public void setApplicationClass(String applicationClass) {
   220     public void setApplicationClass(String applicationClass) {
   339         this.applicationClass = applicationClass;
   221         this.applicationClass = applicationClass;
   340     }
       
   341 
       
   342     public void setIncludeDT(boolean doEmbed) {
       
   343         includeDT = doEmbed;
       
   344     }
   222     }
   345 
   223 
   346     public void setJreInstaller(boolean value) {
   224     public void setJreInstaller(boolean value) {
   347         jreInstaller = value;
   225         jreInstaller = value;
   348     }
   226     }
   360             this.out = out;
   238             this.out = out;
   361         }
   239         }
   362     }
   240     }
   363 
   241 
   364     // we need to expand as in some cases
   242     // we need to expand as in some cases
   365     // (most notably javapackager)
   243     // (most notably jpackager)
   366     // we may get "." as filename and assumption is we include
   244     // we may get "." as filename and assumption is we include
   367     // everything in the given folder
   245     // everything in the given folder
   368     // (IOUtils.copyfiles() have recursive behavior)
   246     // (IOUtils.copyfiles() have recursive behavior)
   369     List<File> expandFileset(File root) {
   247     List<File> expandFileset(File root) {
   370         List<File> files = new LinkedList<>();
   248         List<File> files = new LinkedList<>();
   371         if (jdk.packager.internal.IOUtils.isNotSymbolicLink(root)) {
   249         if (!Files.isSymbolicLink(root.toPath())) {
   372             if (root.isDirectory()) {
   250             if (root.isDirectory()) {
   373                 File[] children = root.listFiles();
   251                 File[] children = root.listFiles();
   374                 if (children != null) {
   252                 if (children != null) {
   375                     for (File f : children) {
   253                     for (File f : children) {
   376                         files.addAll(expandFileset(f));
   254                         files.addAll(expandFileset(f));
   410         }
   288         }
   411         resources.add(new RelativeFileSet(
   289         resources.add(new RelativeFileSet(
   412                 baseDir, new LinkedHashSet<>(expandFileset(file))));
   290                 baseDir, new LinkedHashSet<>(expandFileset(file))));
   413     }
   291     }
   414 
   292 
   415     public void addResource(File baseDir, String path, String type) {
       
   416         addResource(baseDir, createFile(baseDir, path), type);
       
   417     }
       
   418 
       
   419     public void addResource(File baseDir, File file, String type) {
       
   420         addResource(baseDir, file, "eager", type, null, null);
       
   421     }
       
   422 
       
   423     public void addResource(File baseDir, File file, String mode,
       
   424             String type, String os, String arch) {
       
   425         Set<File> singleFile = new LinkedHashSet<>();
       
   426         singleFile.add(file);
       
   427         if (baseDir == null) {
       
   428             baseDir = file.getParentFile();
       
   429         }
       
   430         RelativeFileSet rfs = new RelativeFileSet(baseDir, singleFile);
       
   431         rfs.setArch(arch);
       
   432         rfs.setMode(mode);
       
   433         rfs.setOs(os);
       
   434         rfs.setType(parseTypeFromString(type, file));
       
   435         resources.add(rfs);
       
   436     }
       
   437 
       
   438     private RelativeFileSet.Type parseTypeFromString(String type, File file) {
       
   439         if (type == null) {
       
   440             if (file.getName().endsWith(".jar")) {
       
   441                 return RelativeFileSet.Type.jar;
       
   442             } else if (file.getName().endsWith(".jnlp")) {
       
   443                 return RelativeFileSet.Type.jnlp;
       
   444             } else {
       
   445                 return RelativeFileSet.Type.UNKNOWN;
       
   446             }
       
   447         } else {
       
   448             return RelativeFileSet.Type.valueOf(type);
       
   449         }
       
   450     }
       
   451 
       
   452     private static File createFile(final File baseDir, final String path) {
   293     private static File createFile(final File baseDir, final String path) {
   453         final File testFile = new File(path);
   294         final File testFile = new File(path);
   454         return testFile.isAbsolute() ?
   295         return testFile.isAbsolute() ?
   455                 testFile : new File(baseDir == null ?
   296                 testFile : new File(baseDir == null ?
   456                         null : baseDir.getAbsolutePath(), path);
   297                         null : baseDir.getAbsolutePath(), path);
   480             }
   321             }
   481             if (!hasClass) {
   322             if (!hasClass) {
   482                 throw new PackagerException("ERR_MissingArgument", "--class");
   323                 throw new PackagerException("ERR_MissingArgument", "--class");
   483             }
   324             }
   484             if (!hasMain) {
   325             if (!hasMain) {
   485                 throw new PackagerException("ERR_MissingArgument", "--main-jar");
   326                 throw new PackagerException("ERR_MissingArgument",
       
   327                         "--main-jar");
   486             }
   328             }
   487         }
   329         }
   488 
   330 
   489         // Validate app image if set
   331         // Validate app image if set
   490         String appImage = (String)bundlerArguments.get(Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
   332         String appImage = (String)bundlerArguments.get(
       
   333                 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
   491         if (appImage != null) {
   334         if (appImage != null) {
   492             File appImageDir = new File(appImage);
   335             File appImageDir = new File(appImage);
   493             if (!appImageDir.exists()) {
   336             if (!appImageDir.exists()) {
   494                 throw new PackagerException("ERR_AppImageNotExist", appImage);
   337                 throw new PackagerException("ERR_AppImageNotExist", appImage);
   495             }
   338             }
   496 
   339 
   497             File appImageAppDir = new File(appImage + File.separator + "app");
   340             File appImageAppDir = new File(appImage + File.separator + "app");
   498             File appImageRuntimeDir = new File(appImage + File.separator + "runtime");
   341             File appImageRuntimeDir = new File(appImage
       
   342                     + File.separator + "runtime");
   499             if (!appImageAppDir.exists() || !appImageRuntimeDir.exists()) {
   343             if (!appImageAppDir.exists() || !appImageRuntimeDir.exists()) {
   500                 throw new PackagerException("ERR_AppImageInvalid", appImage);
   344                 throw new PackagerException("ERR_AppImageInvalid", appImage);
   501             }
   345             }
   502         }
   346         }
   503     }
   347     }
   551             StandardBundlerParam.JVM_OPTIONS.getID(),
   395             StandardBundlerParam.JVM_OPTIONS.getID(),
   552             StandardBundlerParam.ARGUMENTS.getID(),
   396             StandardBundlerParam.ARGUMENTS.getID(),
   553             StandardBundlerParam.MODULE_PATH.getID(),
   397             StandardBundlerParam.MODULE_PATH.getID(),
   554             StandardBundlerParam.ADD_MODULES.getID(),
   398             StandardBundlerParam.ADD_MODULES.getID(),
   555             StandardBundlerParam.LIMIT_MODULES.getID(),
   399             StandardBundlerParam.LIMIT_MODULES.getID(),
   556             StandardBundlerParam.FILE_ASSOCIATIONS.getID(),
   400             StandardBundlerParam.FILE_ASSOCIATIONS.getID()
   557             JLinkBundlerHelper.DETECT_MODULES.getID()
       
   558     ));
   401     ));
   559 
   402 
   560     @SuppressWarnings("unchecked")
   403     @SuppressWarnings("unchecked")
   561     public void addBundleArgument(String key, Object value) {
   404     public void addBundleArgument(String key, Object value) {
   562         // special hack for multi-line arguments
   405         // special hack for multi-line arguments
   584         //construct app resources
   427         //construct app resources
   585         //  relative to output folder!
   428         //  relative to output folder!
   586         String currentOS = System.getProperty("os.name").toLowerCase();
   429         String currentOS = System.getProperty("os.name").toLowerCase();
   587         String currentArch = getArch();
   430         String currentArch = getArch();
   588 
   431 
   589         for (RelativeFileSet rfs : resources) {
       
   590             String os = rfs.getOs();
       
   591             String arch = rfs.getArch();
       
   592             //skip resources for other OS
       
   593             // and nativelib jars (we are including raw libraries)
       
   594             if ((os == null || currentOS.contains(os.toLowerCase())) &&
       
   595                     (arch == null ||
       
   596                     currentArch.startsWith(arch.toLowerCase())) &&
       
   597                     rfs.getType() != RelativeFileSet.Type.nativelib) {
       
   598                 if (rfs.getType() == RelativeFileSet.Type.license) {
       
   599                     for (String s : rfs.getIncludedFiles()) {
       
   600                         bundleParams.addLicenseFile(s);
       
   601                     }
       
   602                 }
       
   603             }
       
   604         }
       
   605 
       
   606         bundleParams.setAppResourcesList(resources);
   432         bundleParams.setAppResourcesList(resources);
   607 
   433 
   608         bundleParams.setIdentifier(id);
   434         bundleParams.setIdentifier(id);
   609 
   435 
   610         if (javaRuntimeWasSet) {
       
   611             bundleParams.setRuntime(javaRuntimeToUse);
       
   612         }
       
   613         bundleParams.setApplicationClass(applicationClass);
   436         bundleParams.setApplicationClass(applicationClass);
   614         bundleParams.setPrelaoderClass(preloader);
       
   615         bundleParams.setName(this.appName);
       
   616         bundleParams.setAppVersion(version);
   437         bundleParams.setAppVersion(version);
   617         bundleParams.setType(bundleType);
   438         bundleParams.setType(bundleType);
   618         bundleParams.setBundleFormat(targetFormat);
   439         bundleParams.setBundleFormat(targetFormat);
   619         bundleParams.setVendor(vendor);
   440         bundleParams.setVendor(vendor);
   620         bundleParams.setEmail(email);
   441         bundleParams.setEmail(email);
   641 
   462 
   642         if (stripNativeCommands != null) {
   463         if (stripNativeCommands != null) {
   643             bundleParams.setStripNativeCommands(stripNativeCommands);
   464             bundleParams.setStripNativeCommands(stripNativeCommands);
   644         }
   465         }
   645 
   466 
   646         bundleParams.setSrcDir(srcdir);
       
   647 
       
   648         if (modulePath != null && !modulePath.isEmpty()) {
   467         if (modulePath != null && !modulePath.isEmpty()) {
   649             bundleParams.setModulePath(modulePath);
   468             bundleParams.setModulePath(modulePath);
   650         }
   469         }
   651 
   470 
   652         if (module != null && !module.isEmpty()) {
   471         if (module != null && !module.isEmpty()) {
   653             bundleParams.setMainModule(module);
   472             bundleParams.setMainModule(module);
   654         }
   473         }
   655 
   474 
   656         if (debugPort != null && !debugPort.isEmpty()) {
   475         if (debugPort != null && !debugPort.isEmpty()) {
   657             bundleParams.setDebug(debugPort);
   476             bundleParams.setDebug(debugPort);
   658         }
       
   659 
       
   660         if (detectmods != null) {
       
   661             bundleParams.setDetectMods(detectmods);
       
   662         }
   477         }
   663 
   478 
   664         Map<String, String> paramsMap = new TreeMap<>();
   479         Map<String, String> paramsMap = new TreeMap<>();
   665         if (params != null) {
   480         if (params != null) {
   666             for (Param p : params) {
   481             for (Param p : params) {