src/jdk.packager/windows/classes/jdk/packager/internal/windows/WinAppBundler.java
branchJDK-8200758-branch
changeset 56902 6972c0e75e23
parent 56869 41e17fe9fbeb
child 56933 9f59eeb3cc0f
equal deleted inserted replaced
56901:d5992bef7aa9 56902:6972c0e75e23
    49 import java.util.ResourceBundle;
    49 import java.util.ResourceBundle;
    50 import jdk.packager.internal.Arguments;
    50 import jdk.packager.internal.Arguments;
    51 
    51 
    52 import static jdk.packager.internal.windows.WindowsBundlerParam.*;
    52 import static jdk.packager.internal.windows.WindowsBundlerParam.*;
    53 import jdk.packager.internal.builders.AbstractAppImageBuilder;
    53 import jdk.packager.internal.builders.AbstractAppImageBuilder;
       
    54 import static jdk.packager.internal.windows.WinMsiBundler.WIN_APP_IMAGE;
    54 
    55 
    55 public class WinAppBundler extends AbstractImageBundler {
    56 public class WinAppBundler extends AbstractImageBundler {
    56 
    57 
    57     private static final ResourceBundle I18N =
    58     private static final ResourceBundle I18N =
    58             ResourceBundle.getBundle(
    59             ResourceBundle.getBundle(
   151     // that may skip calls to validate/bundle in this class!
   152     // that may skip calls to validate/bundle in this class!
   152     private static File getRootDir(File outDir, Map<String, ? super Object> p) {
   153     private static File getRootDir(File outDir, Map<String, ? super Object> p) {
   153         return new File(outDir, APP_NAME.fetchFrom(p));
   154         return new File(outDir, APP_NAME.fetchFrom(p));
   154     }
   155     }
   155 
   156 
       
   157     private static boolean usePredefineAppName(Map<String, ? super Object> p) {
       
   158         return (PREDEFINED_APP_IMAGE.fetchFrom(p) != null);
       
   159     }
       
   160 
       
   161     private static String appName;
       
   162     private synchronized static String getAppName(Map<String, ? super Object> p) {
       
   163         // If we building from predefined app image, then we should use names
       
   164         // from image and not from CLI.
       
   165         if (usePredefineAppName(p)) {
       
   166             if (appName == null) {
       
   167                 // Use WIN_APP_IMAGE here, since we already copy pre-defined image to WIN_APP_IMAGE
       
   168                 File appImageDir = new File(WIN_APP_IMAGE.fetchFrom(p).toString() + "\\app");
       
   169                 File [] files = appImageDir.listFiles((File dir, String name) -> name.endsWith(".cfg"));
       
   170                 if (files == null || files.length != 1) {
       
   171                     throw new RuntimeException(MessageFormat.format(
       
   172                         I18N.getString("error.cannot-find-cfg"),
       
   173                         appImageDir));
       
   174                 } else {
       
   175                     appName = files[0].getName();
       
   176                     int index = appName.indexOf(".");
       
   177                     if (index != -1) {
       
   178                         appName = appName.substring(0, index);
       
   179                     }
       
   180                 }
       
   181 
       
   182                 return appName;
       
   183             } else {
       
   184                 return appName;
       
   185             }
       
   186         }
       
   187 
       
   188         return APP_NAME.fetchFrom(p);
       
   189     }
       
   190 
   156     public static String getLauncherName(Map<String, ? super Object> p) {
   191     public static String getLauncherName(Map<String, ? super Object> p) {
   157         return APP_NAME.fetchFrom(p) +".exe";
   192         return getAppName(p) + ".exe";
   158     }
   193     }
   159 
   194 
   160     public static String getLauncherCfgName(Map<String, ? super Object> p) {
   195     public static String getLauncherCfgName(Map<String, ? super Object> p) {
   161         return "app\\" + APP_NAME.fetchFrom(p) +".cfg";
   196         return "app\\" + getAppName(p) +".cfg";
   162     }
   197     }
   163 
   198 
   164     public boolean bundle(Map<String, ? super Object> p, File outputDirectory) {
   199     public boolean bundle(Map<String, ? super Object> p, File outputDirectory) {
   165         return doBundle(p, outputDirectory, false) != null;
   200         return doBundle(p, outputDirectory, false) != null;
   166     }
   201     }
   167     
   202 
   168     private File createRoot(Map<String, ? super Object> p,
   203     private File createRoot(Map<String, ? super Object> p,
   169             File outputDirectory, boolean dependentTask) throws IOException {
   204             File outputDirectory, boolean dependentTask) throws IOException {
   170         if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) {
   205         if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) {
   171             throw new RuntimeException(MessageFormat.format(
   206             throw new RuntimeException(MessageFormat.format(
   172                     I18N.getString("error.cannot-create-output-dir"),
   207                     I18N.getString("error.cannot-create-output-dir"),
   336     @Override
   371     @Override
   337     public File execute(
   372     public File execute(
   338             Map<String, ? super Object> params, File outputParentDir) {
   373             Map<String, ? super Object> params, File outputParentDir) {
   339         return doBundle(params, outputParentDir, false);
   374         return doBundle(params, outputParentDir, false);
   340     }
   375     }
   341     
   376 
   342     @Override    
   377     @Override
   343     public boolean supported() {
   378     public boolean supported() {
   344         return (Platform.getPlatform() == Platform.WINDOWS);
   379         return (Platform.getPlatform() == Platform.WINDOWS);
   345     }
   380     }
   346 
   381 
   347 }
   382 }