8215447: Investigate if current implementation of --license-file is correct for RPM packages
Submitted-by: asemenyuk
Reviewed-by: herrick, almatvee
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Tue Aug 13 18:21:07 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Wed Aug 14 07:50:54 2019 -0400
@@ -29,8 +29,6 @@
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.file.Files;
-import java.nio.file.attribute.PosixFilePermission;
-import java.nio.file.attribute.PosixFilePermissions;
import java.text.MessageFormat;
import java.util.*;
import java.util.regex.Matcher;
@@ -40,6 +38,17 @@
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
+/**
+ * There are two command line options to configure license information for RPM
+ * packaging: --linux-rpm-license-type and --license-file. Value of
+ * --linux-rpm-license-type command line option configures "License:" section
+ * of RPM spec. Value of --license-file command line option specifies a license
+ * file to be added to the package. License file is a sort of documentation file
+ * but it will be installed even if user selects an option to install the
+ * package without documentation. --linux-rpm-license-type is the primary option
+ * to set license information. --license-file makes little sense in case of RPM
+ * packaging.
+ */
public class LinuxRpmBundler extends AbstractBundler {
private static final ResourceBundle I18N = ResourceBundle.getBundle(
@@ -271,31 +280,6 @@
}
}
- private String getLicenseFileString(Map<String, ? super Object> params)
- throws IOException {
- StringBuilder sb = new StringBuilder();
-
- String licenseStr = LICENSE_FILE.fetchFrom(params);
- if (licenseStr != null) {
- File licenseFile = new File(licenseStr);
- File rootDir =
- LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params),
- params);
- File target = new File(rootDir + File.separator + "app"
- + File.separator + licenseFile.getName());
- Files.copy(licenseFile.toPath(), target.toPath());
-
- sb.append("%license ");
- sb.append(LINUX_INSTALL_DIR.fetchFrom(params));
- sb.append("/");
- sb.append(APP_NAME.fetchFrom(params));
- sb.append("/app/");
- sb.append(licenseFile.getName());
- }
-
- return sb.toString();
- }
-
private boolean prepareProjectConfig(Map<String, ? super Object> params)
throws IOException {
Map<String, String> data = createReplacementData(params);
@@ -583,7 +567,13 @@
data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params));
data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params));
- data.put("APPLICATION_LICENSE_FILE", getLicenseFileString(params));
+
+ String licenseFile = LICENSE_FILE.fetchFrom(params);
+ if (licenseFile == null) {
+ licenseFile = "";
+ }
+ data.put("APPLICATION_LICENSE_FILE", licenseFile);
+
String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
data.put("PACKAGE_DEPENDENCIES",
deps.isEmpty() ? "" : "Requires: " + deps);
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.spec Tue Aug 13 18:21:07 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.spec Wed Aug 14 07:50:54 2019 -0400
@@ -29,9 +29,14 @@
rm -rf %{buildroot}
mkdir -p %{buildroot}INSTALLATION_DIRECTORY
cp -r %{_sourcedir}/APPLICATION_FS_NAME %{buildroot}INSTALLATION_DIRECTORY
-
+%if "xAPPLICATION_LICENSE_FILE" != x
+ %define license_install_file %{_defaultlicensedir}/%{name}-%{version}/%{basename:APPLICATION_LICENSE_FILE}
+ install -d -m 755 %{buildroot}%{dirname:%{license_install_file}}
+ install -m 644 APPLICATION_LICENSE_FILE %{buildroot}%{license_install_file}
+%endif
+
%files
-APPLICATION_LICENSE_FILE
++%{?license_install_file:%license %{license_install_file}}
INSTALLATION_DIRECTORY/APPLICATION_FS_NAME
%post
--- a/test/jdk/tools/jpackage/helpers/JPackagePath.java Tue Aug 13 18:21:07 2019 -0400
+++ b/test/jdk/tools/jpackage/helpers/JPackagePath.java Wed Aug 14 07:50:54 2019 -0400
@@ -210,9 +210,7 @@
}
public static String getLinuxInstalledApp(String testName) {
- return File.separator + "opt"
- + File.separator + testName
- + File.separator + testName;
+ return Path.of("/opt", testName, "bin", testName).toString();
}
public static String getOSXInstalledApp(String subDir, String testName) {
--- a/test/jdk/tools/jpackage/linux/base/LicenseBase.java Tue Aug 13 18:21:07 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/LicenseBase.java Wed Aug 14 07:50:54 2019 -0400
@@ -22,6 +22,8 @@
*/
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@@ -48,13 +50,57 @@
String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
JPackageInstallerHelper.validateApp(app);
+ if (EXT.equals("rpm")) {
+ verifyInstallRpm();
+ }
+ }
+
+ private static File getRpmLicenseFileInstallLocation() throws Exception {
+ final String infoResult = "infoResult.txt";
+ int retVal = JPackageHelper.execute(new File(infoResult), "rpm",
+ "--eval", "%{_defaultlicensedir}");
+ if (retVal != 0) {
+ throw new AssertionError("rpm exited with error: " + retVal);
+ }
+
+ final String rootLicenseDir = Files.readString(Path.of(infoResult)).replaceAll(
+ "(\\r|\\n)", "");
+
+ retVal = JPackageHelper.execute(new File(infoResult), "rpm",
+ "-qp", "--queryformat", "%{name}-%{version}",
+ OUTPUT.toLowerCase());
+ if (retVal != 0) {
+ throw new AssertionError("rpm exited with error: " + retVal);
+ }
+
+ final String testPackageName = Files.readString(Path.of(infoResult));
+
+ return Path.of(rootLicenseDir, testPackageName, new File(
+ JPackagePath.getLicenseFilePath()).getName()).toFile();
+ }
+
+ private static void verifyInstallRpm() throws Exception {
+ final File licenseFile = getRpmLicenseFileInstallLocation();
+ if (!licenseFile.exists()) {
+ throw new AssertionError(
+ "Error: " + licenseFile.getAbsolutePath() + " not found");
+ }
}
private static void verifyUnInstall() throws Exception {
String folderPath = JPackagePath.getLinuxInstallFolder(TEST_NAME);
File folder = new File(folderPath);
if (folder.exists()) {
- throw new AssertionError("Error: " + folder.getAbsolutePath() + " exist");
+ throw new AssertionError(
+ "Error: " + folder.getAbsolutePath() + " exist");
+ }
+
+ if (EXT.equals("rpm")) {
+ final File licenseFileFolder = getRpmLicenseFileInstallLocation().getParentFile();
+ if (folder.exists()) {
+ throw new AssertionError(
+ "Error: " + licenseFileFolder.getAbsolutePath() + " exist");
+ }
}
}
--- a/test/jdk/tools/jpackage/linux/base/LicenseTypeBase.java Tue Aug 13 18:21:07 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/LicenseTypeBase.java Wed Aug 14 07:50:54 2019 -0400
@@ -43,7 +43,7 @@
private static final String infoResult = "infoResult.txt";
private static void validatePackage() throws Exception {
int retVal = JPackageHelper.execute(new File(infoResult),"rpm",
- "--query", "--package", "--info", OUTPUT.toLowerCase());
+ "-qp", "--queryformat", "%{license}", OUTPUT.toLowerCase());
if (retVal != 0) {
throw new AssertionError("rpm exited with error: " + retVal);
}
@@ -54,7 +54,7 @@
}
String output = Files.readString(outfile.toPath());
- if (!output.contains(JP_LICENSE_TYPE)) {
+ if (!output.equals(JP_LICENSE_TYPE)) {
throw new AssertionError("Unexpected result: " + output);
}
}