< prev index next >

src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java

Print this page




  32 import java.nio.file.attribute.PosixFilePermission;
  33 import java.nio.file.attribute.PosixFilePermissions;
  34 import java.text.MessageFormat;
  35 import java.util.*;
  36 import java.util.logging.Level;
  37 import java.util.logging.Logger;
  38 import java.util.regex.Matcher;
  39 import java.util.regex.Pattern;
  40 
  41 import static jdk.jpackage.internal.StandardBundlerParam.*;
  42 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
  43 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
  44 
  45 public class LinuxRpmBundler extends AbstractBundler {
  46 
  47     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  48             "jdk.jpackage.internal.resources.LinuxResources");
  49 
  50     public static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER =
  51             new StandardBundlerParam<>(
  52             I18N.getString("param.rpm-app-bundler.name"),
  53             I18N.getString("param.rpm-app-bundler.description"),
  54             "linux.app.bundler",
  55             LinuxAppBundler.class,
  56             params -> new LinuxAppBundler(),
  57             null);
  58 
  59     public static final BundlerParamInfo<File> RPM_IMAGE_DIR =
  60             new StandardBundlerParam<>(
  61             I18N.getString("param.image-dir.name"),
  62             I18N.getString("param.image-dir.description"),
  63             "linux.rpm.imageDir",
  64             File.class,
  65             params -> {
  66                 File imagesRoot = IMAGES_ROOT.fetchFrom(params);
  67                 if (!imagesRoot.exists()) imagesRoot.mkdirs();
  68                 return new File(imagesRoot, "linux-rpm.image");
  69             },
  70             (s, p) -> new File(s));
  71 
  72     // Fedora rules for package naming are used here
  73     // https://fedoraproject.org/wiki/Packaging:NamingGuidelines?rd=Packaging/NamingGuidelines
  74     //
  75     // all Fedora packages must be named using only the following ASCII
  76     // characters. These characters are displayed here:
  77     //
  78     // abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._+
  79     //
  80     private static final Pattern RPM_BUNDLE_NAME_PATTERN =
  81             Pattern.compile("[a-z\\d\\+\\-\\.\\_]+", Pattern.CASE_INSENSITIVE);
  82 
  83     public static final BundlerParamInfo<String> BUNDLE_NAME =
  84             new StandardBundlerParam<> (
  85             I18N.getString("param.bundle-name.name"),
  86             I18N.getString("param.bundle-name.description"),
  87             Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(),
  88             String.class,
  89             params -> {
  90                 String nm = APP_NAME.fetchFrom(params);
  91                 if (nm == null) return null;
  92 
  93                 // make sure to lower case and spaces become dashes
  94                 nm = nm.toLowerCase().replaceAll("[ ]", "-");
  95 
  96                 return nm;
  97             },
  98             (s, p) -> {
  99                 if (!RPM_BUNDLE_NAME_PATTERN.matcher(s).matches()) {
 100                     String msgKey = "error.invalid-value-for-package-name";
 101                     throw new IllegalArgumentException(
 102                             new ConfigException(MessageFormat.format(
 103                                     I18N.getString(msgKey), s),
 104                                     I18N.getString(msgKey + ".advice")));
 105                 }
 106 
 107                 return s;
 108             }
 109         );
 110 
 111     public static final BundlerParamInfo<String> LICENSE_TYPE =
 112         new StandardBundlerParam<>(
 113                 I18N.getString("param.license-type.name"),
 114                 I18N.getString("param.license-type.description"),
 115                 Arguments.CLIOptions.LINUX_RPM_LICENSE_TYPE.getId(),
 116                 String.class,
 117                 params -> I18N.getString("param.license-type.default"),
 118                 (s, p) -> s
 119         );
 120 
 121     public static final BundlerParamInfo<String> XDG_FILE_PREFIX =
 122             new StandardBundlerParam<> (
 123             I18N.getString("param.xdg-prefix.name"),
 124             I18N.getString("param.xdg-prefix.description"),
 125             "linux.xdg-prefix",
 126             String.class,
 127             params -> {
 128                 try {
 129                     String vendor;
 130                     if (params.containsKey(VENDOR.getID())) {
 131                         vendor = VENDOR.fetchFrom(params);
 132                     } else {
 133                         vendor = "jpackage";
 134                     }
 135                     String appName = APP_NAME.fetchFrom(params);
 136 
 137                     return (vendor + "-" + appName).replaceAll("\\s", "");
 138                 } catch (Exception e) {
 139                     if (Log.isDebug()) {
 140                         e.printStackTrace();
 141                     }
 142                 }
 143                 return "unknown-MimeInfo.xml";
 144             },


 299             sb.append("%license ");
 300             sb.append(LINUX_INSTALL_DIR.fetchFrom(params));
 301             sb.append("/");
 302             sb.append(APP_NAME.fetchFrom(params));
 303             sb.append("/app/");
 304             sb.append(licenseFile.getName());
 305         }
 306 
 307         return sb.toString();
 308     }
 309 
 310     private boolean prepareProjectConfig(Map<String, ? super Object> params)
 311             throws IOException {
 312         Map<String, String> data = createReplacementData(params);
 313         File rootDir =
 314             LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params);
 315 
 316         // prepare installer icon
 317         File iconTarget = getConfig_IconFile(rootDir, params);
 318         File icon = LinuxAppBundler.ICON_PNG.fetchFrom(params);
 319         if (!RUNTIME_INSTALLER.fetchFrom(params)) {
 320             if (icon == null || !icon.exists()) {
 321                 fetchResource(iconTarget.getName(),
 322                         I18N.getString("resource.menu-icon"),
 323                         DEFAULT_ICON,
 324                         iconTarget,
 325                         VERBOSE.fetchFrom(params),
 326                         RESOURCE_DIR.fetchFrom(params));
 327             } else {
 328                 fetchResource(iconTarget.getName(),
 329                         I18N.getString("resource.menu-icon"),
 330                         icon,
 331                         iconTarget,
 332                         VERBOSE.fetchFrom(params),
 333                         RESOURCE_DIR.fetchFrom(params));
 334             }
 335         }
 336 
 337         StringBuilder installScripts = new StringBuilder();
 338         StringBuilder removeScripts = new StringBuilder();
 339         for (Map<String, ? super Object> secondaryLauncher :
 340                 SECONDARY_LAUNCHERS.fetchFrom(params)) {
 341             Map<String, String> secondaryLauncherData =
 342                     createReplacementData(secondaryLauncher);
 343             secondaryLauncherData.put("APPLICATION_FS_NAME",
 344                     data.get("APPLICATION_FS_NAME"));
 345             secondaryLauncherData.put("DESKTOP_MIMES", "");
 346 
 347             // prepare desktop shortcut
 348             Writer w = new BufferedWriter(new FileWriter(
 349                     getConfig_DesktopShortcutFile(rootDir, secondaryLauncher)));
 350             String content = preprocessTextResource(
 351                     getConfig_DesktopShortcutFile(rootDir,
 352                     secondaryLauncher).getName(),
 353                     I18N.getString("resource.menu-shortcut-descriptor"),
 354                     DEFAULT_DESKTOP_FILE_TEMPLATE, secondaryLauncherData,
 355                     VERBOSE.fetchFrom(params),
 356                     RESOURCE_DIR.fetchFrom(params));
 357             w.write(content);
 358             w.close();
 359 
 360             // prepare installer icon
 361             iconTarget = getConfig_IconFile(rootDir, secondaryLauncher);
 362             icon = LinuxAppBundler.ICON_PNG.fetchFrom(secondaryLauncher);
 363             if (icon == null || !icon.exists()) {
 364                 fetchResource(iconTarget.getName(),
 365                         I18N.getString("resource.menu-icon"),
 366                         DEFAULT_ICON,
 367                         iconTarget,
 368                         VERBOSE.fetchFrom(params),
 369                         RESOURCE_DIR.fetchFrom(params));
 370             } else {
 371                 fetchResource(iconTarget.getName(),
 372                         I18N.getString("resource.menu-icon"),
 373                         icon,
 374                         iconTarget,
 375                         VERBOSE.fetchFrom(params),
 376                         RESOURCE_DIR.fetchFrom(params));
 377             }
 378 
 379             // post copying of desktop icon
 380             installScripts.append("xdg-desktop-menu install --novendor ");
 381             installScripts.append(LINUX_INSTALL_DIR.fetchFrom(params));
 382             installScripts.append("/");
 383             installScripts.append(data.get("APPLICATION_FS_NAME"));
 384             installScripts.append("/");
 385             installScripts.append(secondaryLauncherData.get(
 386                     "APPLICATION_LAUNCHER_FILENAME"));
 387             installScripts.append(".desktop\n");
 388 
 389             // preun cleanup of desktop icon
 390             removeScripts.append("xdg-desktop-menu uninstall --novendor ");
 391             removeScripts.append(LINUX_INSTALL_DIR.fetchFrom(params));
 392             removeScripts.append("/");
 393             removeScripts.append(data.get("APPLICATION_FS_NAME"));
 394             removeScripts.append("/");
 395             removeScripts.append(secondaryLauncherData.get(
 396                     "APPLICATION_LAUNCHER_FILENAME"));
 397             removeScripts.append(".desktop\n");
 398 
 399         }
 400         data.put("SECONDARY_LAUNCHERS_INSTALL", installScripts.toString());
 401         data.put("SECONDARY_LAUNCHERS_REMOVE", removeScripts.toString());
 402 
 403         StringBuilder cdsScript = new StringBuilder();
 404 
 405         data.put("APP_CDS_CACHE", cdsScript.toString());
 406 
 407         List<Map<String, ? super Object>> associations =
 408                 FILE_ASSOCIATIONS.fetchFrom(params);
 409         data.put("FILE_ASSOCIATION_INSTALL", "");
 410         data.put("FILE_ASSOCIATION_REMOVE", "");
 411         data.put("DESKTOP_MIMES", "");
 412         if (associations != null) {
 413             String mimeInfoFile = XDG_FILE_PREFIX.fetchFrom(params)
 414                     + "-MimeInfo.xml";
 415             StringBuilder mimeInfo = new StringBuilder(
 416                 "<?xml version=\"1.0\"?>\n<mime-info xmlns="
 417                 +"'http://www.freedesktop.org/standards/shared-mime-info'>\n");
 418             StringBuilder registrations = new StringBuilder();
 419             StringBuilder deregistrations = new StringBuilder();
 420             StringBuilder desktopMimes = new StringBuilder("MimeType=");
 421             boolean addedEntry = false;


 527                                 .append(target.getName())
 528                                 .append(" ")
 529                                 .append(dashMime)
 530                                 .append("\n");
 531                     }
 532                 }
 533             }
 534             mimeInfo.append("</mime-info>");
 535 
 536             if (addedEntry) {
 537                 Writer w = new BufferedWriter(new FileWriter(
 538                         new File(rootDir, mimeInfoFile)));
 539                 w.write(mimeInfo.toString());
 540                 w.close();
 541                 data.put("FILE_ASSOCIATION_INSTALL", registrations.toString());
 542                 data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString());
 543                 data.put("DESKTOP_MIMES", desktopMimes.toString());
 544             }
 545         }
 546 
 547         if (!RUNTIME_INSTALLER.fetchFrom(params)) {
 548             //prepare desktop shortcut
 549             Writer w = new BufferedWriter(new FileWriter(
 550                     getConfig_DesktopShortcutFile(rootDir, params)));
 551             String content = preprocessTextResource(
 552                     getConfig_DesktopShortcutFile(rootDir, params).getName(),
 553                     I18N.getString("resource.menu-shortcut-descriptor"),
 554                     DEFAULT_DESKTOP_FILE_TEMPLATE, data,
 555                     VERBOSE.fetchFrom(params),
 556                     RESOURCE_DIR.fetchFrom(params));
 557             w.write(content);
 558             w.close();
 559         }
 560 
 561         // prepare spec file
 562         Writer w = new BufferedWriter(
 563                 new FileWriter(getConfig_SpecFile(params)));
 564         String content = preprocessTextResource(
 565                 getConfig_SpecFile(params).getName(),
 566                 I18N.getString("resource.rpm-spec-file"),
 567                 DEFAULT_SPEC_TEMPLATE, data,


 578         Map<String, String> data = new HashMap<>();
 579 
 580         data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params));
 581         data.put("APPLICATION_FS_NAME", APP_NAME.fetchFrom(params));
 582         data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params));
 583         data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params));
 584         data.put("APPLICATION_VERSION", VERSION.fetchFrom(params));
 585         data.put("APPLICATION_LAUNCHER_FILENAME", APP_NAME.fetchFrom(params));
 586         data.put("INSTALLATION_DIRECTORY", LINUX_INSTALL_DIR.fetchFrom(params));
 587         data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params));
 588         data.put("DEPLOY_BUNDLE_CATEGORY", CATEGORY.fetchFrom(params));
 589         // TODO rpm categories
 590         data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
 591         data.put("APPLICATION_SUMMARY", TITLE.fetchFrom(params));
 592         data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params));
 593         data.put("APPLICATION_LICENSE_FILE", getLicenseFileString(params));
 594         String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
 595         data.put("PACKAGE_DEPENDENCIES",
 596                 deps.isEmpty() ? "" : "Requires: " + deps);
 597         data.put("RUNTIME_INSTALLER",
 598                 RUNTIME_INSTALLER.fetchFrom(params).toString());
 599         return data;
 600     }
 601 
 602     private File getConfig_DesktopShortcutFile(File rootDir,
 603             Map<String, ? super Object> params) {
 604         return new File(rootDir, APP_NAME.fetchFrom(params) + ".desktop");
 605     }
 606 
 607     private File getConfig_IconFile(File rootDir,
 608             Map<String, ? super Object> params) {
 609         return new File(rootDir, APP_NAME.fetchFrom(params) + ".png");
 610     }
 611 
 612     private File getConfig_SpecFile(Map<String, ? super Object> params) {
 613         return new File(RPM_IMAGE_DIR.fetchFrom(params),
 614                 APP_NAME.fetchFrom(params) + ".spec");
 615     }
 616 
 617     private File buildRPM(Map<String, ? super Object> params,
 618             File outdir) throws IOException {
 619         Log.verbose(MessageFormat.format(I18N.getString(
 620                 "message.outputting-bundle-location"),
 621                 outdir.getAbsolutePath()));
 622 
 623         File broot = new File(BUILD_ROOT.fetchFrom(params), "rmpbuildroot");
 624 
 625         outdir.mkdirs();
 626 
 627         //run rpmbuild
 628         ProcessBuilder pb = new ProcessBuilder(
 629                 TOOL_RPMBUILD,
 630                 "-bb", getConfig_SpecFile(params).getAbsolutePath(),
 631                 "--define", "%_sourcedir "
 632                         + RPM_IMAGE_DIR.fetchFrom(params).getAbsolutePath(),
 633                 // save result to output dir
 634                 "--define", "%_rpmdir " + outdir.getAbsolutePath(),
 635                 // do not use other system directories to build as current user
 636                 "--define", "%_topdir " + broot.getAbsolutePath()
 637         );
 638         pb = pb.directory(RPM_IMAGE_DIR.fetchFrom(params));
 639         IOUtils.exec(pb, false);
 640 
 641         Log.verbose(MessageFormat.format(
 642                 I18N.getString("message.output-bundle-location"),
 643                 outdir.getAbsolutePath()));




  32 import java.nio.file.attribute.PosixFilePermission;
  33 import java.nio.file.attribute.PosixFilePermissions;
  34 import java.text.MessageFormat;
  35 import java.util.*;
  36 import java.util.logging.Level;
  37 import java.util.logging.Logger;
  38 import java.util.regex.Matcher;
  39 import java.util.regex.Pattern;
  40 
  41 import static jdk.jpackage.internal.StandardBundlerParam.*;
  42 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
  43 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
  44 
  45 public class LinuxRpmBundler extends AbstractBundler {
  46 
  47     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  48             "jdk.jpackage.internal.resources.LinuxResources");
  49 
  50     public static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER =
  51             new StandardBundlerParam<>(


  52             "linux.app.bundler",
  53             LinuxAppBundler.class,
  54             params -> new LinuxAppBundler(),
  55             null);
  56 
  57     public static final BundlerParamInfo<File> RPM_IMAGE_DIR =
  58             new StandardBundlerParam<>(


  59             "linux.rpm.imageDir",
  60             File.class,
  61             params -> {
  62                 File imagesRoot = IMAGES_ROOT.fetchFrom(params);
  63                 if (!imagesRoot.exists()) imagesRoot.mkdirs();
  64                 return new File(imagesRoot, "linux-rpm.image");
  65             },
  66             (s, p) -> new File(s));
  67 
  68     // Fedora rules for package naming are used here
  69     // https://fedoraproject.org/wiki/Packaging:NamingGuidelines?rd=Packaging/NamingGuidelines
  70     //
  71     // all Fedora packages must be named using only the following ASCII
  72     // characters. These characters are displayed here:
  73     //
  74     // abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._+
  75     //
  76     private static final Pattern RPM_BUNDLE_NAME_PATTERN =
  77             Pattern.compile("[a-z\\d\\+\\-\\.\\_]+", Pattern.CASE_INSENSITIVE);
  78 
  79     public static final BundlerParamInfo<String> BUNDLE_NAME =
  80             new StandardBundlerParam<> (


  81             Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(),
  82             String.class,
  83             params -> {
  84                 String nm = APP_NAME.fetchFrom(params);
  85                 if (nm == null) return null;
  86 
  87                 // make sure to lower case and spaces become dashes
  88                 nm = nm.toLowerCase().replaceAll("[ ]", "-");
  89 
  90                 return nm;
  91             },
  92             (s, p) -> {
  93                 if (!RPM_BUNDLE_NAME_PATTERN.matcher(s).matches()) {
  94                     String msgKey = "error.invalid-value-for-package-name";
  95                     throw new IllegalArgumentException(
  96                             new ConfigException(MessageFormat.format(
  97                                     I18N.getString(msgKey), s),
  98                                     I18N.getString(msgKey + ".advice")));
  99                 }
 100 
 101                 return s;
 102             }
 103         );
 104 
 105     public static final BundlerParamInfo<String> LICENSE_TYPE =
 106         new StandardBundlerParam<>(


 107                 Arguments.CLIOptions.LINUX_RPM_LICENSE_TYPE.getId(),
 108                 String.class,
 109                 params -> I18N.getString("param.license-type.default"),
 110                 (s, p) -> s
 111         );
 112 
 113     public static final BundlerParamInfo<String> XDG_FILE_PREFIX =
 114             new StandardBundlerParam<> (


 115             "linux.xdg-prefix",
 116             String.class,
 117             params -> {
 118                 try {
 119                     String vendor;
 120                     if (params.containsKey(VENDOR.getID())) {
 121                         vendor = VENDOR.fetchFrom(params);
 122                     } else {
 123                         vendor = "jpackage";
 124                     }
 125                     String appName = APP_NAME.fetchFrom(params);
 126 
 127                     return (vendor + "-" + appName).replaceAll("\\s", "");
 128                 } catch (Exception e) {
 129                     if (Log.isDebug()) {
 130                         e.printStackTrace();
 131                     }
 132                 }
 133                 return "unknown-MimeInfo.xml";
 134             },


 289             sb.append("%license ");
 290             sb.append(LINUX_INSTALL_DIR.fetchFrom(params));
 291             sb.append("/");
 292             sb.append(APP_NAME.fetchFrom(params));
 293             sb.append("/app/");
 294             sb.append(licenseFile.getName());
 295         }
 296 
 297         return sb.toString();
 298     }
 299 
 300     private boolean prepareProjectConfig(Map<String, ? super Object> params)
 301             throws IOException {
 302         Map<String, String> data = createReplacementData(params);
 303         File rootDir =
 304             LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params);
 305 
 306         // prepare installer icon
 307         File iconTarget = getConfig_IconFile(rootDir, params);
 308         File icon = LinuxAppBundler.ICON_PNG.fetchFrom(params);
 309         if (!StandardBundlerParam.isRuntimeInstaller(params)) {
 310             if (icon == null || !icon.exists()) {
 311                 fetchResource(iconTarget.getName(),
 312                         I18N.getString("resource.menu-icon"),
 313                         DEFAULT_ICON,
 314                         iconTarget,
 315                         VERBOSE.fetchFrom(params),
 316                         RESOURCE_DIR.fetchFrom(params));
 317             } else {
 318                 fetchResource(iconTarget.getName(),
 319                         I18N.getString("resource.menu-icon"),
 320                         icon,
 321                         iconTarget,
 322                         VERBOSE.fetchFrom(params),
 323                         RESOURCE_DIR.fetchFrom(params));
 324             }
 325         }
 326 
 327         StringBuilder installScripts = new StringBuilder();
 328         StringBuilder removeScripts = new StringBuilder();
 329         for (Map<String, ? super Object> addLauncher :
 330                 ADD_LAUNCHERS.fetchFrom(params)) {
 331             Map<String, String> addLauncherData =
 332                     createReplacementData(addLauncher);
 333             addLauncherData.put("APPLICATION_FS_NAME",
 334                     data.get("APPLICATION_FS_NAME"));
 335             addLauncherData.put("DESKTOP_MIMES", "");
 336 
 337             // prepare desktop shortcut
 338             Writer w = new BufferedWriter(new FileWriter(
 339                     getConfig_DesktopShortcutFile(rootDir, addLauncher)));
 340             String content = preprocessTextResource(
 341                     getConfig_DesktopShortcutFile(rootDir,
 342                     addLauncher).getName(),
 343                     I18N.getString("resource.menu-shortcut-descriptor"),
 344                     DEFAULT_DESKTOP_FILE_TEMPLATE, addLauncherData,
 345                     VERBOSE.fetchFrom(params),
 346                     RESOURCE_DIR.fetchFrom(params));
 347             w.write(content);
 348             w.close();
 349 
 350             // prepare installer icon
 351             iconTarget = getConfig_IconFile(rootDir, addLauncher);
 352             icon = LinuxAppBundler.ICON_PNG.fetchFrom(addLauncher);
 353             if (icon == null || !icon.exists()) {
 354                 fetchResource(iconTarget.getName(),
 355                         I18N.getString("resource.menu-icon"),
 356                         DEFAULT_ICON,
 357                         iconTarget,
 358                         VERBOSE.fetchFrom(params),
 359                         RESOURCE_DIR.fetchFrom(params));
 360             } else {
 361                 fetchResource(iconTarget.getName(),
 362                         I18N.getString("resource.menu-icon"),
 363                         icon,
 364                         iconTarget,
 365                         VERBOSE.fetchFrom(params),
 366                         RESOURCE_DIR.fetchFrom(params));
 367             }
 368 
 369             // post copying of desktop icon
 370             installScripts.append("xdg-desktop-menu install --novendor ");
 371             installScripts.append(LINUX_INSTALL_DIR.fetchFrom(params));
 372             installScripts.append("/");
 373             installScripts.append(data.get("APPLICATION_FS_NAME"));
 374             installScripts.append("/");
 375             installScripts.append(addLauncherData.get(
 376                     "APPLICATION_LAUNCHER_FILENAME"));
 377             installScripts.append(".desktop\n");
 378 
 379             // preun cleanup of desktop icon
 380             removeScripts.append("xdg-desktop-menu uninstall --novendor ");
 381             removeScripts.append(LINUX_INSTALL_DIR.fetchFrom(params));
 382             removeScripts.append("/");
 383             removeScripts.append(data.get("APPLICATION_FS_NAME"));
 384             removeScripts.append("/");
 385             removeScripts.append(addLauncherData.get(
 386                     "APPLICATION_LAUNCHER_FILENAME"));
 387             removeScripts.append(".desktop\n");
 388 
 389         }
 390         data.put("ADD_LAUNCHERS_INSTALL", installScripts.toString());
 391         data.put("ADD_LAUNCHERS_REMOVE", removeScripts.toString());
 392 
 393         StringBuilder cdsScript = new StringBuilder();
 394 
 395         data.put("APP_CDS_CACHE", cdsScript.toString());
 396 
 397         List<Map<String, ? super Object>> associations =
 398                 FILE_ASSOCIATIONS.fetchFrom(params);
 399         data.put("FILE_ASSOCIATION_INSTALL", "");
 400         data.put("FILE_ASSOCIATION_REMOVE", "");
 401         data.put("DESKTOP_MIMES", "");
 402         if (associations != null) {
 403             String mimeInfoFile = XDG_FILE_PREFIX.fetchFrom(params)
 404                     + "-MimeInfo.xml";
 405             StringBuilder mimeInfo = new StringBuilder(
 406                 "<?xml version=\"1.0\"?>\n<mime-info xmlns="
 407                 +"'http://www.freedesktop.org/standards/shared-mime-info'>\n");
 408             StringBuilder registrations = new StringBuilder();
 409             StringBuilder deregistrations = new StringBuilder();
 410             StringBuilder desktopMimes = new StringBuilder("MimeType=");
 411             boolean addedEntry = false;


 517                                 .append(target.getName())
 518                                 .append(" ")
 519                                 .append(dashMime)
 520                                 .append("\n");
 521                     }
 522                 }
 523             }
 524             mimeInfo.append("</mime-info>");
 525 
 526             if (addedEntry) {
 527                 Writer w = new BufferedWriter(new FileWriter(
 528                         new File(rootDir, mimeInfoFile)));
 529                 w.write(mimeInfo.toString());
 530                 w.close();
 531                 data.put("FILE_ASSOCIATION_INSTALL", registrations.toString());
 532                 data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString());
 533                 data.put("DESKTOP_MIMES", desktopMimes.toString());
 534             }
 535         }
 536 
 537         if (!StandardBundlerParam.isRuntimeInstaller(params)) {
 538             //prepare desktop shortcut
 539             Writer w = new BufferedWriter(new FileWriter(
 540                     getConfig_DesktopShortcutFile(rootDir, params)));
 541             String content = preprocessTextResource(
 542                     getConfig_DesktopShortcutFile(rootDir, params).getName(),
 543                     I18N.getString("resource.menu-shortcut-descriptor"),
 544                     DEFAULT_DESKTOP_FILE_TEMPLATE, data,
 545                     VERBOSE.fetchFrom(params),
 546                     RESOURCE_DIR.fetchFrom(params));
 547             w.write(content);
 548             w.close();
 549         }
 550 
 551         // prepare spec file
 552         Writer w = new BufferedWriter(
 553                 new FileWriter(getConfig_SpecFile(params)));
 554         String content = preprocessTextResource(
 555                 getConfig_SpecFile(params).getName(),
 556                 I18N.getString("resource.rpm-spec-file"),
 557                 DEFAULT_SPEC_TEMPLATE, data,


 568         Map<String, String> data = new HashMap<>();
 569 
 570         data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params));
 571         data.put("APPLICATION_FS_NAME", APP_NAME.fetchFrom(params));
 572         data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params));
 573         data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params));
 574         data.put("APPLICATION_VERSION", VERSION.fetchFrom(params));
 575         data.put("APPLICATION_LAUNCHER_FILENAME", APP_NAME.fetchFrom(params));
 576         data.put("INSTALLATION_DIRECTORY", LINUX_INSTALL_DIR.fetchFrom(params));
 577         data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params));
 578         data.put("DEPLOY_BUNDLE_CATEGORY", CATEGORY.fetchFrom(params));
 579         // TODO rpm categories
 580         data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
 581         data.put("APPLICATION_SUMMARY", TITLE.fetchFrom(params));
 582         data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params));
 583         data.put("APPLICATION_LICENSE_FILE", getLicenseFileString(params));
 584         String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
 585         data.put("PACKAGE_DEPENDENCIES",
 586                 deps.isEmpty() ? "" : "Requires: " + deps);
 587         data.put("RUNTIME_INSTALLER",
 588                 StandardBundlerParam.isRuntimeInstaller(params).toString());
 589         return data;
 590     }
 591 
 592     private File getConfig_DesktopShortcutFile(File rootDir,
 593             Map<String, ? super Object> params) {
 594         return new File(rootDir, APP_NAME.fetchFrom(params) + ".desktop");
 595     }
 596 
 597     private File getConfig_IconFile(File rootDir,
 598             Map<String, ? super Object> params) {
 599         return new File(rootDir, APP_NAME.fetchFrom(params) + ".png");
 600     }
 601 
 602     private File getConfig_SpecFile(Map<String, ? super Object> params) {
 603         return new File(RPM_IMAGE_DIR.fetchFrom(params),
 604                 APP_NAME.fetchFrom(params) + ".spec");
 605     }
 606 
 607     private File buildRPM(Map<String, ? super Object> params,
 608             File outdir) throws IOException {
 609         Log.verbose(MessageFormat.format(I18N.getString(
 610                 "message.outputting-bundle-location"),
 611                 outdir.getAbsolutePath()));
 612 
 613         File broot = new File(TEMP_ROOT.fetchFrom(params), "rmpbuildroot");
 614 
 615         outdir.mkdirs();
 616 
 617         //run rpmbuild
 618         ProcessBuilder pb = new ProcessBuilder(
 619                 TOOL_RPMBUILD,
 620                 "-bb", getConfig_SpecFile(params).getAbsolutePath(),
 621                 "--define", "%_sourcedir "
 622                         + RPM_IMAGE_DIR.fetchFrom(params).getAbsolutePath(),
 623                 // save result to output dir
 624                 "--define", "%_rpmdir " + outdir.getAbsolutePath(),
 625                 // do not use other system directories to build as current user
 626                 "--define", "%_topdir " + broot.getAbsolutePath()
 627         );
 628         pb = pb.directory(RPM_IMAGE_DIR.fetchFrom(params));
 629         IOUtils.exec(pb, false);
 630 
 631         Log.verbose(MessageFormat.format(
 632                 I18N.getString("message.output-bundle-location"),
 633                 outdir.getAbsolutePath()));


< prev index next >