< prev index next >

src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinAppBundler.java

Print this page




  29 import java.io.File;
  30 import java.io.IOException;
  31 import java.io.PrintStream;
  32 import java.nio.file.Path;
  33 import java.text.MessageFormat;
  34 import java.util.Arrays;
  35 import java.util.Collection;
  36 import java.util.Map;
  37 import java.util.ResourceBundle;
  38 
  39 import static jdk.jpackage.internal.WindowsBundlerParam.*;
  40 import static jdk.jpackage.internal.WinMsiBundler.WIN_APP_IMAGE;
  41 
  42 public class WinAppBundler extends AbstractImageBundler {
  43 
  44     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  45             "jdk.jpackage.internal.resources.WinResources");
  46 
  47     static final BundlerParamInfo<File> ICON_ICO =
  48             new StandardBundlerParam<>(
  49             I18N.getString("param.icon-ico.name"),
  50             I18N.getString("param.icon-ico.description"),
  51             "icon.ico",
  52             File.class,
  53             params -> {
  54                 File f = ICON.fetchFrom(params);
  55                 if (f != null && !f.getName().toLowerCase().endsWith(".ico")) {
  56                     Log.error(MessageFormat.format(
  57                             I18N.getString("message.icon-not-ico"), f));
  58                     return null;
  59                 }
  60                 return f;
  61             },
  62             (s, p) -> new File(s));
  63 
  64     @Override
  65     public boolean validate(Map<String, ? super Object> params)
  66             throws UnsupportedPlatformException, ConfigException {
  67         try {
  68             if (params == null) throw new ConfigException(
  69                     I18N.getString("error.parameters-null"),
  70                     I18N.getString("error.parameters-null.advice"));


 154         }
 155 
 156         return APP_NAME.fetchFrom(p);
 157     }
 158 
 159     public static String getLauncherName(Map<String, ? super Object> p) {
 160         return getAppName(p) + ".exe";
 161     }
 162 
 163     public static String getLauncherCfgName(Map<String, ? super Object> p) {
 164         return "app\\" + getAppName(p) +".cfg";
 165     }
 166 
 167     public boolean bundle(Map<String, ? super Object> p, File outputDirectory)
 168             throws PackagerException {
 169         return doBundle(p, outputDirectory, false) != null;
 170     }
 171 
 172     File doBundle(Map<String, ? super Object> p, File outputDirectory,
 173             boolean dependentTask) throws PackagerException {
 174         if (RUNTIME_INSTALLER.fetchFrom(p)) {
 175             return doJreBundle(p, outputDirectory, dependentTask);
 176         } else {
 177             return doAppBundle(p, outputDirectory, dependentTask);
 178         }
 179     }
 180 
 181     File doJreBundle(Map<String, ? super Object> p, File outputDirectory,
 182             boolean dependentTask) throws PackagerException {
 183         try {
 184             File rootDirectory = createRoot(p, outputDirectory, dependentTask,
 185                 APP_NAME.fetchFrom(p), "windowsapp-image-builder");
 186             AbstractAppImageBuilder appBuilder = new WindowsAppImageBuilder(
 187                     APP_NAME.fetchFrom(p),
 188                     outputDirectory.toPath());
 189             File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
 190             if (predefined == null ) {
 191                 JLinkBundlerHelper.generateJre(p, appBuilder);
 192             } else {
 193                 return predefined;
 194             }
 195             return rootDirectory;
 196         } catch (PackagerException pe) {
 197             throw pe;
 198         } catch (Exception e) {
 199             Log.verbose(e);
 200             throw new PackagerException(e);
 201         }
 202     }
 203 
 204     File doAppBundle(Map<String, ? super Object> p, File outputDirectory,
 205             boolean dependentTask) throws PackagerException {
 206         try {
 207             File rootDirectory = createRoot(p, outputDirectory, dependentTask,
 208                     APP_NAME.fetchFrom(p), "windowsapp-image-builder");
 209             AbstractAppImageBuilder appBuilder =
 210                     new WindowsAppImageBuilder(p, outputDirectory.toPath());
 211             if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) {
 212                 JLinkBundlerHelper.execute(p, appBuilder);
 213             } else {
 214                 StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder);
 215             }
 216             if (!dependentTask) {
 217                 Log.verbose(MessageFormat.format(
 218                         I18N.getString("message.result-dir"),
 219                         outputDirectory.getAbsolutePath()));
 220             }
 221             return rootDirectory;
 222         } catch (PackagerException pe) {
 223             throw pe;
 224         } catch (Exception e) {
 225             Log.verbose(e);
 226             throw new PackagerException(e);
 227         }
 228     }




  29 import java.io.File;
  30 import java.io.IOException;
  31 import java.io.PrintStream;
  32 import java.nio.file.Path;
  33 import java.text.MessageFormat;
  34 import java.util.Arrays;
  35 import java.util.Collection;
  36 import java.util.Map;
  37 import java.util.ResourceBundle;
  38 
  39 import static jdk.jpackage.internal.WindowsBundlerParam.*;
  40 import static jdk.jpackage.internal.WinMsiBundler.WIN_APP_IMAGE;
  41 
  42 public class WinAppBundler extends AbstractImageBundler {
  43 
  44     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  45             "jdk.jpackage.internal.resources.WinResources");
  46 
  47     static final BundlerParamInfo<File> ICON_ICO =
  48             new StandardBundlerParam<>(


  49             "icon.ico",
  50             File.class,
  51             params -> {
  52                 File f = ICON.fetchFrom(params);
  53                 if (f != null && !f.getName().toLowerCase().endsWith(".ico")) {
  54                     Log.error(MessageFormat.format(
  55                             I18N.getString("message.icon-not-ico"), f));
  56                     return null;
  57                 }
  58                 return f;
  59             },
  60             (s, p) -> new File(s));
  61 
  62     @Override
  63     public boolean validate(Map<String, ? super Object> params)
  64             throws UnsupportedPlatformException, ConfigException {
  65         try {
  66             if (params == null) throw new ConfigException(
  67                     I18N.getString("error.parameters-null"),
  68                     I18N.getString("error.parameters-null.advice"));


 152         }
 153 
 154         return APP_NAME.fetchFrom(p);
 155     }
 156 
 157     public static String getLauncherName(Map<String, ? super Object> p) {
 158         return getAppName(p) + ".exe";
 159     }
 160 
 161     public static String getLauncherCfgName(Map<String, ? super Object> p) {
 162         return "app\\" + getAppName(p) +".cfg";
 163     }
 164 
 165     public boolean bundle(Map<String, ? super Object> p, File outputDirectory)
 166             throws PackagerException {
 167         return doBundle(p, outputDirectory, false) != null;
 168     }
 169 
 170     File doBundle(Map<String, ? super Object> p, File outputDirectory,
 171             boolean dependentTask) throws PackagerException {
 172         if (StandardBundlerParam.isRuntimeInstaller(p)) {
 173             return PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
 174         } else {
 175             return doAppBundle(p, outputDirectory, dependentTask);
 176         }
 177     }
 178 























 179     File doAppBundle(Map<String, ? super Object> p, File outputDirectory,
 180             boolean dependentTask) throws PackagerException {
 181         try {
 182             File rootDirectory = createRoot(p, outputDirectory, dependentTask,
 183                     APP_NAME.fetchFrom(p));
 184             AbstractAppImageBuilder appBuilder =
 185                     new WindowsAppImageBuilder(p, outputDirectory.toPath());
 186             if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) {
 187                 JLinkBundlerHelper.execute(p, appBuilder);
 188             } else {
 189                 StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder);
 190             }
 191             if (!dependentTask) {
 192                 Log.verbose(MessageFormat.format(
 193                         I18N.getString("message.result-dir"),
 194                         outputDirectory.getAbsolutePath()));
 195             }
 196             return rootDirectory;
 197         } catch (PackagerException pe) {
 198             throw pe;
 199         } catch (Exception e) {
 200             Log.verbose(e);
 201             throw new PackagerException(e);
 202         }
 203     }


< prev index next >