Skip to content
Permalink
Browse files
8276084: Linux DEB Bundler: release number in outputted .deb file sho…
…uld be optional

Reviewed-by: almatvee, herrick
  • Loading branch information
Alexey Semenyuk committed Nov 15, 2021
1 parent 7fc344d commit 9046077fe6ce7bb042fbd0fa1a80537cb4a60581
@@ -108,12 +108,17 @@ public class LinuxDebBundler extends LinuxPackageBundler {
DEB_ARCH = debArch;
}

private static final String releaseSuffix(Map<String, ? super Object> params) {
return Optional.ofNullable(RELEASE.fetchFrom(params, false)).map(
rel -> "-" + rel).orElse("");
}

private static final BundlerParamInfo<String> FULL_PACKAGE_NAME =
new StandardBundlerParam<>(
"linux.deb.fullPackageName", String.class, params -> {
return PACKAGE_NAME.fetchFrom(params)
+ "_" + VERSION.fetchFrom(params)
+ "-" + RELEASE.fetchFrom(params)
+ releaseSuffix(params)
+ "_" + DEB_ARCH;
}, (s, p) -> s);

@@ -275,9 +280,9 @@ protected List<ConfigException> verifyOutputBundle(
List<PackageProperty> properties = List.of(
new PackageProperty("Package", PACKAGE_NAME.fetchFrom(params),
"APPLICATION_PACKAGE", controlFileName),
new PackageProperty("Version", String.format("%s-%s",
VERSION.fetchFrom(params), RELEASE.fetchFrom(params)),
"APPLICATION_VERSION-APPLICATION_RELEASE",
new PackageProperty("Version", String.format("%s%s",
VERSION.fetchFrom(params), releaseSuffix(params)),
"APPLICATION_VERSION_WITH_RELEASE",
controlFileName),
new PackageProperty("Architecture", DEB_ARCH, "APPLICATION_ARCH",
controlFileName));
@@ -442,6 +447,8 @@ protected Map<String, String> createReplacementData(
data.put("APPLICATION_HOMEPAGE", Optional.ofNullable(
ABOUT_URL.fetchFrom(params)).map(value -> "Homepage: " + value).orElse(
""));
data.put("APPLICATION_VERSION_WITH_RELEASE", String.format("%s%s",
VERSION.fetchFrom(params), releaseSuffix(params)));

return data;
}
@@ -220,7 +220,6 @@ private Map<String, String> createDefaultReplacementData(
data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params));
data.put("APPLICATION_VERSION", VERSION.fetchFrom(params));
data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
data.put("APPLICATION_RELEASE", RELEASE.fetchFrom(params));

String defaultDeps = String.join(", ", getListOfNeededPackages(params));
String customDeps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params).strip();
@@ -177,6 +177,7 @@ protected Map<String, String> createReplacementData(
appDirectory = appDirectory.resolve(PACKAGE_NAME.fetchFrom(params));
}

data.put("APPLICATION_RELEASE", RELEASE.fetchFrom(params));
data.put("APPLICATION_PREFIX", prefix.toString());
data.put("APPLICATION_DIRECTORY", appDirectory.toString());
data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params));
@@ -1,5 +1,5 @@
Package: APPLICATION_PACKAGE
Version: APPLICATION_VERSION-APPLICATION_RELEASE
Version: APPLICATION_VERSION_WITH_RELEASE
Section: APPLICATION_SECTION
Maintainer: APPLICATION_MAINTAINER
Priority: optional
@@ -44,8 +44,22 @@


public class LinuxHelper {
private static String getRelease(JPackageCommand cmd) {
return cmd.getArgumentValue("--linux-app-release", () -> "1");
private static String getReleaseSuffix(JPackageCommand cmd) {
String value = null;
final PackageType packageType = cmd.packageType();
switch (packageType) {
case LINUX_DEB:
value = Optional.ofNullable(cmd.getArgumentValue(
"--linux-app-release", () -> null)).map(v -> "-" + v).orElse(
"");
break;

case LINUX_RPM:
value = "-" + cmd.getArgumentValue("--linux-app-release",
() -> "1");
break;
}
return value;
}

public static String getPackageName(JPackageCommand cmd) {
@@ -74,18 +88,18 @@ static String getBundleName(JPackageCommand cmd) {
String format = null;
switch (packageType) {
case LINUX_DEB:
format = "%s_%s-%s_%s";
format = "%s_%s%s_%s";
break;

case LINUX_RPM:
format = "%s-%s-%s.%s";
format = "%s-%s%s.%s";
break;
}

final String release = getRelease(cmd);
final String releaseSuffix = getReleaseSuffix(cmd);
final String version = cmd.version();

return String.format(format, getPackageName(cmd), version, release,
return String.format(format, getPackageName(cmd), version, releaseSuffix,
getDefaultPackageArch(packageType)) + packageType.getSuffix();
}

@@ -81,7 +81,7 @@ public static void testHardcodedProperties() throws IOException {
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(
"Expected value of \"Version\" property is [1.0-1]. Actual value in output package is [1.2.3-R2]")
"Expected value of \"Version\" property is [1.0]. Actual value in output package is [1.2.3-R2]")
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(String.format(
@@ -24,6 +24,7 @@
import jdk.jpackage.test.PackageType;
import jdk.jpackage.test.PackageTest;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.JPackageCommand;


/**
@@ -47,10 +48,26 @@
* @build jdk.jpackage.test.*
* @build ReleaseTest
* @requires (os.family == "linux")
* @requires (jpackage.test.SQETest == null)
* @modules jdk.jpackage/jdk.jpackage.internal
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=ReleaseTest
*/

/*
* @test
* @summary jpackage with --linux-app-release
* @library ../helpers
* @key jpackagePlatformPackage
* @build jdk.jpackage.test.*
* @build ReleaseTest
* @requires (os.family == "linux")
* @requires (jpackage.test.SQETest != null)
* @modules jdk.jpackage/jdk.jpackage.internal
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=ReleaseTest.test
*/

public class ReleaseTest {

@Test
@@ -71,4 +88,17 @@ public static void test() {
}, "ends with")
.run();
}

@Test
public static void testNoExplitRelease() {
new PackageTest()
.forTypes(PackageType.LINUX)
.configureHelloApp()
.addInitializer(JPackageCommand::setFakeRuntime)
.forTypes(PackageType.LINUX_RPM)
.addBundlePropertyVerifier("Release", "1")
.forTypes(PackageType.LINUX_DEB)
.addBundlePropertyVerifier("Version", "1.0")
.run();
}
}

1 comment on commit 9046077

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 9046077 Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.