8222778: Packaging Tool (JEP 343) on Linux/AArch64 JDK-8200758-branch
authordchuyko
Fri, 26 Jul 2019 16:25:05 +0300
branchJDK-8200758-branch
changeset 57543 bcd1ab268a7d
parent 57532 eb0bd96672f4
child 57557 b4aa3d0c1431
8222778: Packaging Tool (JEP 343) on Linux/AArch64 Reviewed-by: almatvee, aph
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java
src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp
src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp
test/jdk/tools/jpackage/linux/base/Base.java
test/jdk/tools/jpackage/linux/base/BundleNameBase.java
test/jdk/tools/jpackage/linux/base/FileAssociationsBase.java
test/jdk/tools/jpackage/linux/base/InstallDirBase.java
test/jdk/tools/jpackage/linux/base/LicenseBase.java
test/jdk/tools/jpackage/linux/base/LicenseTypeBase.java
test/jdk/tools/jpackage/linux/base/MaintainerBase.java
test/jdk/tools/jpackage/linux/base/PackageDepsBase.java
test/jdk/tools/jpackage/linux/deb/BundleNameTest.java
test/jdk/tools/jpackage/linux/deb/FileAssociationsTest.java
test/jdk/tools/jpackage/linux/deb/InstallDirTest.java
test/jdk/tools/jpackage/linux/deb/LicenseTest.java
test/jdk/tools/jpackage/linux/deb/MaintainerTest.java
test/jdk/tools/jpackage/linux/deb/PackageDepsTest.java
test/jdk/tools/jpackage/linux/deb/Test.java
test/jdk/tools/jpackage/linux/rpm/install.sh
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java	Fri Jul 26 16:25:05 2019 +0300
@@ -200,7 +200,8 @@
     private final static String DEFAULT_DESKTOP_FILE_TEMPLATE =
             "template.desktop";
 
-    public final static String TOOL_DPKG = "dpkg-deb";
+    private final static String TOOL_DPKG_DEB = "dpkg-deb";
+    private final static String TOOL_DPKG = "dpkg";
 
     public static boolean testTool(String toolName, String minVersion) {
         try {
@@ -231,6 +232,11 @@
 
             // NOTE: Can we validate that the required tools are available
             // before we start?
+            if (!testTool(TOOL_DPKG_DEB, "1")){
+                throw new ConfigException(MessageFormat.format(
+                        I18N.getString("error.tool-not-found"), TOOL_DPKG_DEB),
+                        I18N.getString("error.tool-not-found.advice"));
+            }
             if (!testTool(TOOL_DPKG, "1")){
                 throw new ConfigException(MessageFormat.format(
                         I18N.getString("error.tool-not-found"), TOOL_DPKG),
@@ -354,12 +360,13 @@
 
     }
 
-    private String getArch() {
-        String arch = System.getProperty("os.arch");
-        if ("i386".equals(arch))
-            return "i386";
-        else
-            return "amd64";
+    private static String getDebArch() throws IOException {
+        try (var baos = new ByteArrayOutputStream();
+                var ps = new PrintStream(baos)) {
+            var pb = new ProcessBuilder(TOOL_DPKG, "--print-architecture");
+            IOUtils.exec(pb, false, ps);
+            return baos.toString().split("\n", 2)[0];
+        }
     }
 
     private long getInstalledSizeKB(Map<String, ? super Object> params) {
@@ -717,7 +724,7 @@
     }
 
     private Map<String, String> createReplacementData(
-            Map<String, ? super Object> params) {
+            Map<String, ? super Object> params) throws IOException {
         Map<String, String> data = new HashMap<>();
         String launcher = LinuxAppImageBuilder.getLauncherRelativePath(params);
 
@@ -734,7 +741,7 @@
         data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
         data.put("APPLICATION_COPYRIGHT", COPYRIGHT.fetchFrom(params));
         data.put("APPLICATION_LICENSE_TEXT", LICENSE_TEXT.fetchFrom(params));
-        data.put("APPLICATION_ARCH", getArch());
+        data.put("APPLICATION_ARCH", getDebArch());
         data.put("APPLICATION_INSTALLED_SIZE",
                 Long.toString(getInstalledSizeKB(params)));
         String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
@@ -791,7 +798,7 @@
 
         // run dpkg
         ProcessBuilder pb = new ProcessBuilder(
-                "fakeroot", TOOL_DPKG, "-b",
+                "fakeroot", TOOL_DPKG_DEB, "-b",
                 FULL_PACKAGE_NAME.fetchFrom(params),
                 outFile.getAbsolutePath());
         pb = pb.directory(DEB_IMAGE_DIR.fetchFrom(params).getParentFile());
@@ -831,7 +838,7 @@
 
     public static boolean isSupported() {
         if (Platform.getPlatform() == Platform.LINUX) {
-            if (testTool(TOOL_DPKG, "1")) {
+            if (testTool(TOOL_DPKG_DEB, "1")) {
                 return true;
             }
         }
--- a/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp	Fri Jul 26 16:25:05 2019 +0300
@@ -189,7 +189,7 @@
     bool result = false;
 
     if (FMap.ContainsKey(SectionName) == true) {
-        IniSectionData* section;
+        IniSectionData* section = NULL;
 
         if (FMap.GetValue(SectionName, section) == true && section != NULL) {
             OrderedMap<TString, TString> data = section->GetData();
--- a/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp	Thu Jul 25 08:24:01 2019 -0400
+++ b/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp	Fri Jul 26 16:25:05 2019 +0300
@@ -208,10 +208,6 @@
         } else if (count == 0) {
             // break;
         } else {
-            if (buffer[count - 1] == EOF) {
-                buffer[count - 1] = '\0';
-            }
-
             std::list<TString> output = Helpers::StringToArray(buffer);
             FOutput.splice(FOutput.end(), output, output.begin(), output.end());
             result = true;
--- a/test/jdk/tools/jpackage/linux/base/Base.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/Base.java	Fri Jul 26 16:25:05 2019 +0300
@@ -22,6 +22,7 @@
  */
 
 import java.io.File;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -57,11 +58,21 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    static String getRpmArch() throws Exception {
+        File out = File.createTempFile("rpmbuild", ".out");
+        out.deleteOnExit();
+        int code = JPackageHelper.execute(out, "rpmbuild", "-E=%{_target_cpu}");
+        if (code != 0) {
+            throw new AssertionError("Error: unable to get rpm arch");
+        }
+        return Files.readAllLines(out.toPath()).get(0);
+    }
+
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         EXT = ext;
         if (EXT.equals("rpm")) {
-            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1.x86_64." + EXT;
+            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + getRpmArch() + "." + EXT;
         } else {
             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
         }
--- a/test/jdk/tools/jpackage/linux/base/BundleNameBase.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/BundleNameBase.java	Fri Jul 26 16:25:05 2019 +0300
@@ -58,12 +58,12 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         BUNDLE_NAME = "jpackage-test-bundle-name";
         EXT = ext;
         if (EXT.equals("rpm")) {
-            OUTPUT = "output" + File.separator + BUNDLE_NAME + "-1.0-1.x86_64." + EXT;
+            OUTPUT = "output" + File.separator + BUNDLE_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
         } else {
             OUTPUT = "output" + File.separator + BUNDLE_NAME + "-1.0." + EXT;
         }
--- a/test/jdk/tools/jpackage/linux/base/FileAssociationsBase.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/FileAssociationsBase.java	Fri Jul 26 16:25:05 2019 +0300
@@ -120,12 +120,12 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         EXT = ext;
         TEST_EXT = "jptest1";
         if (EXT.equals("rpm")) {
-            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1.x86_64." + EXT;
+            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
         } else {
             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
         }
--- a/test/jdk/tools/jpackage/linux/base/InstallDirBase.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/InstallDirBase.java	Fri Jul 26 16:25:05 2019 +0300
@@ -63,11 +63,11 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         EXT = ext;
         if (EXT.equals("rpm")) {
-            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1.x86_64." + EXT;
+            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
         } else {
             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
         }
--- a/test/jdk/tools/jpackage/linux/base/LicenseBase.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/LicenseBase.java	Fri Jul 26 16:25:05 2019 +0300
@@ -58,11 +58,11 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         EXT = ext;
         if (EXT.equals("rpm")) {
-            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1.x86_64." + EXT;
+            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
         } else {
             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
         }
--- a/test/jdk/tools/jpackage/linux/base/LicenseTypeBase.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/LicenseTypeBase.java	Fri Jul 26 16:25:05 2019 +0300
@@ -79,12 +79,12 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         EXT = ext;
         JP_LICENSE_TYPE = "JP_LICENSE_TYPE";
         if (EXT.equals("rpm")) {
-            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1.x86_64." + EXT;
+            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
         } else {
             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
         }
--- a/test/jdk/tools/jpackage/linux/base/MaintainerBase.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/MaintainerBase.java	Fri Jul 26 16:25:05 2019 +0300
@@ -79,7 +79,7 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         EMAIL = "jpackage-test@java.com";
         EXT = ext;
--- a/test/jdk/tools/jpackage/linux/base/PackageDepsBase.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/PackageDepsBase.java	Fri Jul 26 16:25:05 2019 +0300
@@ -101,13 +101,13 @@
         }
     }
 
-    private static void init(String name, String ext) {
+    private static void init(String name, String ext) throws Exception {
         TEST_NAME = name;
         DEP_NAME = name + "Dep";
         EXT = ext;
         if (EXT.equals("rpm")) {
-            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1.x86_64." + EXT;
-            OUTPUT_DEP = "output" + File.separator + DEP_NAME + "-1.0-1.x86_64." + EXT;
+            OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
+            OUTPUT_DEP = "output" + File.separator + DEP_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
         } else {
             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
             OUTPUT_DEP = "output" + File.separator + DEP_NAME + "-1.0." + EXT;
--- a/test/jdk/tools/jpackage/linux/deb/BundleNameTest.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/BundleNameTest.java	Fri Jul 26 16:25:05 2019 +0300
@@ -33,7 +33,7 @@
  * @requires (os.family == "linux")
  * @modules jdk.jpackage
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm -Xmx512m BundleNameTest
+ * @run main/othervm/timeout=360 -Xmx512m BundleNameTest
  */
 public class BundleNameTest {
     private static final String TEST_NAME = "BundleNameTest";
--- a/test/jdk/tools/jpackage/linux/deb/FileAssociationsTest.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/FileAssociationsTest.java	Fri Jul 26 16:25:05 2019 +0300
@@ -33,7 +33,7 @@
  * @requires (os.family == "linux")
  * @modules jdk.jpackage
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm -Xmx512m FileAssociationsTest
+ * @run main/othervm/timeout=360 -Xmx512m FileAssociationsTest
  */
 public class FileAssociationsTest {
     private static final String TEST_NAME = "FileAssociationsTest";
--- a/test/jdk/tools/jpackage/linux/deb/InstallDirTest.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/InstallDirTest.java	Fri Jul 26 16:25:05 2019 +0300
@@ -33,7 +33,7 @@
  * @requires (os.family == "linux")
  * @modules jdk.jpackage
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm -Xmx512m InstallDirTest
+ * @run main/othervm/timeout=360 -Xmx512m InstallDirTest
  */
 public class InstallDirTest {
     private static final String TEST_NAME = "InstallDirTest";
--- a/test/jdk/tools/jpackage/linux/deb/LicenseTest.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/LicenseTest.java	Fri Jul 26 16:25:05 2019 +0300
@@ -33,7 +33,7 @@
  * @requires (os.family == "linux")
  * @modules jdk.jpackage
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm -Xmx512m LicenseTest
+ * @run main/othervm/timeout=360 -Xmx512m LicenseTest
  */
 public class LicenseTest {
     private static final String TEST_NAME = "LicenseTest";
--- a/test/jdk/tools/jpackage/linux/deb/MaintainerTest.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/MaintainerTest.java	Fri Jul 26 16:25:05 2019 +0300
@@ -33,7 +33,7 @@
  * @requires (os.family == "linux")
  * @modules jdk.jpackage
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm -Xmx512m MaintainerTest
+ * @run main/othervm/timeout=360 -Xmx512m MaintainerTest
  */
 public class MaintainerTest {
     private static final String TEST_NAME = "MaintainerTest";
--- a/test/jdk/tools/jpackage/linux/deb/PackageDepsTest.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/PackageDepsTest.java	Fri Jul 26 16:25:05 2019 +0300
@@ -33,7 +33,7 @@
  * @requires (os.family == "linux")
  * @modules jdk.jpackage
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm/timeout=240 -Xmx512m PackageDepsTest
+ * @run main/othervm/timeout=420 -Xmx512m PackageDepsTest
  */
 public class PackageDepsTest {
     private static final String TEST_NAME = "PackageDepsTest";
--- a/test/jdk/tools/jpackage/linux/deb/Test.java	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/Test.java	Fri Jul 26 16:25:05 2019 +0300
@@ -33,7 +33,7 @@
  * @requires (os.family == "linux")
  * @modules jdk.jpackage
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm -Xmx512m Test
+ * @run main/othervm/timeout=300 -Xmx512m Test
  */
 public class Test {
     private static final String TEST_NAME = "Test";
--- a/test/jdk/tools/jpackage/linux/rpm/install.sh	Thu Jul 25 08:24:01 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/rpm/install.sh	Fri Jul 26 16:25:05 2019 +0300
@@ -1,8 +1,9 @@
-sudo rpm --install fileassociationstest-1.0-1.x86_64.rpm
-sudo rpm --install installdirtest-1.0-1.x86_64.rpm
-sudo rpm --install licensetest-1.0-1.x86_64.rpm
-sudo rpm --install licensetypetest-1.0-1.x86_64.rpm
-sudo rpm --install packagedepstestdep-1.0-1.x86_64.rpm
-sudo rpm --install packagedepstest-1.0-1.x86_64.rpm
-sudo rpm --install test-1.0-1.x86_64.rpm
-sudo rpm --install jpackage-test-bundle-name-1.0-1.x86_64.rpm
+ARCH=$(rpmbuild -E='%{_target_cpu}')
+sudo rpm --install fileassociationstest-1.0-1.${ARCH}.rpm
+sudo rpm --install installdirtest-1.0-1.${ARCH}.rpm
+sudo rpm --install licensetest-1.0-1.${ARCH}.rpm
+sudo rpm --install licensetypetest-1.0-1.${ARCH}.rpm
+sudo rpm --install packagedepstestdep-1.0-1.${ARCH}.rpm
+sudo rpm --install packagedepstest-1.0-1.${ARCH}.rpm
+sudo rpm --install test-1.0-1.${ARCH}.rpm
+sudo rpm --install jpackage-test-bundle-name-1.0-1.${ARCH}.rpm