8215381: Investigate if current implementation of --license-file is correct for Debian packages JDK-8200758-branch
authorherrick
Mon, 19 Aug 2019 17:39:48 -0400
branchJDK-8200758-branch
changeset 57807 4a15115716ea
parent 57806 91f8eec58086
child 57808 013547ae70ac
8215381: Investigate if current implementation of --license-file is correct for Debian packages Submitted-by: asemenyuk Reviewed-by: herrick, almatvee
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources_ja.properties
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources_zh_CN.properties
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.copyright
src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/ValidOptions.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources.properties
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_ja.properties
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_zh_CN.properties
test/jdk/tools/jpackage/linux/base/LicenseBase.java
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java	Mon Aug 19 17:39:48 2019 -0400
@@ -28,12 +28,15 @@
 import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.attribute.PosixFilePermission;
 import java.nio.file.attribute.PosixFilePermissions;
 import java.text.MessageFormat;
 import java.util.*;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 
 import static jdk.jpackage.internal.StandardBundlerParam.*;
 import static jdk.jpackage.internal.LinuxAppBundler.ICON_PNG;
@@ -140,13 +143,13 @@
                     + EMAIL.fetchFrom(params) + ">",
             (s, p) -> s);
 
-    public static final BundlerParamInfo<String> SECTION = 
+    public static final BundlerParamInfo<String> SECTION =
             new StandardBundlerParam<>(
             Arguments.CLIOptions.LINUX_CATEGORY.getId(),
             String.class,
             params -> "misc",
             (s, p) -> s);
-    
+
     public static final BundlerParamInfo<String> LICENSE_TEXT =
             new StandardBundlerParam<> (
             "linux.deb.licenseText",
@@ -155,7 +158,13 @@
                 try {
                     String licenseFile = LICENSE_FILE.fetchFrom(params);
                     if (licenseFile != null) {
-                        return Files.readString(new File(licenseFile).toPath());
+                        StringBuilder contentBuilder = new StringBuilder();
+                        try (Stream<String> stream = Files.lines(Path.of(
+                                licenseFile), StandardCharsets.UTF_8)) {
+                            stream.forEach(s -> contentBuilder.append(s).append(
+                                    "\n"));
+                        }
+                        return contentBuilder.toString();
                     }
                 } catch (Exception e) {
                     Log.verbose(e);
@@ -164,6 +173,13 @@
             },
             (s, p) -> s);
 
+    public static final BundlerParamInfo<String> COPYRIGHT_FILE =
+            new StandardBundlerParam<>(
+            Arguments.CLIOptions.LINUX_DEB_COPYRIGHT_FILE.getId(),
+            String.class,
+            params -> null,
+            (s, p) -> s);
+
     public static final BundlerParamInfo<String> XDG_FILE_PREFIX =
             new StandardBundlerParam<> (
             "linux.xdg-prefix",
@@ -715,16 +731,23 @@
         }
         setPermissions(getConfig_PostrmFile(params), "rwxr-xr-x");
 
-        try (Writer w = Files.newBufferedWriter(
-                getConfig_CopyrightFile(params).toPath())) {
-            String content = preprocessTextResource(
-                    getConfig_CopyrightFile(params).getName(),
-                    I18N.getString("resource.deb-copyright-file"),
-                    DEFAULT_COPYRIGHT_TEMPLATE,
-                    data,
-                    VERBOSE.fetchFrom(params),
-                    RESOURCE_DIR.fetchFrom(params));
-            w.write(content);
+        getConfig_CopyrightFile(params).getParentFile().mkdirs();
+        String customCopyrightFile = COPYRIGHT_FILE.fetchFrom(params);
+        if (customCopyrightFile != null) {
+            IOUtils.copyFile(new File(customCopyrightFile),
+                    getConfig_CopyrightFile(params));
+        } else {
+            try (Writer w = Files.newBufferedWriter(
+                    getConfig_CopyrightFile(params).toPath())) {
+                String content = preprocessTextResource(
+                        getConfig_CopyrightFile(params).getName(),
+                        I18N.getString("resource.copyright-file"),
+                        DEFAULT_COPYRIGHT_TEMPLATE,
+                        data,
+                        VERBOSE.fetchFrom(params),
+                        RESOURCE_DIR.fetchFrom(params));
+                w.write(content);
+            }
         }
 
         return true;
@@ -793,7 +816,8 @@
     }
 
     private File getConfig_CopyrightFile(Map<String, ? super Object> params) {
-        return new File(CONFIG_DIR.fetchFrom(params), "copyright");
+        return Path.of(DEB_IMAGE_DIR.fetchFrom(params).getAbsolutePath(), "usr",
+                "share", "doc", BUNDLE_NAME.fetchFrom(params), "copyright").toFile();
     }
 
     private File buildDeb(Map<String, ? super Object> params,
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties	Mon Aug 19 17:39:48 2019 -0400
@@ -35,7 +35,7 @@
 resource.deb-prerm-script=DEB prerm script
 resource.deb-postinstall-script=DEB postinstall script
 resource.deb-postrm-script=DEB postrm script
-resource.deb-copyright-file=DEB copyright file
+resource.copyright-file=Copyright file
 resource.menu-shortcut-descriptor=Menu shortcut descriptor
 resource.menu-icon=menu icon
 resource.rpm-spec-file=RPM spec file
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources_ja.properties	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources_ja.properties	Mon Aug 19 17:39:48 2019 -0400
@@ -35,7 +35,7 @@
 resource.deb-prerm-script=DEB prerm script
 resource.deb-postinstall-script=DEB postinstall script
 resource.deb-postrm-script=DEB postrm script
-resource.deb-copyright-file=DEB copyright file
+resource.copyright-file=Copyright file
 resource.menu-shortcut-descriptor=Menu shortcut descriptor
 resource.menu-icon=menu icon
 resource.rpm-spec-file=RPM spec file
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources_zh_CN.properties	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources_zh_CN.properties	Mon Aug 19 17:39:48 2019 -0400
@@ -35,7 +35,7 @@
 resource.deb-prerm-script=DEB prerm script
 resource.deb-postinstall-script=DEB postinstall script
 resource.deb-postrm-script=DEB postrm script
-resource.deb-copyright-file=DEB copyright file
+resource.copyright-file=Copyright file
 resource.menu-shortcut-descriptor=Menu shortcut descriptor
 resource.menu-icon=menu icon
 resource.rpm-spec-file=RPM spec file
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.copyright	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.copyright	Mon Aug 19 17:39:48 2019 -0400
@@ -1,8 +1,5 @@
-
-Copyright:
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 
-    APPLICATION_COPYRIGHT
-
-License:
-
-    APPLICATION_LICENSE_TEXT
+Files: *
+Copyright: APPLICATION_COPYRIGHT
+License: APPLICATION_LICENSE_TEXT
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java	Mon Aug 19 17:39:48 2019 -0400
@@ -108,6 +108,9 @@
 
         putUnlessNull(bundleParams, CLIOptions.LINUX_CATEGORY.getId(),
                 getOptionValue(CLIOptions.LINUX_CATEGORY));
+        
+        putUnlessNull(bundleParams, CLIOptions.LINUX_DEB_COPYRIGHT_FILE.getId(),
+                getOptionValue(CLIOptions.LINUX_DEB_COPYRIGHT_FILE));
 
         putUnlessNull(bundleParams,
                 CLIOptions.WIN_CONSOLE_HINT.getId(),
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java	Mon Aug 19 17:39:48 2019 -0400
@@ -322,6 +322,9 @@
 
         LINUX_DEB_MAINTAINER ("linux-deb-maintainer",
                 OptionCategories.PLATFORM_LINUX),
+        
+        LINUX_DEB_COPYRIGHT_FILE ("linux-deb-copyright-file",
+                OptionCategories.PLATFORM_LINUX),
 
         LINUX_CATEGORY ("linux-app-category",
                 OptionCategories.PLATFORM_LINUX),
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ValidOptions.java	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ValidOptions.java	Mon Aug 19 17:39:48 2019 -0400
@@ -121,6 +121,7 @@
         if (Platform.getPlatform() == Platform.LINUX) {
             options.put(CLIOptions.LINUX_BUNDLE_NAME.getId(), USE.INSTALL);
             options.put(CLIOptions.LINUX_DEB_MAINTAINER.getId(), USE.INSTALL);
+            options.put(CLIOptions.LINUX_DEB_COPYRIGHT_FILE.getId(), USE.INSTALL);
             options.put(CLIOptions.LINUX_CATEGORY.getId(), USE.INSTALL);
             options.put(CLIOptions.LINUX_RPM_LICENSE_TYPE.getId(), USE.INSTALL);
             options.put(CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(),
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources.properties	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources.properties	Mon Aug 19 17:39:48 2019 -0400
@@ -246,6 +246,9 @@
 \          Name for Linux bundle, defaults to the application name\n\
 \  --linux-deb-maintainer <email address>\n\
 \          Maintainer for .deb bundle\n\
+\  --linux-deb-copyright-file <file path>\n\
+\          Path to custom copyright file for Debian packaging\n\
+\          (absolute path or relative to the current directory)\n\
 \  --linux-menu-group <menu-group-name>\n\
 \          Menu group this application is placed in\n\
 \  --linux-package-deps\n\
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_ja.properties	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_ja.properties	Mon Aug 19 17:39:48 2019 -0400
@@ -246,6 +246,9 @@
 \          Name for Linux bundle, defaults to the application name\n\
 \  --linux-deb-maintainer <email address>\n\
 \          Maintainer for .deb bundle\n\
+\  --linux-deb-copyright-file <file path>\n\
+\          Path to custom copyright file for Debian packaging\n\
+\          (absolute path or relative to the current directory)\n\
 \  --linux-menu-group <menu-group-name>\n\
 \          Menu group this application is placed in\n\
 \  --linux-package-deps\n\
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_zh_CN.properties	Mon Aug 19 17:34:40 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_zh_CN.properties	Mon Aug 19 17:39:48 2019 -0400
@@ -246,6 +246,9 @@
 \          Name for Linux bundle, defaults to the application name\n\
 \  --linux-deb-maintainer <email address>\n\
 \          Maintainer for .deb bundle\n\
+\  --linux-deb-copyright-file <file path>\n\
+\          Path to custom copyright file for Debian packaging\n\
+\          (absolute path or relative to the current directory)\n\
 \  --linux-menu-group <menu-group-name>\n\
 \          Menu group this application is placed in\n\
 \  --linux-package-deps\n\
--- a/test/jdk/tools/jpackage/linux/base/LicenseBase.java	Mon Aug 19 17:34:40 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/LicenseBase.java	Mon Aug 19 17:39:48 2019 -0400
@@ -50,8 +50,15 @@
         String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
         JPackageInstallerHelper.validateApp(app);
 
+        File licenseFile = null;
         if (EXT.equals("rpm")) {
-            verifyInstallRpm();
+            licenseFile = getRpmLicenseFileInstallLocation();
+        } else if (EXT.equals("deb")) {
+            licenseFile = getDebLicenseFileInstallLocation();
+        }
+        if (!licenseFile.exists()) {
+            throw new AssertionError(
+                    "Error: " + licenseFile.getAbsolutePath() + " not found");
         }
     }
 
@@ -67,8 +74,8 @@
                 "(\\r|\\n)", "");
 
         retVal = JPackageHelper.execute(new File(infoResult), "rpm",
-                "-qp", "--queryformat", "%{name}-%{version}",
-                OUTPUT.toLowerCase());
+                "-q", "--queryformat", "%{name}-%{version}",
+                TEST_NAME.toLowerCase());
         if (retVal != 0) {
             throw new AssertionError("rpm exited with error: " + retVal);
         }
@@ -79,12 +86,9 @@
                 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 File getDebLicenseFileInstallLocation() throws Exception {
+        return Path.of("/usr", "share", "doc", TEST_NAME.toLowerCase(),
+                "copyright").toFile();
     }
 
     private static void verifyUnInstall() throws Exception {
@@ -101,6 +105,12 @@
                 throw new AssertionError(
                         "Error: " + licenseFileFolder.getAbsolutePath() + " exist");
             }
+        } else if (EXT.equals("deb")) {
+            final File licenseFileFolder = getDebLicenseFileInstallLocation().getParentFile();
+            if (folder.exists()) {
+                throw new AssertionError(
+                        "Error: " + licenseFileFolder.getAbsolutePath() + " exist");
+            }
         }
     }