modules/fxpackager/src/main/java/com/oracle/tools/packager/AbstractBundler.java

Print this page




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.oracle.tools.packager;
  27 
  28 import com.oracle.tools.packager.windows.WindowsBundlerParam;
  29 
  30 import java.io.ByteArrayOutputStream;
  31 import java.io.File;
  32 import java.io.IOException;
  33 import java.io.InputStream;
  34 import java.net.URL;
  35 import java.text.MessageFormat;
  36 import java.util.*;
  37 import java.util.regex.Pattern;
  38 
  39 public abstract class AbstractBundler implements Bundler {
  40 
  41     private static final ResourceBundle I18N =
  42             ResourceBundle.getBundle(AbstractBundler.class.getName());
  43 
  44     public static final BundlerParamInfo<File> IMAGES_ROOT = new WindowsBundlerParam<>(
  45             I18N.getString("param.images-root.name"),
  46             I18N.getString("param.images-root.description"),
  47             "imagesRoot",
  48             File.class,
  49             params -> new File(StandardBundlerParam.BUILD_ROOT.fetchFrom(params), "images"),
  50             (s, p) -> null);
  51 
  52     //do not use file separator -
  53     // we use it for classpath lookup and there / are not platform specific
  54     public final static String BUNDLER_PREFIX = "package/";
  55 
  56     protected Class baseResourceLoader = null;
  57     
  58     //helper method to test if required files are present in the runtime
  59     public void testRuntime(RelativeFileSet runtime, String[] file) throws ConfigException {
  60         if (runtime == null) {
  61             return; //null runtime is ok (request to use system)
  62         }
  63 
  64         Pattern[] weave = Arrays.stream(file).map(Pattern::compile).toArray(Pattern[]::new);
  65 
  66         if (!runtime.getIncludedFiles().stream().anyMatch(s ->
  67                 Arrays.stream(weave).anyMatch(pattern -> pattern.matcher(s).matches())
  68         )) {
  69             throw new ConfigException(
  70                     MessageFormat.format(I18N.getString("error.jre-missing-file"), Arrays.toString(file)),
  71                     I18N.getString("error.jre-missing-file.advice"));
  72         }
  73     }
  74 
  75     protected void fetchResource(
  76             String publicName, String category,
  77             String defaultName, File result, boolean verbose, File publicRoot)
  78             throws IOException {
  79         URL u = locateResource(publicName, category, defaultName, verbose, publicRoot);
  80         if (u != null) {
  81             IOUtils.copyFromURL(u, result);
  82         } else {
  83             if (verbose) {
  84                 Log.info(MessageFormat.format(I18N.getString("message.using-default-resource"), category == null ? "" : "[" + category + "] ", publicName));
  85             }
  86         }
  87     }
  88 
  89     protected void fetchResource(
  90             String publicName, String category,
  91             File defaultFile, File result, boolean verbose, File publicRoot)
  92             throws IOException {
  93         URL u = locateResource(publicName, category, null, verbose, publicRoot);
  94         if (u != null) {




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.oracle.tools.packager;
  27 
  28 import com.oracle.tools.packager.windows.WindowsBundlerParam;
  29 
  30 import java.io.ByteArrayOutputStream;
  31 import java.io.File;
  32 import java.io.IOException;
  33 import java.io.InputStream;
  34 import java.net.URL;
  35 import java.text.MessageFormat;
  36 import java.util.*;

  37 
  38 public abstract class AbstractBundler implements Bundler {
  39 
  40     private static final ResourceBundle I18N =
  41             ResourceBundle.getBundle(AbstractBundler.class.getName());
  42 
  43     public static final BundlerParamInfo<File> IMAGES_ROOT = new WindowsBundlerParam<>(
  44             I18N.getString("param.images-root.name"),
  45             I18N.getString("param.images-root.description"),
  46             "imagesRoot",
  47             File.class,
  48             params -> new File(StandardBundlerParam.BUILD_ROOT.fetchFrom(params), "images"),
  49             (s, p) -> null);
  50 
  51     //do not use file separator -
  52     // we use it for classpath lookup and there / are not platform specific
  53     public final static String BUNDLER_PREFIX = "package/";
  54 
  55     protected Class baseResourceLoader = null;
  56     

















  57     protected void fetchResource(
  58             String publicName, String category,
  59             String defaultName, File result, boolean verbose, File publicRoot)
  60             throws IOException {
  61         URL u = locateResource(publicName, category, defaultName, verbose, publicRoot);
  62         if (u != null) {
  63             IOUtils.copyFromURL(u, result);
  64         } else {
  65             if (verbose) {
  66                 Log.info(MessageFormat.format(I18N.getString("message.using-default-resource"), category == null ? "" : "[" + category + "] ", publicName));
  67             }
  68         }
  69     }
  70 
  71     protected void fetchResource(
  72             String publicName, String category,
  73             File defaultFile, File result, boolean verbose, File publicRoot)
  74             throws IOException {
  75         URL u = locateResource(publicName, category, null, verbose, publicRoot);
  76         if (u != null) {