8225447: Revise Debian packaging
Submitted-by: asemenyuk
Reviewed-by: kcr, almatvee
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java Mon Aug 19 17:39:48 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java Mon Aug 19 20:31:10 2019 -0400
@@ -29,8 +29,13 @@
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.charset.StandardCharsets;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
+
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.text.MessageFormat;
@@ -315,19 +320,22 @@
private boolean prepareProto(Map<String, ? super Object> params)
throws PackagerException, IOException {
File appImage = StandardBundlerParam.getPredefinedAppImage(params);
- File appDir = null;
// we either have an application image or need to build one
if (appImage != null) {
- appDir = new File(APP_IMAGE_ROOT.fetchFrom(params),
- APP_NAME.fetchFrom(params));
// copy everything from appImage dir into appDir/name
- IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
+ IOUtils.copyRecursive(appImage.toPath(),
+ getConfig_RootDirectory(params).toPath());
} else {
- appDir = APP_BUNDLER.fetchFrom(params).doBundle(params,
+ File bundleDir = APP_BUNDLER.fetchFrom(params).doBundle(params,
APP_IMAGE_ROOT.fetchFrom(params), true);
+ if (bundleDir == null) {
+ return false;
+ }
+ Files.move(bundleDir.toPath(), getConfig_RootDirectory(
+ params).toPath(), StandardCopyOption.REPLACE_EXISTING);
}
- return appDir != null;
+ return true;
}
public File bundle(Map<String, ? super Object> params,
@@ -355,6 +363,7 @@
imageDir.mkdirs();
configDir.mkdirs();
if (prepareProto(params) && prepareProjectConfig(params)) {
+ adjustPermissionsRecursive(imageDir);
return buildDeb(params, outdir);
}
return null;
@@ -412,11 +421,38 @@
return count;
}
+ private void adjustPermissionsRecursive(File dir) throws IOException {
+ Files.walkFileTree(dir.toPath(), new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file,
+ BasicFileAttributes attrs)
+ throws IOException {
+ if (file.endsWith(".so") || !Files.isExecutable(file)) {
+ setPermissions(file.toFile(), "rw-r--r--");
+ } else if (Files.isExecutable(file)) {
+ setPermissions(file.toFile(), "rwxr-xr-x");
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException e)
+ throws IOException {
+ if (e == null) {
+ setPermissions(dir.toFile(), "rwxr-xr-x");
+ return FileVisitResult.CONTINUE;
+ } else {
+ // directory iteration failed
+ throw e;
+ }
+ }
+ });
+ }
+
private boolean prepareProjectConfig(Map<String, ? super Object> params)
throws IOException {
Map<String, String> data = createReplacementData(params);
- File rootDir = LinuxAppBundler.getRootDir(APP_IMAGE_ROOT.fetchFrom(
- params), params);
+ File rootDir = getConfig_RootDirectory(params);
File binDir = new File(rootDir, "bin");
File iconTarget = getConfig_IconFile(binDir, params);
@@ -576,7 +612,7 @@
.append(LINUX_INSTALL_DIR.fetchFrom(params))
.append("/")
.append(data.get("APPLICATION_FS_NAME"))
- .append("/")
+ .append("/bin/")
.append(mimeInfoFile)
.append("\n");
@@ -584,7 +620,7 @@
.append(LINUX_INSTALL_DIR.fetchFrom(params))
.append("/")
.append(data.get("APPLICATION_FS_NAME"))
- .append("/")
+ .append("/bin/")
.append(mimeInfoFile)
.append("\n");
addedEntry = true;
@@ -759,7 +795,8 @@
String launcher = LinuxAppImageBuilder.getLauncherRelativePath(params);
data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params));
- data.put("APPLICATION_FS_NAME", APP_NAME.fetchFrom(params));
+ data.put("APPLICATION_FS_NAME",
+ getConfig_RootDirectory(params).getName());
data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params));
data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params));
data.put("APPLICATION_MAINTAINER", MAINTAINER.fetchFrom(params));
@@ -776,9 +813,8 @@
data.put("APPLICATION_ARCH", getDebArch());
data.put("APPLICATION_INSTALLED_SIZE",
Long.toString(getInstalledSizeKB(params)));
- String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
- data.put("PACKAGE_DEPENDENCIES",
- deps.isEmpty() ? "" : "Depends: " + deps);
+ data.put("PACKAGE_DEPENDENCIES", LINUX_PACKAGE_DEPENDENCIES.fetchFrom(
+ params));
data.put("RUNTIME_INSTALLER", "" +
StandardBundlerParam.isRuntimeInstaller(params));
@@ -820,6 +856,12 @@
"share", "doc", BUNDLE_NAME.fetchFrom(params), "copyright").toFile();
}
+ private File getConfig_RootDirectory(
+ Map<String, ? super Object> params) {
+ return Path.of(APP_IMAGE_ROOT.fetchFrom(params).getAbsolutePath(),
+ BUNDLE_NAME.fetchFrom(params)).toFile();
+ }
+
private File buildDeb(Map<String, ? super Object> params,
File outdir) throws IOException {
File outFile = new File(outdir,
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Mon Aug 19 17:39:48 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Mon Aug 19 20:31:10 2019 -0400
@@ -449,7 +449,7 @@
.append(LINUX_INSTALL_DIR.fetchFrom(params))
.append("/")
.append(data.get("APPLICATION_FS_NAME"))
- .append("/")
+ .append("/bin/")
.append(mimeInfoFile)
.append("\n");
@@ -457,7 +457,7 @@
.append(LINUX_INSTALL_DIR.fetchFrom(params))
.append("/")
.append(data.get("APPLICATION_FS_NAME"))
- .append("/")
+ .append("/bin/")
.append(mimeInfoFile)
.append("\n");
addedEntry = true;
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.control Mon Aug 19 17:39:48 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.control Mon Aug 19 20:31:10 2019 -0400
@@ -7,5 +7,5 @@
Architecture: APPLICATION_ARCH
Provides: APPLICATION_PACKAGE
Description: APPLICATION_DESCRIPTION
+Depends: PACKAGE_DEPENDENCIES
Installed-Size: APPLICATION_INSTALLED_SIZE
-PACKAGE_DEPENDENCIES
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.postinst Mon Aug 19 17:39:48 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.postinst Mon Aug 19 20:31:10 2019 -0400
@@ -25,23 +25,6 @@
xdg-desktop-menu install --novendor INSTALLATION_DIRECTORY/APPLICATION_FS_NAME/APPLICATION_LAUNCHER_FILENAME.desktop
FILE_ASSOCIATION_INSTALL
fi
- if [ "SERVICE_HINT" = "true" ]; then
- echo Installing daemon
- cp INSTALLATION_DIRECTORY/APPLICATION_FS_NAME/APPLICATION_PACKAGE.init /etc/init.d/APPLICATION_PACKAGE
-
- if [ -x "/etc/init.d/APPLICATION_PACKAGE" ]; then
- update-rc.d APPLICATION_PACKAGE defaults
-
- if [ "START_ON_INSTALL" = "true" ]; then
- if which invoke-rc.d >/dev/null 2>&1; then
- invoke-rc.d APPLICATION_PACKAGE start
- else
- /etc/init.d/APPLICATION_PACKAGE start
- fi
- fi
- fi
-
- fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
@@ -53,9 +36,4 @@
;;
esac
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
exit 0
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.postrm Mon Aug 19 17:39:48 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.postrm Mon Aug 19 20:31:10 2019 -0400
@@ -20,14 +20,6 @@
case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
- if [ "$1" = "purge" ] ; then
- if [ "SERVICE_HINT" = "true" ]; then
- echo Uninstalling daemon
- rm -f /etc/init.d/APPLICATION_PACKAGE
-
- update-rc.d APPLICATION_PACKAGE remove
- fi
- fi
;;
*)
@@ -36,9 +28,4 @@
;;
esac
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
exit 0
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.preinst Mon Aug 19 17:39:48 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.preinst Mon Aug 19 20:31:10 2019 -0400
@@ -27,9 +27,4 @@
;;
esac
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
exit 0
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.prerm Mon Aug 19 17:39:48 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/template.prerm Mon Aug 19 20:31:10 2019 -0400
@@ -36,10 +36,5 @@
;;
esac
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
exit 0
--- a/test/jdk/tools/jpackage/helpers/JPackagePath.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/helpers/JPackagePath.java Mon Aug 19 20:31:10 2019 -0400
@@ -223,10 +223,7 @@
}
public static String getLinuxInstalledApp(String subDir, String testName) {
- return File.separator + "opt"
- + File.separator + subDir
- + File.separator + testName
- + File.separator + testName;
+ return Path.of("/opt", subDir, testName, "bin", testName).toString();
}
public static String getWinInstallFolder(String testName) {
--- a/test/jdk/tools/jpackage/linux/base/MaintainerBase.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/base/MaintainerBase.java Mon Aug 19 20:31:10 2019 -0400
@@ -53,9 +53,18 @@
throw new AssertionError(infoResult + " was not created");
}
- String output = Files.readString(outfile.toPath());
- if (!output.contains("Maintainer: " + EMAIL)) {
- throw new AssertionError("Unexpected result: " + output);
+ boolean maintainerFound = false;
+ for (String line: Files.readAllLines(outfile.toPath())) {
+ if (line.matches("^[ ]*Maintainer:.*$")) {
+ maintainerFound = true;
+ if (!line.contains(EMAIL)) {
+ throw new AssertionError("Unexpected result: " + line);
+ }
+ }
+ }
+
+ if (!maintainerFound) {
+ throw new AssertionError("Maintainer field not found");
}
}
--- a/test/jdk/tools/jpackage/linux/deb/BundleNameTest.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/BundleNameTest.java Mon Aug 19 20:31:10 2019 -0400
@@ -36,7 +36,7 @@
* @run main/othervm/timeout=360 -Xmx512m BundleNameTest
*/
public class BundleNameTest {
- private static final String TEST_NAME = "BundleNameTest";
+ private static final String TEST_NAME = "bundlenametest";
private static final String EXT = "deb";
public static void main(String[] args) throws Exception {
--- a/test/jdk/tools/jpackage/linux/deb/FileAssociationsTest.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/FileAssociationsTest.java Mon Aug 19 20:31:10 2019 -0400
@@ -36,7 +36,7 @@
* @run main/othervm/timeout=360 -Xmx512m FileAssociationsTest
*/
public class FileAssociationsTest {
- private static final String TEST_NAME = "FileAssociationsTest";
+ private static final String TEST_NAME = "fileassociationstest";
private static final String EXT = "deb";
public static void main(String[] args) throws Exception {
--- a/test/jdk/tools/jpackage/linux/deb/InstallDirTest.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/InstallDirTest.java Mon Aug 19 20:31:10 2019 -0400
@@ -36,7 +36,7 @@
* @run main/othervm/timeout=360 -Xmx512m InstallDirTest
*/
public class InstallDirTest {
- private static final String TEST_NAME = "InstallDirTest";
+ private static final String TEST_NAME = "installdirtest";
private static final String EXT = "deb";
public static void main(String[] args) throws Exception {
--- a/test/jdk/tools/jpackage/linux/deb/LicenseTest.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/LicenseTest.java Mon Aug 19 20:31:10 2019 -0400
@@ -36,7 +36,7 @@
* @run main/othervm/timeout=360 -Xmx512m LicenseTest
*/
public class LicenseTest {
- private static final String TEST_NAME = "LicenseTest";
+ private static final String TEST_NAME = "licensetest";
private static final String EXT = "deb";
public static void main(String[] args) throws Exception {
--- a/test/jdk/tools/jpackage/linux/deb/MaintainerTest.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/MaintainerTest.java Mon Aug 19 20:31:10 2019 -0400
@@ -36,7 +36,7 @@
* @run main/othervm/timeout=360 -Xmx512m MaintainerTest
*/
public class MaintainerTest {
- private static final String TEST_NAME = "MaintainerTest";
+ private static final String TEST_NAME = "maintainertest";
private static final String EXT = "deb";
public static void main(String[] args) throws Exception {
--- a/test/jdk/tools/jpackage/linux/deb/PackageDepsTest.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/PackageDepsTest.java Mon Aug 19 20:31:10 2019 -0400
@@ -36,7 +36,7 @@
* @run main/othervm/timeout=420 -Xmx512m PackageDepsTest
*/
public class PackageDepsTest {
- private static final String TEST_NAME = "PackageDepsTest";
+ private static final String TEST_NAME = "packagedepstest";
private static final String EXT = "deb";
public static void main(String[] args) throws Exception {
--- a/test/jdk/tools/jpackage/linux/deb/Test.java Mon Aug 19 17:39:48 2019 -0400
+++ b/test/jdk/tools/jpackage/linux/deb/Test.java Mon Aug 19 20:31:10 2019 -0400
@@ -36,7 +36,7 @@
* @run main/othervm/timeout=300 -Xmx512m Test
*/
public class Test {
- private static final String TEST_NAME = "Test";
+ private static final String TEST_NAME = "test";
private static final String EXT = "deb";
public static void main(String[] args) throws Exception {