< prev index next >

src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java

Print this page




  36 import java.text.MessageFormat;
  37 import java.util.Map;
  38 import java.util.ResourceBundle;
  39 
  40 import jdk.jpackage.internal.resources.ResourceLocator;
  41 
  42 /**
  43  * AbstractBundler
  44  *
  45  * This is the base class all Bundlers extend from.
  46  * It contains methods and parameters common to all Bundlers.
  47  * The concrete implementations are in the platform specific Bundlers.
  48  */
  49 public abstract class AbstractBundler implements Bundler {
  50 
  51     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  52             "jdk.jpackage.internal.resources.MainResources");
  53 
  54     public static final BundlerParamInfo<File> IMAGES_ROOT =
  55             new StandardBundlerParam<>(
  56             I18N.getString("param.images-root.name"),
  57             I18N.getString("param.images-root.description"),
  58             "imagesRoot",
  59             File.class,
  60             params -> new File(
  61                 StandardBundlerParam.BUILD_ROOT.fetchFrom(params), "images"),
  62             (s, p) -> null);
  63 
  64     public InputStream getResourceAsStream(String name) {
  65         return ResourceLocator.class.getResourceAsStream(name);
  66     }
  67 
  68     protected void fetchResource(String publicName, String category,
  69             String defaultName, File result, boolean verbose, File publicRoot)
  70             throws IOException {
  71 
  72         InputStream is = streamResource(publicName, category,
  73                 defaultName, verbose, publicRoot);
  74         if (is != null) {
  75             try {
  76                 Files.copy(is, result.toPath(),
  77                         StandardCopyOption.REPLACE_EXISTING);
  78             } finally {
  79                 is.close();
  80             }
  81         } else {


 171 
 172         // substitute
 173         String result = new String(baos.toByteArray());
 174         for (Map.Entry<String, String> e : pairs.entrySet()) {
 175             if (e.getValue() != null) {
 176                 result = result.replace(e.getKey(), e.getValue());
 177             }
 178         }
 179         return result;
 180     }
 181 
 182     @Override
 183     public String toString() {
 184         return getName();
 185     }
 186 
 187     @Override
 188     public void cleanup(Map<String, ? super Object> params) {
 189         try {
 190             IOUtils.deleteRecursive(
 191                     StandardBundlerParam.BUILD_ROOT.fetchFrom(params));
 192         } catch (IOException e) {
 193             Log.debug(e.getMessage());
 194         }
 195     }
 196 }


  36 import java.text.MessageFormat;
  37 import java.util.Map;
  38 import java.util.ResourceBundle;
  39 
  40 import jdk.jpackage.internal.resources.ResourceLocator;
  41 
  42 /**
  43  * AbstractBundler
  44  *
  45  * This is the base class all Bundlers extend from.
  46  * It contains methods and parameters common to all Bundlers.
  47  * The concrete implementations are in the platform specific Bundlers.
  48  */
  49 public abstract class AbstractBundler implements Bundler {
  50 
  51     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  52             "jdk.jpackage.internal.resources.MainResources");
  53 
  54     public static final BundlerParamInfo<File> IMAGES_ROOT =
  55             new StandardBundlerParam<>(


  56             "imagesRoot",
  57             File.class,
  58             params -> new File(
  59                 StandardBundlerParam.TEMP_ROOT.fetchFrom(params), "images"),
  60             (s, p) -> null);
  61 
  62     public InputStream getResourceAsStream(String name) {
  63         return ResourceLocator.class.getResourceAsStream(name);
  64     }
  65 
  66     protected void fetchResource(String publicName, String category,
  67             String defaultName, File result, boolean verbose, File publicRoot)
  68             throws IOException {
  69 
  70         InputStream is = streamResource(publicName, category,
  71                 defaultName, verbose, publicRoot);
  72         if (is != null) {
  73             try {
  74                 Files.copy(is, result.toPath(),
  75                         StandardCopyOption.REPLACE_EXISTING);
  76             } finally {
  77                 is.close();
  78             }
  79         } else {


 169 
 170         // substitute
 171         String result = new String(baos.toByteArray());
 172         for (Map.Entry<String, String> e : pairs.entrySet()) {
 173             if (e.getValue() != null) {
 174                 result = result.replace(e.getKey(), e.getValue());
 175             }
 176         }
 177         return result;
 178     }
 179 
 180     @Override
 181     public String toString() {
 182         return getName();
 183     }
 184 
 185     @Override
 186     public void cleanup(Map<String, ? super Object> params) {
 187         try {
 188             IOUtils.deleteRecursive(
 189                     StandardBundlerParam.TEMP_ROOT.fetchFrom(params));
 190         } catch (IOException e) {
 191             Log.debug(e.getMessage());
 192         }
 193     }
 194 }
< prev index next >