8230974: creating rpm, get error for relative path to the license.txt
Submitted-by: asemenyuk
Reviewed-by: herrick
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Mon Sep 30 19:33:13 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Mon Sep 30 20:16:48 2019 -0400
@@ -169,8 +169,14 @@
params), PACKAGE_NAME.fetchFrom(params)).toString());
data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params));
data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params));
- data.put("APPLICATION_LICENSE_FILE", Optional.ofNullable(
- LICENSE_FILE.fetchFrom(params)).orElse(""));
+
+ String licenseFile = LICENSE_FILE.fetchFrom(params);
+ if (licenseFile == null) {
+ licenseFile = "";
+ } else {
+ licenseFile = Path.of(licenseFile).toAbsolutePath().normalize().toString();
+ }
+ data.put("APPLICATION_LICENSE_FILE", licenseFile);
data.put("APPLICATION_GROUP", Optional.ofNullable(
GROUP.fetchFrom(params)).orElse(""));
--- a/test/jdk/tools/jpackage/share/LicenseTest.java Mon Sep 30 19:33:13 2019 -0400
+++ b/test/jdk/tools/jpackage/share/LicenseTest.java Mon Sep 30 20:16:48 2019 -0400
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
@@ -87,7 +88,20 @@
public static void testCommon() {
new PackageTest().configureHelloApp()
.addInitializer(cmd -> {
- cmd.addArguments("--license-file", LICENSE_FILE);
+ Path licenseCopy = TKit.workDir().resolve(LICENSE_FILE.getFileName()).toAbsolutePath().normalize();
+ Files.copy(LICENSE_FILE, licenseCopy,
+ StandardCopyOption.REPLACE_EXISTING);
+ final Path basePath = Path.of(".").toAbsolutePath().normalize();
+ try {
+ licenseCopy = basePath.relativize(licenseCopy);
+ } catch (IllegalArgumentException ex) {
+ // May happen on Windows: java.lang.IllegalArgumentException: 'other' has different root
+ TKit.trace(String.format(
+ "Not using relative path to license file for --license-file parameter. Failed to relativize [%s] at [%s]",
+ licenseCopy, basePath));
+ ex.printStackTrace();
+ }
+ cmd.addArguments("--license-file", licenseCopy);
})
.forTypes(PackageType.LINUX)
.addBundleVerifier(cmd -> {