150
151 static final StandardBundlerParam<String> MAIN_CLASS =
152 new StandardBundlerParam<>(
153 Arguments.CLIOptions.APPCLASS.getId(),
154 String.class,
155 params -> {
156 if (isRuntimeInstaller(params)) {
157 return null;
158 }
159 extractMainClassInfoFromAppResources(params);
160 String s = (String) params.get(
161 BundleParams.PARAM_APPLICATION_CLASS);
162 if (s == null) {
163 s = JLinkBundlerHelper.getMainClass(params);
164 }
165 return s;
166 },
167 (s, p) -> s
168 );
169
170 static final StandardBundlerParam<String> APP_NAME =
171 new StandardBundlerParam<>(
172 Arguments.CLIOptions.NAME.getId(),
173 String.class,
174 params -> {
175 String s = MAIN_CLASS.fetchFrom(params);
176 if (s == null) return null;
177
178 int idx = s.lastIndexOf(".");
179 if (idx >= 0) {
180 return s.substring(idx+1);
181 }
182 return s;
183 },
184 (s, p) -> s
185 );
186
187 static final StandardBundlerParam<File> ICON =
188 new StandardBundlerParam<>(
189 Arguments.CLIOptions.ICON.getId(),
190 File.class,
191 params -> null,
192 (s, p) -> new File(s)
193 );
194
195 static final StandardBundlerParam<String> VENDOR =
196 new StandardBundlerParam<>(
197 Arguments.CLIOptions.VENDOR.getId(),
198 String.class,
199 params -> I18N.getString("param.vendor.default"),
200 (s, p) -> s
201 );
202
212
213 static final StandardBundlerParam<String> COPYRIGHT =
214 new StandardBundlerParam<>(
215 Arguments.CLIOptions.COPYRIGHT.getId(),
216 String.class,
217 params -> MessageFormat.format(I18N.getString(
218 "param.copyright.default"), new Date()),
219 (s, p) -> s
220 );
221
222 @SuppressWarnings("unchecked")
223 static final StandardBundlerParam<List<String>> ARGUMENTS =
224 new StandardBundlerParam<>(
225 Arguments.CLIOptions.ARGUMENTS.getId(),
226 (Class<List<String>>) (Object) List.class,
227 params -> Collections.emptyList(),
228 (s, p) -> splitStringWithEscapes(s)
229 );
230
231 @SuppressWarnings("unchecked")
232 static final StandardBundlerParam<List<String>> JVM_OPTIONS =
233 new StandardBundlerParam<>(
234 Arguments.CLIOptions.JAVA_OPTIONS.getId(),
235 (Class<List<String>>) (Object) List.class,
236 params -> Collections.emptyList(),
237 (s, p) -> Arrays.asList(s.split("\n\n"))
238 );
239
240 // note that each bundler is likely to replace this one with
241 // their own converter
242 static final StandardBundlerParam<String> VERSION =
243 new StandardBundlerParam<>(
244 Arguments.CLIOptions.VERSION.getId(),
245 String.class,
246 params -> I18N.getString("param.version.default"),
247 (s, p) -> s
248 );
249
250 @SuppressWarnings("unchecked")
251 public static final StandardBundlerParam<String> LICENSE_FILE =
252 new StandardBundlerParam<>(
284 (s, p) -> null
285 );
286
287 static final StandardBundlerParam<String> IDENTIFIER =
288 new StandardBundlerParam<>(
289 Arguments.CLIOptions.IDENTIFIER.getId(),
290 String.class,
291 params -> {
292 String s = MAIN_CLASS.fetchFrom(params);
293 if (s == null) return null;
294
295 int idx = s.lastIndexOf(".");
296 if (idx >= 1) {
297 return s.substring(0, idx);
298 }
299 return s;
300 },
301 (s, p) -> s
302 );
303
304 static final StandardBundlerParam<String> PREFERENCES_ID =
305 new StandardBundlerParam<>(
306 "preferencesID",
307 String.class,
308 p -> Optional.ofNullable(IDENTIFIER.fetchFrom(p)).
309 orElse("").replace('.', '/'),
310 (s, p) -> s
311 );
312
313 static final StandardBundlerParam<Boolean> VERBOSE =
314 new StandardBundlerParam<>(
315 Arguments.CLIOptions.VERBOSE.getId(),
316 Boolean.class,
317 params -> false,
318 // valueOf(null) is false, and we actually do want null
319 (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
320 true : Boolean.valueOf(s)
321 );
322
323 static final StandardBundlerParam<File> RESOURCE_DIR =
324 new StandardBundlerParam<>(
325 Arguments.CLIOptions.RESOURCE_DIR.getId(),
326 File.class,
327 params -> null,
328 (s, p) -> new File(s)
329 );
330
331 static final BundlerParamInfo<String> INSTALL_DIR =
332 new StandardBundlerParam<>(
333 Arguments.CLIOptions.INSTALL_DIR.getId(),
334 String.class,
335 params -> null,
336 (s, p) -> s
337 );
338
339 static final StandardBundlerParam<File> PREDEFINED_APP_IMAGE =
340 new StandardBundlerParam<>(
341 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId(),
342 File.class,
343 params -> null,
344 (s, p) -> new File(s));
345
346 static final StandardBundlerParam<File> PREDEFINED_RUNTIME_IMAGE =
347 new StandardBundlerParam<>(
348 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId(),
349 File.class,
350 params -> null,
351 (s, p) -> new File(s));
352
353 @SuppressWarnings("unchecked")
354 static final StandardBundlerParam<List<Map<String, ? super Object>>> ADD_LAUNCHERS =
355 new StandardBundlerParam<>(
356 Arguments.CLIOptions.ADD_LAUNCHER.getId(),
357 (Class<List<Map<String, ? super Object>>>) (Object)
358 List.class,
359 params -> new ArrayList<>(1),
360 // valueOf(null) is false, and we actually do want null
361 (s, p) -> null
362 );
363
364 @SuppressWarnings("unchecked")
365 static final StandardBundlerParam
366 <List<Map<String, ? super Object>>> FILE_ASSOCIATIONS =
367 new StandardBundlerParam<>(
368 Arguments.CLIOptions.FILE_ASSOCIATIONS.getId(),
369 (Class<List<Map<String, ? super Object>>>) (Object)
370 List.class,
371 params -> new ArrayList<>(1),
372 // valueOf(null) is false, and we actually do want null
701 result.add(new RelativeFileSet(f.getParentFile(),
702 Collections.singleton(f)));
703 }
704 }
705 return result;
706 }
707
708 private static RelativeFileSet getMainJar(
709 String mainJarValue, Map<String, ? super Object> params) {
710 for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(params)) {
711 File appResourcesRoot = rfs.getBaseDirectory();
712 File mainJarFile = new File(appResourcesRoot, mainJarValue);
713
714 if (mainJarFile.exists()) {
715 return new RelativeFileSet(appResourcesRoot,
716 new LinkedHashSet<>(Collections.singletonList(
717 mainJarFile)));
718 }
719 mainJarFile = new File(mainJarValue);
720 if (mainJarFile.exists()) {
721 // absolute path for main-jar may fail is only legal if
722 // path is within the appResourceRoot directory
723 try {
724 return new RelativeFileSet(appResourcesRoot,
725 new LinkedHashSet<>(Collections.singletonList(
726 mainJarFile)));
727 } catch (Exception e) {
728 // if not within, RelativeFileSet constructor throws a
729 // RuntimeException, but the IllegalArgumentException
730 // below contains a more explicit error message.
731 }
732 } else {
733 List<Path> modulePath = MODULE_PATH.fetchFrom(params);
734 modulePath.removeAll(getDefaultModulePath());
735 if (!modulePath.isEmpty()) {
736 Path modularJarPath = JLinkBundlerHelper.findPathOfModule(
737 modulePath, mainJarValue);
738 if (modularJarPath != null &&
739 Files.exists(modularJarPath)) {
740 return new RelativeFileSet(appResourcesRoot,
741 new LinkedHashSet<>(Collections.singletonList(
742 modularJarPath.toFile())));
743 }
744 }
745 }
746 }
747
748 throw new IllegalArgumentException(
749 new ConfigException(MessageFormat.format(I18N.getString(
750 "error.main-jar-does-not-exist"),
751 mainJarValue), I18N.getString(
|
150
151 static final StandardBundlerParam<String> MAIN_CLASS =
152 new StandardBundlerParam<>(
153 Arguments.CLIOptions.APPCLASS.getId(),
154 String.class,
155 params -> {
156 if (isRuntimeInstaller(params)) {
157 return null;
158 }
159 extractMainClassInfoFromAppResources(params);
160 String s = (String) params.get(
161 BundleParams.PARAM_APPLICATION_CLASS);
162 if (s == null) {
163 s = JLinkBundlerHelper.getMainClass(params);
164 }
165 return s;
166 },
167 (s, p) -> s
168 );
169
170 static final StandardBundlerParam<File> PREDEFINED_RUNTIME_IMAGE =
171 new StandardBundlerParam<>(
172 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId(),
173 File.class,
174 params -> null,
175 (s, p) -> new File(s)
176 );
177
178 static final StandardBundlerParam<String> APP_NAME =
179 new StandardBundlerParam<>(
180 Arguments.CLIOptions.NAME.getId(),
181 String.class,
182 params -> {
183 String s = MAIN_CLASS.fetchFrom(params);
184 if (s != null) {
185 int idx = s.lastIndexOf(".");
186 if (idx >= 0) {
187 return s.substring(idx+1);
188 }
189 return s;
190 } else if (isRuntimeInstaller(params)) {
191 File f = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
192 if (f != null) {
193 return f.getName();
194 }
195 }
196 return null;
197 },
198 (s, p) -> s
199 );
200
201 static final StandardBundlerParam<File> ICON =
202 new StandardBundlerParam<>(
203 Arguments.CLIOptions.ICON.getId(),
204 File.class,
205 params -> null,
206 (s, p) -> new File(s)
207 );
208
209 static final StandardBundlerParam<String> VENDOR =
210 new StandardBundlerParam<>(
211 Arguments.CLIOptions.VENDOR.getId(),
212 String.class,
213 params -> I18N.getString("param.vendor.default"),
214 (s, p) -> s
215 );
216
226
227 static final StandardBundlerParam<String> COPYRIGHT =
228 new StandardBundlerParam<>(
229 Arguments.CLIOptions.COPYRIGHT.getId(),
230 String.class,
231 params -> MessageFormat.format(I18N.getString(
232 "param.copyright.default"), new Date()),
233 (s, p) -> s
234 );
235
236 @SuppressWarnings("unchecked")
237 static final StandardBundlerParam<List<String>> ARGUMENTS =
238 new StandardBundlerParam<>(
239 Arguments.CLIOptions.ARGUMENTS.getId(),
240 (Class<List<String>>) (Object) List.class,
241 params -> Collections.emptyList(),
242 (s, p) -> splitStringWithEscapes(s)
243 );
244
245 @SuppressWarnings("unchecked")
246 static final StandardBundlerParam<List<String>> JAVA_OPTIONS =
247 new StandardBundlerParam<>(
248 Arguments.CLIOptions.JAVA_OPTIONS.getId(),
249 (Class<List<String>>) (Object) List.class,
250 params -> Collections.emptyList(),
251 (s, p) -> Arrays.asList(s.split("\n\n"))
252 );
253
254 // note that each bundler is likely to replace this one with
255 // their own converter
256 static final StandardBundlerParam<String> VERSION =
257 new StandardBundlerParam<>(
258 Arguments.CLIOptions.VERSION.getId(),
259 String.class,
260 params -> I18N.getString("param.version.default"),
261 (s, p) -> s
262 );
263
264 @SuppressWarnings("unchecked")
265 public static final StandardBundlerParam<String> LICENSE_FILE =
266 new StandardBundlerParam<>(
298 (s, p) -> null
299 );
300
301 static final StandardBundlerParam<String> IDENTIFIER =
302 new StandardBundlerParam<>(
303 Arguments.CLIOptions.IDENTIFIER.getId(),
304 String.class,
305 params -> {
306 String s = MAIN_CLASS.fetchFrom(params);
307 if (s == null) return null;
308
309 int idx = s.lastIndexOf(".");
310 if (idx >= 1) {
311 return s.substring(0, idx);
312 }
313 return s;
314 },
315 (s, p) -> s
316 );
317
318 static final StandardBundlerParam<Boolean> VERBOSE =
319 new StandardBundlerParam<>(
320 Arguments.CLIOptions.VERBOSE.getId(),
321 Boolean.class,
322 params -> false,
323 // valueOf(null) is false, and we actually do want null
324 (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
325 true : Boolean.valueOf(s)
326 );
327
328 static final StandardBundlerParam<File> RESOURCE_DIR =
329 new StandardBundlerParam<>(
330 Arguments.CLIOptions.RESOURCE_DIR.getId(),
331 File.class,
332 params -> null,
333 (s, p) -> new File(s)
334 );
335
336 static final BundlerParamInfo<String> INSTALL_DIR =
337 new StandardBundlerParam<>(
338 Arguments.CLIOptions.INSTALL_DIR.getId(),
339 String.class,
340 params -> null,
341 (s, p) -> s
342 );
343
344 static final StandardBundlerParam<File> PREDEFINED_APP_IMAGE =
345 new StandardBundlerParam<>(
346 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId(),
347 File.class,
348 params -> null,
349 (s, p) -> new File(s));
350
351 @SuppressWarnings("unchecked")
352 static final StandardBundlerParam<List<Map<String, ? super Object>>> ADD_LAUNCHERS =
353 new StandardBundlerParam<>(
354 Arguments.CLIOptions.ADD_LAUNCHER.getId(),
355 (Class<List<Map<String, ? super Object>>>) (Object)
356 List.class,
357 params -> new ArrayList<>(1),
358 // valueOf(null) is false, and we actually do want null
359 (s, p) -> null
360 );
361
362 @SuppressWarnings("unchecked")
363 static final StandardBundlerParam
364 <List<Map<String, ? super Object>>> FILE_ASSOCIATIONS =
365 new StandardBundlerParam<>(
366 Arguments.CLIOptions.FILE_ASSOCIATIONS.getId(),
367 (Class<List<Map<String, ? super Object>>>) (Object)
368 List.class,
369 params -> new ArrayList<>(1),
370 // valueOf(null) is false, and we actually do want null
699 result.add(new RelativeFileSet(f.getParentFile(),
700 Collections.singleton(f)));
701 }
702 }
703 return result;
704 }
705
706 private static RelativeFileSet getMainJar(
707 String mainJarValue, Map<String, ? super Object> params) {
708 for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(params)) {
709 File appResourcesRoot = rfs.getBaseDirectory();
710 File mainJarFile = new File(appResourcesRoot, mainJarValue);
711
712 if (mainJarFile.exists()) {
713 return new RelativeFileSet(appResourcesRoot,
714 new LinkedHashSet<>(Collections.singletonList(
715 mainJarFile)));
716 }
717 mainJarFile = new File(mainJarValue);
718 if (mainJarFile.exists()) {
719 // absolute path for main-jar may fail is not legal
720 // below contains explicit error message.
721 } else {
722 List<Path> modulePath = MODULE_PATH.fetchFrom(params);
723 modulePath.removeAll(getDefaultModulePath());
724 if (!modulePath.isEmpty()) {
725 Path modularJarPath = JLinkBundlerHelper.findPathOfModule(
726 modulePath, mainJarValue);
727 if (modularJarPath != null &&
728 Files.exists(modularJarPath)) {
729 return new RelativeFileSet(appResourcesRoot,
730 new LinkedHashSet<>(Collections.singletonList(
731 modularJarPath.toFile())));
732 }
733 }
734 }
735 }
736
737 throw new IllegalArgumentException(
738 new ConfigException(MessageFormat.format(I18N.getString(
739 "error.main-jar-does-not-exist"),
740 mainJarValue), I18N.getString(
|