< prev index next >

src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppBundler.java

Print this page




  27 
  28 import java.io.File;
  29 import java.io.IOException;
  30 import java.net.MalformedURLException;
  31 import java.net.URL;
  32 import java.text.MessageFormat;
  33 import java.util.Arrays;
  34 import java.util.Collection;
  35 import java.util.Map;
  36 import java.util.ResourceBundle;
  37 
  38 import static jdk.jpackage.internal.StandardBundlerParam.*;
  39 
  40 public class LinuxAppBundler extends AbstractImageBundler {
  41 
  42     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  43             "jdk.jpackage.internal.resources.LinuxResources");
  44 
  45     public static final BundlerParamInfo<File> ICON_PNG =
  46             new StandardBundlerParam<>(
  47             I18N.getString("param.icon-png.name"),
  48             I18N.getString("param.icon-png.description"),
  49             "icon.png",
  50             File.class,
  51             params -> {
  52                 File f = ICON.fetchFrom(params);
  53                 if (f != null && !f.getName().toLowerCase().endsWith(".png")) {
  54                     Log.error(MessageFormat.format(
  55                             I18N.getString("message.icon-not-png"), f));
  56                     return null;
  57                 }
  58                 return f;
  59             },
  60             (s, p) -> new File(s));
  61 
  62     public static final BundlerParamInfo<String> LINUX_INSTALL_DIR =
  63             new StandardBundlerParam<>(
  64             I18N.getString("param.linux-install-dir.name"),
  65             I18N.getString("param.linux-install-dir.description"),
  66             "linux-install-dir",
  67             String.class,
  68             params -> {
  69                  String dir = INSTALL_DIR.fetchFrom(params);
  70                  if (dir != null) {
  71                      if (dir.endsWith("/")) {
  72                          dir = dir.substring(0, dir.length()-1);
  73                      }
  74                      return dir;
  75                  }
  76                  return "/opt";
  77              },
  78             (s, p) -> s
  79     );
  80 
  81     public static final BundlerParamInfo<String> LINUX_PACKAGE_DEPENDENCIES =
  82             new StandardBundlerParam<>(
  83             I18N.getString("param.linux-package-dependencies.name"),
  84             I18N.getString("param.linux-package-dependencies.description"),
  85             Arguments.CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(),
  86             String.class,
  87             params -> {
  88                  return "";
  89              },
  90             (s, p) -> s
  91     );
  92 
  93     @Override
  94     public boolean validate(Map<String, ? super Object> p)
  95             throws UnsupportedPlatformException, ConfigException {
  96         try {
  97             if (p == null) throw new ConfigException(
  98                     I18N.getString("error.parameters-null"),
  99                     I18N.getString("error.parameters-null.advice"));
 100 
 101             return doValidate(p);
 102         } catch (RuntimeException re) {
 103             if (re.getCause() instanceof ConfigException) {
 104                 throw (ConfigException) re.getCause();


 114             throw new UnsupportedPlatformException();
 115         }
 116 
 117         imageBundleValidation(p);
 118 
 119         return true;
 120     }
 121 
 122     // it is static for the sake of sharing with "installer" bundlers
 123     // that may skip calls to validate/bundle in this class!
 124     public static File getRootDir(File outDir, Map<String, ? super Object> p) {
 125         return new File(outDir, APP_NAME.fetchFrom(p));
 126     }
 127 
 128     public static String getLauncherCfgName(Map<String, ? super Object> p) {
 129         return "app/" + APP_NAME.fetchFrom(p) +".cfg";
 130     }
 131 
 132     File doBundle(Map<String, ? super Object> p, File outputDirectory,
 133             boolean dependentTask) throws PackagerException {
 134         if (RUNTIME_INSTALLER.fetchFrom(p)) {
 135             return doJreBundle(p, outputDirectory, dependentTask);
 136         } else {
 137             return doAppBundle(p, outputDirectory, dependentTask);
 138         }
 139     }
 140 
 141     private File doJreBundle(Map<String, ? super Object> p,
 142             File outputDirectory, boolean dependentTask) throws PackagerException {
 143         try {
 144             File rootDirectory = createRoot(p, outputDirectory, dependentTask,
 145                     APP_NAME.fetchFrom(p), "linuxapp-image-builder");
 146             AbstractAppImageBuilder appBuilder = new LinuxAppImageBuilder(
 147                     APP_NAME.fetchFrom(p), outputDirectory.toPath());
 148             File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
 149             if (predefined == null ) {
 150                 JLinkBundlerHelper.generateJre(p, appBuilder);
 151             } else {
 152                 return predefined;
 153             }
 154             return rootDirectory;
 155         } catch (PackagerException pe) {
 156             throw pe;
 157         } catch (Exception ex) {
 158             Log.verbose(ex);
 159             throw new PackagerException(ex);
 160         }
 161     }
 162 
 163     private File doAppBundle(Map<String, ? super Object> p,
 164             File outputDirectory, boolean dependentTask) throws PackagerException {
 165         try {
 166             File rootDirectory = createRoot(p, outputDirectory, dependentTask,
 167                     APP_NAME.fetchFrom(p), "linuxapp-image-builder");
 168             AbstractAppImageBuilder appBuilder = new LinuxAppImageBuilder(p,
 169                     outputDirectory.toPath());
 170             if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) {
 171                 JLinkBundlerHelper.execute(p, appBuilder);
 172             } else {
 173                 StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder);
 174             }
 175             return rootDirectory;
 176         } catch (PackagerException pe) {
 177             throw pe;
 178         } catch (Exception ex) {
 179             Log.verbose(ex);
 180             throw new PackagerException(ex);
 181         }
 182     }
 183 
 184     @Override
 185     public String getName() {
 186         return I18N.getString("app.bundler.name");
 187     }




  27 
  28 import java.io.File;
  29 import java.io.IOException;
  30 import java.net.MalformedURLException;
  31 import java.net.URL;
  32 import java.text.MessageFormat;
  33 import java.util.Arrays;
  34 import java.util.Collection;
  35 import java.util.Map;
  36 import java.util.ResourceBundle;
  37 
  38 import static jdk.jpackage.internal.StandardBundlerParam.*;
  39 
  40 public class LinuxAppBundler extends AbstractImageBundler {
  41 
  42     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  43             "jdk.jpackage.internal.resources.LinuxResources");
  44 
  45     public static final BundlerParamInfo<File> ICON_PNG =
  46             new StandardBundlerParam<>(


  47             "icon.png",
  48             File.class,
  49             params -> {
  50                 File f = ICON.fetchFrom(params);
  51                 if (f != null && !f.getName().toLowerCase().endsWith(".png")) {
  52                     Log.error(MessageFormat.format(
  53                             I18N.getString("message.icon-not-png"), f));
  54                     return null;
  55                 }
  56                 return f;
  57             },
  58             (s, p) -> new File(s));
  59 
  60     public static final BundlerParamInfo<String> LINUX_INSTALL_DIR =
  61             new StandardBundlerParam<>(


  62             "linux-install-dir",
  63             String.class,
  64             params -> {
  65                  String dir = INSTALL_DIR.fetchFrom(params);
  66                  if (dir != null) {
  67                      if (dir.endsWith("/")) {
  68                          dir = dir.substring(0, dir.length()-1);
  69                      }
  70                      return dir;
  71                  }
  72                  return "/opt";
  73              },
  74             (s, p) -> s
  75     );
  76 
  77     public static final BundlerParamInfo<String> LINUX_PACKAGE_DEPENDENCIES =
  78             new StandardBundlerParam<>(


  79             Arguments.CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(),
  80             String.class,
  81             params -> {
  82                  return "";
  83              },
  84             (s, p) -> s
  85     );
  86 
  87     @Override
  88     public boolean validate(Map<String, ? super Object> p)
  89             throws UnsupportedPlatformException, ConfigException {
  90         try {
  91             if (p == null) throw new ConfigException(
  92                     I18N.getString("error.parameters-null"),
  93                     I18N.getString("error.parameters-null.advice"));
  94 
  95             return doValidate(p);
  96         } catch (RuntimeException re) {
  97             if (re.getCause() instanceof ConfigException) {
  98                 throw (ConfigException) re.getCause();


 108             throw new UnsupportedPlatformException();
 109         }
 110 
 111         imageBundleValidation(p);
 112 
 113         return true;
 114     }
 115 
 116     // it is static for the sake of sharing with "installer" bundlers
 117     // that may skip calls to validate/bundle in this class!
 118     public static File getRootDir(File outDir, Map<String, ? super Object> p) {
 119         return new File(outDir, APP_NAME.fetchFrom(p));
 120     }
 121 
 122     public static String getLauncherCfgName(Map<String, ? super Object> p) {
 123         return "app/" + APP_NAME.fetchFrom(p) +".cfg";
 124     }
 125 
 126     File doBundle(Map<String, ? super Object> p, File outputDirectory,
 127             boolean dependentTask) throws PackagerException {
 128         if (StandardBundlerParam.isRuntimeInstaller(p)) {
 129             return PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
 130         } else {
 131             return doAppBundle(p, outputDirectory, dependentTask);
 132         }
 133     }
 134 






















 135     private File doAppBundle(Map<String, ? super Object> p,
 136             File outputDirectory, boolean dependentTask) throws PackagerException {
 137         try {
 138             File rootDirectory = createRoot(p, outputDirectory, dependentTask,
 139                     APP_NAME.fetchFrom(p));
 140             AbstractAppImageBuilder appBuilder = new LinuxAppImageBuilder(p,
 141                     outputDirectory.toPath());
 142             if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) {
 143                 JLinkBundlerHelper.execute(p, appBuilder);
 144             } else {
 145                 StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder);
 146             }
 147             return rootDirectory;
 148         } catch (PackagerException pe) {
 149             throw pe;
 150         } catch (Exception ex) {
 151             Log.verbose(ex);
 152             throw new PackagerException(ex);
 153         }
 154     }
 155 
 156     @Override
 157     public String getName() {
 158         return I18N.getString("app.bundler.name");
 159     }


< prev index next >