src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java
branchJDK-8200758-branch
changeset 57742 e3d4b9bc5093
parent 57741 38856ef4a19c
child 57776 783db59cd8d3
equal deleted inserted replaced
57741:38856ef4a19c 57742:e3d4b9bc5093
    27 
    27 
    28 import javax.imageio.ImageIO;
    28 import javax.imageio.ImageIO;
    29 import java.awt.image.BufferedImage;
    29 import java.awt.image.BufferedImage;
    30 import java.io.*;
    30 import java.io.*;
    31 import java.nio.file.Files;
    31 import java.nio.file.Files;
    32 import java.nio.file.attribute.PosixFilePermission;
       
    33 import java.nio.file.attribute.PosixFilePermissions;
       
    34 import java.text.MessageFormat;
    32 import java.text.MessageFormat;
    35 import java.util.*;
    33 import java.util.*;
    36 import java.util.regex.Matcher;
    34 import java.util.regex.Matcher;
    37 import java.util.regex.Pattern;
    35 import java.util.regex.Pattern;
    38 
    36 
    39 import static jdk.jpackage.internal.StandardBundlerParam.*;
    37 import static jdk.jpackage.internal.StandardBundlerParam.*;
    40 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
    38 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
    41 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
    39 import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
    42 
    40 
       
    41 /**
       
    42  * There are two command line options to configure license information for RPM
       
    43  * packaging: --linux-rpm-license-type and --license-file. Value of
       
    44  * --linux-rpm-license-type command line option configures "License:" section
       
    45  * of RPM spec. Value of --license-file command line option specifies a license
       
    46  * file to be added to the package. License file is a sort of documentation file
       
    47  * but it will be installed even if user selects an option to install the
       
    48  * package without documentation. --linux-rpm-license-type is the primary option
       
    49  * to set license information. --license-file makes little sense in case of RPM
       
    50  * packaging.
       
    51  */
    43 public class LinuxRpmBundler extends AbstractBundler {
    52 public class LinuxRpmBundler extends AbstractBundler {
    44 
    53 
    45     private static final ResourceBundle I18N = ResourceBundle.getBundle(
    54     private static final ResourceBundle I18N = ResourceBundle.getBundle(
    46             "jdk.jpackage.internal.resources.LinuxResources");
    55             "jdk.jpackage.internal.resources.LinuxResources");
    47 
    56 
   269             Log.verbose(ex);
   278             Log.verbose(ex);
   270             throw new PackagerException(ex);
   279             throw new PackagerException(ex);
   271         }
   280         }
   272     }
   281     }
   273 
   282 
   274     private String getLicenseFileString(Map<String, ? super Object> params)
       
   275             throws IOException {
       
   276         StringBuilder sb = new StringBuilder();
       
   277 
       
   278         String licenseStr = LICENSE_FILE.fetchFrom(params);
       
   279         if (licenseStr != null) {
       
   280             File licenseFile = new File(licenseStr);
       
   281             File rootDir =
       
   282                     LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params),
       
   283                             params);
       
   284             File target = new File(rootDir + File.separator + "app"
       
   285                     + File.separator + licenseFile.getName());
       
   286             Files.copy(licenseFile.toPath(), target.toPath());
       
   287 
       
   288             sb.append("%license ");
       
   289             sb.append(LINUX_INSTALL_DIR.fetchFrom(params));
       
   290             sb.append("/");
       
   291             sb.append(APP_NAME.fetchFrom(params));
       
   292             sb.append("/app/");
       
   293             sb.append(licenseFile.getName());
       
   294         }
       
   295 
       
   296         return sb.toString();
       
   297     }
       
   298 
       
   299     private boolean prepareProjectConfig(Map<String, ? super Object> params)
   283     private boolean prepareProjectConfig(Map<String, ? super Object> params)
   300             throws IOException {
   284             throws IOException {
   301         Map<String, String> data = createReplacementData(params);
   285         Map<String, String> data = createReplacementData(params);
   302         File rootDir =
   286         File rootDir =
   303             LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params);
   287             LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params);
   581         data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params));
   565         data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params));
   582         data.put("DEPLOY_BUNDLE_CATEGORY", MENU_GROUP.fetchFrom(params));
   566         data.put("DEPLOY_BUNDLE_CATEGORY", MENU_GROUP.fetchFrom(params));
   583         data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
   567         data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
   584         data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params));
   568         data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params));
   585         data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params));
   569         data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params));
   586         data.put("APPLICATION_LICENSE_FILE", getLicenseFileString(params));
   570 
       
   571         String licenseFile = LICENSE_FILE.fetchFrom(params);
       
   572         if (licenseFile == null) {
       
   573             licenseFile = "";
       
   574         }
       
   575         data.put("APPLICATION_LICENSE_FILE", licenseFile);
       
   576 
   587         String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
   577         String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
   588         data.put("PACKAGE_DEPENDENCIES",
   578         data.put("PACKAGE_DEPENDENCIES",
   589                 deps.isEmpty() ? "" : "Requires: " + deps);
   579                 deps.isEmpty() ? "" : "Requires: " + deps);
   590         data.put("RUNTIME_INSTALLER", "" +
   580         data.put("RUNTIME_INSTALLER", "" +
   591                 StandardBundlerParam.isRuntimeInstaller(params));
   581                 StandardBundlerParam.isRuntimeInstaller(params));