251 return appDir != null; |
251 return appDir != null; |
252 } |
252 } |
253 |
253 |
254 public File bundle(Map<String, ? super Object> params, |
254 public File bundle(Map<String, ? super Object> params, |
255 File outdir) throws PackagerException { |
255 File outdir) throws PackagerException { |
256 if (!outdir.isDirectory() && !outdir.mkdirs()) { |
256 |
257 throw new PackagerException( |
257 IOUtils.writableOutputDir(outdir.toPath()); |
258 "error.cannot-create-output-dir", |
|
259 outdir.getAbsolutePath()); |
|
260 } |
|
261 if (!outdir.canWrite()) { |
|
262 throw new PackagerException( |
|
263 "error.cannot-write-to-output-dir", |
|
264 outdir.getAbsolutePath()); |
|
265 } |
|
266 |
258 |
267 File imageDir = RPM_IMAGE_DIR.fetchFrom(params); |
259 File imageDir = RPM_IMAGE_DIR.fetchFrom(params); |
268 try { |
260 try { |
269 |
261 |
270 imageDir.mkdirs(); |
262 imageDir.mkdirs(); |
307 private boolean prepareProjectConfig(Map<String, ? super Object> params) |
299 private boolean prepareProjectConfig(Map<String, ? super Object> params) |
308 throws IOException { |
300 throws IOException { |
309 Map<String, String> data = createReplacementData(params); |
301 Map<String, String> data = createReplacementData(params); |
310 File rootDir = |
302 File rootDir = |
311 LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params); |
303 LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params); |
|
304 File binDir = new File(rootDir, "bin"); |
312 |
305 |
313 // prepare installer icon |
306 // prepare installer icon |
314 File iconTarget = getConfig_IconFile(rootDir, params); |
307 File iconTarget = getConfig_IconFile(binDir, params); |
315 File icon = LinuxAppBundler.ICON_PNG.fetchFrom(params); |
308 File icon = LinuxAppBundler.ICON_PNG.fetchFrom(params); |
316 if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
309 if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
317 if (icon == null || !icon.exists()) { |
310 if (icon == null || !icon.exists()) { |
318 fetchResource(iconTarget.getName(), |
311 fetchResource(iconTarget.getName(), |
319 I18N.getString("resource.menu-icon"), |
312 I18N.getString("resource.menu-icon"), |
341 data.get("APPLICATION_FS_NAME")); |
334 data.get("APPLICATION_FS_NAME")); |
342 addLauncherData.put("DESKTOP_MIMES", ""); |
335 addLauncherData.put("DESKTOP_MIMES", ""); |
343 |
336 |
344 // prepare desktop shortcut |
337 // prepare desktop shortcut |
345 try (Writer w = Files.newBufferedWriter( |
338 try (Writer w = Files.newBufferedWriter( |
346 getConfig_DesktopShortcutFile(rootDir, |
339 getConfig_DesktopShortcutFile(binDir, |
347 addLauncher).toPath())) { |
340 addLauncher).toPath())) { |
348 String content = preprocessTextResource( |
341 String content = preprocessTextResource( |
349 getConfig_DesktopShortcutFile(rootDir, |
342 getConfig_DesktopShortcutFile(binDir, |
350 addLauncher).getName(), |
343 addLauncher).getName(), |
351 I18N.getString("resource.menu-shortcut-descriptor"), |
344 I18N.getString("resource.menu-shortcut-descriptor"), |
352 DEFAULT_DESKTOP_FILE_TEMPLATE, addLauncherData, |
345 DEFAULT_DESKTOP_FILE_TEMPLATE, addLauncherData, |
353 VERBOSE.fetchFrom(params), |
346 VERBOSE.fetchFrom(params), |
354 RESOURCE_DIR.fetchFrom(params)); |
347 RESOURCE_DIR.fetchFrom(params)); |
355 w.write(content); |
348 w.write(content); |
356 } |
349 } |
357 |
350 |
358 // prepare installer icon |
351 // prepare installer icon |
359 iconTarget = getConfig_IconFile(rootDir, addLauncher); |
352 iconTarget = getConfig_IconFile(binDir, addLauncher); |
360 icon = LinuxAppBundler.ICON_PNG.fetchFrom(addLauncher); |
353 icon = LinuxAppBundler.ICON_PNG.fetchFrom(addLauncher); |
361 if (icon == null || !icon.exists()) { |
354 if (icon == null || !icon.exists()) { |
362 fetchResource(iconTarget.getName(), |
355 fetchResource(iconTarget.getName(), |
363 I18N.getString("resource.menu-icon"), |
356 I18N.getString("resource.menu-icon"), |
364 DEFAULT_ICON, |
357 DEFAULT_ICON, |
486 |
479 |
487 if (faIcon != null && faIcon.exists()) { |
480 if (faIcon != null && faIcon.exists()) { |
488 int size = getSquareSizeOfImage(faIcon); |
481 int size = getSquareSizeOfImage(faIcon); |
489 |
482 |
490 if (size > 0) { |
483 if (size > 0) { |
491 File target = new File(rootDir, |
484 File target = new File(binDir, |
492 APP_NAME.fetchFrom(params) |
485 APP_NAME.fetchFrom(params) |
493 + "_fa_" + faIcon.getName()); |
486 + "_fa_" + faIcon.getName()); |
494 IOUtils.copyFile(faIcon, target); |
487 IOUtils.copyFile(faIcon, target); |
495 |
488 |
496 // xdg-icon-resource install --context mimetypes |
489 // xdg-icon-resource install --context mimetypes |
531 } |
524 } |
532 mimeInfo.append("</mime-info>"); |
525 mimeInfo.append("</mime-info>"); |
533 |
526 |
534 if (addedEntry) { |
527 if (addedEntry) { |
535 try (Writer w = Files.newBufferedWriter( |
528 try (Writer w = Files.newBufferedWriter( |
536 new File(rootDir, mimeInfoFile).toPath())) { |
529 new File(binDir, mimeInfoFile).toPath())) { |
537 w.write(mimeInfo.toString()); |
530 w.write(mimeInfo.toString()); |
538 } |
531 } |
539 data.put("FILE_ASSOCIATION_INSTALL", registrations.toString()); |
532 data.put("FILE_ASSOCIATION_INSTALL", registrations.toString()); |
540 data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString()); |
533 data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString()); |
541 data.put("DESKTOP_MIMES", desktopMimes.toString()); |
534 data.put("DESKTOP_MIMES", desktopMimes.toString()); |
543 } |
536 } |
544 |
537 |
545 if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
538 if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
546 //prepare desktop shortcut |
539 //prepare desktop shortcut |
547 try (Writer w = Files.newBufferedWriter( |
540 try (Writer w = Files.newBufferedWriter( |
548 getConfig_DesktopShortcutFile(rootDir, params).toPath())) { |
541 getConfig_DesktopShortcutFile(binDir, params).toPath())) { |
549 String content = preprocessTextResource( |
542 String content = preprocessTextResource( |
550 getConfig_DesktopShortcutFile(rootDir, |
543 getConfig_DesktopShortcutFile(binDir, |
551 params).getName(), |
544 params).getName(), |
552 I18N.getString("resource.menu-shortcut-descriptor"), |
545 I18N.getString("resource.menu-shortcut-descriptor"), |
553 DEFAULT_DESKTOP_FILE_TEMPLATE, data, |
546 DEFAULT_DESKTOP_FILE_TEMPLATE, data, |
554 VERBOSE.fetchFrom(params), |
547 VERBOSE.fetchFrom(params), |
555 RESOURCE_DIR.fetchFrom(params)); |
548 RESOURCE_DIR.fetchFrom(params)); |
573 } |
566 } |
574 |
567 |
575 private Map<String, String> createReplacementData( |
568 private Map<String, String> createReplacementData( |
576 Map<String, ? super Object> params) throws IOException { |
569 Map<String, ? super Object> params) throws IOException { |
577 Map<String, String> data = new HashMap<>(); |
570 Map<String, String> data = new HashMap<>(); |
|
571 String launcher = LinuxAppImageBuilder.getLauncherRelativePath(params); |
578 |
572 |
579 data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params)); |
573 data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params)); |
580 data.put("APPLICATION_FS_NAME", APP_NAME.fetchFrom(params)); |
574 data.put("APPLICATION_FS_NAME", APP_NAME.fetchFrom(params)); |
581 data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params)); |
575 data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params)); |
582 data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params)); |
576 data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params)); |
583 data.put("APPLICATION_VERSION", VERSION.fetchFrom(params)); |
577 data.put("APPLICATION_VERSION", VERSION.fetchFrom(params)); |
584 data.put("APPLICATION_LAUNCHER_FILENAME", APP_NAME.fetchFrom(params)); |
578 data.put("APPLICATION_LAUNCHER_FILENAME", launcher); |
585 data.put("INSTALLATION_DIRECTORY", LINUX_INSTALL_DIR.fetchFrom(params)); |
579 data.put("INSTALLATION_DIRECTORY", LINUX_INSTALL_DIR.fetchFrom(params)); |
586 data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params)); |
580 data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params)); |
587 data.put("DEPLOY_BUNDLE_CATEGORY", MENU_GROUP.fetchFrom(params)); |
581 data.put("DEPLOY_BUNDLE_CATEGORY", MENU_GROUP.fetchFrom(params)); |
588 data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params)); |
582 data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params)); |
589 data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params)); |
583 data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params)); |