11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
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 hello;
27
28 import com.oracle.tools.packager.Bundler;
29 import com.oracle.tools.packager.Bundlers;
30 import com.oracle.tools.packager.ConfigException;
31 import com.oracle.tools.packager.Log;
32 import com.oracle.tools.packager.RelativeFileSet;
33 import com.oracle.tools.packager.StandardBundlerParam;
34 import com.oracle.tools.packager.UnsupportedPlatformException;
35
36 import java.io.File;
37 import java.io.IOException;
38 import java.util.Arrays;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.LinkedList;
42 import java.util.Map;
43 import java.util.Queue;
44 import java.util.Set;
45 import java.util.TreeMap;
46 import java.util.TreeSet;
47
48 import static com.oracle.tools.packager.StandardBundlerParam.*;
49 import static com.oracle.tools.packager.StandardBundlerParam.ICON;
50 import static com.oracle.tools.packager.StandardBundlerParam.VERBOSE;
60 return;
61 }
62
63 File output = new File(".");
64 Set<String> bundlerIDs = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
65 Map<String, ? super Object> params = new TreeMap<>();
66
67 Queue<String> argsQ = new LinkedList<>(Arrays.asList(args));
68 while (!argsQ.isEmpty()) {
69 String arg = argsQ.remove();
70 switch (arg) {
71 case "-o":
72 output = new File(argsQ.remove());
73 output.mkdirs();
74 break;
75
76 case "-b":
77 params.put(argsQ.remove(), argsQ.remove());
78 break;
79
80 case "-all":
81 // JVM args
82 params.put(StandardBundlerParam.JVM_OPTIONS.getID(), "-Doption.1=bundlerargs\n-Doption.2=bundlerargs\n-Dcollide=jvmoptions");
83 // properties
84 params.put(StandardBundlerParam.JVM_PROPERTIES.getID(), "prop.1=bundlerargs\nprop.2=bundlerargs\ncollide=properties");
85 // userJVM Args
86 params.put(StandardBundlerParam.USER_JVM_OPTIONS.getID(), "-Duser.arg.1\\==bundlerargs\n-Duser.arg.2=\\=bundlerargs\n-Dcollide=\\=userjvmoptions\n-Dcollide\\=jvmoptions=AWESOME");
87 // arguments
88 params.put(StandardBundlerParam.ARGUMENTS.getID(), "argument1\n" +
89 "argument2\n" +
90 "argument3=value\n" +
91 "arg4=with=embedded\n" +
92 "arg5=with=equals=at=end=\n" +
93 "one_equal_at_end=\n" +
94 "=\n" +
95 "\"Prev Arg was just an equals\"\n" +
96 "argument1\n" +
97 "argument1\n" +
98 "argument1");
99 break;
115 }
116 }
117
118 Log.setLogger(new Log.Logger(VERBOSE.fetchFrom(params)));
119
120 Bundlers bundlers = Bundlers.createBundlersInstance();
121
122 for (Bundler bundler : bundlers.getBundlers()) {
123 if (!bundlerIDs.isEmpty()
124 && !bundlerIDs.contains(bundler.getBundleType())
125 && !bundlerIDs.contains(bundler.getID())) {
126 continue;
127 }
128
129 Map<String, Object> bundleParams = new HashMap<>();
130
131 bundleParams.put(BUILD_ROOT.getID(), output);
132
133 File appResourcesDir = new File(".");
134 File fakeMainJar = new File(appResourcesDir, "mainApp.jar");
135 File packagerJar = new File(appResourcesDir, "packager.jar");
136 Set<File> appResources = new HashSet<>(Arrays.asList(fakeMainJar, packagerJar));
137
138 bundleParams.put(APP_NAME.getID(), "DevTest");
139 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager");
140 bundleParams.put(MAIN_JAR.getID(),
141 new RelativeFileSet(fakeMainJar.getParentFile(),
142 new HashSet<>(Arrays.asList(fakeMainJar)))
143 );
144 bundleParams.put(CLASSPATH.getID(), fakeMainJar.getName() + " " + packagerJar.getName());
145 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
146 bundleParams.put(VERBOSE.getID(), true);
147 bundleParams.put(ICON.getID(), "java-logo2.gif");
148
149 bundleParams.putAll(params);
150 try {
151 bundler.validate(bundleParams);
152 } catch (UnsupportedPlatformException upe) {
153 System.out.println("Skipping " + bundler.getID() + " as it is not supported on this platform");
154 continue;
155 } catch (ConfigException ce) {
156 System.out.println("Configuration Error : " + ce.getMessage());
157 System.out.println(" Advice to fix : " + ce.getAdvice());
158 continue;
159 }
160
161 System.out.println("Running bundler for " + bundler.getID());
162 System.out.println(" results at " + bundler.execute(bundleParams, output));
163 }
164 }
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
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 hello;
27
28 import com.oracle.tools.packager.Bundler;
29 import com.oracle.tools.packager.Bundlers;
30 import com.oracle.tools.packager.ConfigException;
31 import com.oracle.tools.packager.JLinkBundlerHelper;
32 import com.oracle.tools.packager.Log;
33 import com.oracle.tools.packager.RelativeFileSet;
34 import com.oracle.tools.packager.StandardBundlerParam;
35 import com.oracle.tools.packager.UnsupportedPlatformException;
36
37 import java.io.File;
38 import java.io.IOException;
39 import java.util.Arrays;
40 import java.util.HashMap;
41 import java.util.HashSet;
42 import java.util.LinkedList;
43 import java.util.Map;
44 import java.util.Queue;
45 import java.util.Set;
46 import java.util.TreeMap;
47 import java.util.TreeSet;
48
49 import static com.oracle.tools.packager.StandardBundlerParam.*;
50 import static com.oracle.tools.packager.StandardBundlerParam.ICON;
51 import static com.oracle.tools.packager.StandardBundlerParam.VERBOSE;
61 return;
62 }
63
64 File output = new File(".");
65 Set<String> bundlerIDs = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
66 Map<String, ? super Object> params = new TreeMap<>();
67
68 Queue<String> argsQ = new LinkedList<>(Arrays.asList(args));
69 while (!argsQ.isEmpty()) {
70 String arg = argsQ.remove();
71 switch (arg) {
72 case "-o":
73 output = new File(argsQ.remove());
74 output.mkdirs();
75 break;
76
77 case "-b":
78 params.put(argsQ.remove(), argsQ.remove());
79 break;
80
81 case "-modulepath":
82 params.put(JLinkBundlerHelper.MODULE_PATH.getID(), argsQ.remove());
83 break;
84
85 case "-all":
86 // JVM args
87 params.put(StandardBundlerParam.JVM_OPTIONS.getID(), "-Doption.1=bundlerargs\n-Doption.2=bundlerargs\n-Dcollide=jvmoptions");
88 // properties
89 params.put(StandardBundlerParam.JVM_PROPERTIES.getID(), "prop.1=bundlerargs\nprop.2=bundlerargs\ncollide=properties");
90 // userJVM Args
91 params.put(StandardBundlerParam.USER_JVM_OPTIONS.getID(), "-Duser.arg.1\\==bundlerargs\n-Duser.arg.2=\\=bundlerargs\n-Dcollide=\\=userjvmoptions\n-Dcollide\\=jvmoptions=AWESOME");
92 // arguments
93 params.put(StandardBundlerParam.ARGUMENTS.getID(), "argument1\n" +
94 "argument2\n" +
95 "argument3=value\n" +
96 "arg4=with=embedded\n" +
97 "arg5=with=equals=at=end=\n" +
98 "one_equal_at_end=\n" +
99 "=\n" +
100 "\"Prev Arg was just an equals\"\n" +
101 "argument1\n" +
102 "argument1\n" +
103 "argument1");
104 break;
120 }
121 }
122
123 Log.setLogger(new Log.Logger(VERBOSE.fetchFrom(params)));
124
125 Bundlers bundlers = Bundlers.createBundlersInstance();
126
127 for (Bundler bundler : bundlers.getBundlers()) {
128 if (!bundlerIDs.isEmpty()
129 && !bundlerIDs.contains(bundler.getBundleType())
130 && !bundlerIDs.contains(bundler.getID())) {
131 continue;
132 }
133
134 Map<String, Object> bundleParams = new HashMap<>();
135
136 bundleParams.put(BUILD_ROOT.getID(), output);
137
138 File appResourcesDir = new File(".");
139 File fakeMainJar = new File(appResourcesDir, "mainApp.jar");
140 Set<File> appResources = new HashSet<>(Arrays.asList(fakeMainJar));
141
142 bundleParams.put(APP_NAME.getID(), "DevTest");
143 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager");
144 bundleParams.put(MAIN_JAR.getID(),
145 new RelativeFileSet(fakeMainJar.getParentFile(),
146 new HashSet<>(Arrays.asList(fakeMainJar)))
147 );
148 bundleParams.put(CLASSPATH.getID(), fakeMainJar.getName());
149 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
150 bundleParams.put(VERBOSE.getID(), true);
151 bundleParams.put(ICON.getID(), "java-logo2.gif");
152
153 bundleParams.putAll(params);
154 try {
155 bundler.validate(bundleParams);
156 } catch (UnsupportedPlatformException upe) {
157 System.out.println("Skipping " + bundler.getID() + " as it is not supported on this platform");
158 continue;
159 } catch (ConfigException ce) {
160 System.out.println("Configuration Error : " + ce.getMessage());
161 System.out.println(" Advice to fix : " + ce.getAdvice());
162 continue;
163 }
164
165 System.out.println("Running bundler for " + bundler.getID());
166 System.out.println(" results at " + bundler.execute(bundleParams, output));
167 }
168 }
|