< prev index next >

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

Print this page
rev 9619 : imported patch 9-jake-fxpackager.patch

@@ -30,11 +30,23 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
 import java.nio.file.Files;
 import java.text.MessageFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.ResourceBundle;
+import java.util.Set;
 import java.util.function.BiFunction;
 import java.util.function.Function;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;

@@ -75,14 +87,38 @@
             new StandardBundlerParam<>(
                     I18N.getString("param.app-resources-list.name"),
                     I18N.getString("param.app-resource-list.description"),
                     BundleParams.PARAM_APP_RESOURCES + "List",
                     (Class<List<RelativeFileSet>>) (Object) List.class,
-                    p -> new ArrayList<>(Arrays.asList(APP_RESOURCES.fetchFrom(p))), // Default is appResources, as a single item list
-                    null // no string translation, tool must provide complex type
+                    p -> new ArrayList<>(Collections.singletonList(APP_RESOURCES.fetchFrom(p))), // Default is appResources, as a single item list
+                    StandardBundlerParam::createAppResourcesListFromString
             );
 
+    private static List<RelativeFileSet> createAppResourcesListFromString(String s, Map<String, ? super Object> objectObjectMap) {
+        List<RelativeFileSet> result = new ArrayList<>();
+        for (String path : s.split("[:;]")) {
+            File f = new File(path);
+            if (f.getName().equals("*") || path.endsWith("/") || path.endsWith("\\")) {
+                if (f.getName().equals("*")) {
+                    f = f.getParentFile();
+                }
+                Set<File> theFiles = new HashSet<>();
+                try {
+                    Files.walk(f.toPath())
+                            .filter(Files::isRegularFile)
+                            .forEach(p -> theFiles.add(p.toFile()));
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+                result.add(new RelativeFileSet(f, theFiles));
+            } else {
+                result.add(new RelativeFileSet(f.getParentFile(), Collections.singleton(f)));
+            }
+        }
+        return result;
+    }
+
     public static final StandardBundlerParam<File> ICON =
             new StandardBundlerParam<>(
                     I18N.getString("param.icon-file.name"),
                     I18N.getString("param.icon-file.description"),
                     BundleParams.PARAM_ICON,

@@ -97,10 +133,11 @@
                     I18N.getString("param.main-class.name"),
                     I18N.getString("param.main-class.description"),
                     BundleParams.PARAM_APPLICATION_CLASS,
                     String.class,
                     params -> {
+                        //FIXME sniff modules
                         extractMainClassInfoFromAppResources(params);
                         return (String) params.get(BundleParams.PARAM_APPLICATION_CLASS);
                     },
                     (s, p) -> s
             );

@@ -193,11 +230,11 @@
                     (s, p) -> {
                         for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(p)) {
                             File appResourcesRoot = rfs.getBaseDirectory();
                             File f = new File(appResourcesRoot, s);
                             if (f.exists()) {
-                                return new RelativeFileSet(appResourcesRoot, new LinkedHashSet<>(Arrays.asList(f)));
+                                return new RelativeFileSet(appResourcesRoot, new LinkedHashSet<>(Collections.singletonList(f)));
                             }
                         }
                         throw new IllegalArgumentException(
                                 new ConfigException(
                                         MessageFormat.format(I18N.getString("error.main-jar-does-not-exist"), s),

@@ -417,11 +454,11 @@
                     params -> Collections.<String>emptyList(),
                     (s, p) -> Arrays.asList(s.split(","))
             );
 
     public static final BundlerParamInfo<String> LICENSE_TYPE =
-            new StandardBundlerParam<> (
+            new StandardBundlerParam<>(
                     I18N.getString("param.license-type.name"),
                     I18N.getString("param.license-type.description"),
                     BundleParams.PARAM_LICENSE_TYPE,
                     String.class,
                     params -> I18N.getString("param.license-type.default"),

@@ -605,11 +642,11 @@
             new StandardBundlerParam<>(
                     I18N.getString("param.com-app-cds-root.name"),
                     I18N.getString("param.com-app-cds-root.description"),
                     "commercial.AppCDS.classRoots",
                     (Class<List<String>>)((Object)List.class),
-                    p -> Arrays.asList(MAIN_CLASS.fetchFrom(p)),
+                    p -> Collections.singletonList(MAIN_CLASS.fetchFrom(p)),
                     (s, p) -> Arrays.asList(s.split("[ ,:]"))
             );
 
     public static void extractMainClassInfoFromAppResources(Map<String, ? super Object> params) {
         boolean hasMainClass = params.containsKey(MAIN_CLASS.getID());

@@ -696,11 +733,11 @@
                         }
                         if (!hasMainJar) {
                             if (fnames[0] == null) {
                                 fnames[0] = file.getParentFile().toString();
                             }
-                            params.put(MAIN_JAR.getID(), new RelativeFileSet(new File(fnames[0]), new LinkedHashSet<>(Arrays.asList(file))));
+                            params.put(MAIN_JAR.getID(), new RelativeFileSet(new File(fnames[0]), new LinkedHashSet<>(Collections.singletonList(file))));
                         }
                         if (!hasMainJarClassPath) {
                             String cp = attrs.getValue(Attributes.Name.CLASS_PATH);
                             params.put(CLASSPATH.getID(), cp == null ? "" : cp);
                         }

@@ -761,7 +798,6 @@
             }
         }
         l.add(current.toString());
         return l;
     }
-
 }
< prev index next >