From 9aee154a4549f9336452f03dd6c0afe8dbc2273d Mon Sep 17 00:00:00 2001 From: Oleg Estekhin Date: Fri, 17 Nov 2023 11:39:00 +0300 Subject: [PATCH 1/4] add betaExpand parameter to convertToDebianVersion --- .../java/org/vafer/jdeb/maven/DebMojo.java | 2 +- src/main/java/org/vafer/jdeb/utils/Utils.java | 5 +- .../org/vafer/jdeb/utils/UtilsTestCase.java | 94 +++++++++---------- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/vafer/jdeb/maven/DebMojo.java b/src/main/java/org/vafer/jdeb/maven/DebMojo.java index be807ec01..0df4c798b 100644 --- a/src/main/java/org/vafer/jdeb/maven/DebMojo.java +++ b/src/main/java/org/vafer/jdeb/maven/DebMojo.java @@ -440,7 +440,7 @@ protected VariableResolver initializeVariableResolver( Map varia * @return the Maven project version */ private String getProjectVersion() { - return Utils.convertToDebianVersion(getProject().getVersion(), this.snapshotExpand, this.snapshotEnv, this.snapshotTemplate, session.getStartTime()); + return Utils.convertToDebianVersion(getProject().getVersion(), this.snapshotExpand, this.snapshotEnv, this.snapshotTemplate, session.getStartTime(), true); } /** diff --git a/src/main/java/org/vafer/jdeb/utils/Utils.java b/src/main/java/org/vafer/jdeb/utils/Utils.java index 689362db5..ecf6b87b0 100644 --- a/src/main/java/org/vafer/jdeb/utils/Utils.java +++ b/src/main/java/org/vafer/jdeb/utils/Utils.java @@ -250,8 +250,9 @@ private static String formatSnapshotTemplate( String template, Date timestamp ) * @param template the template used to replace -SNAPSHOT, the timestamp format is in brackets, * the rest of the string is preserved (prefix[yyMMdd]suffix -> prefix151230suffix) * @param timestamp the UTC date used as the timestamp to replace the SNAPSHOT suffix. + * @param betaExpand whether to process the rc, alpha or beta version */ - public static String convertToDebianVersion( String version, boolean apply, String envName, String template, Date timestamp ) { + public static String convertToDebianVersion( String version, boolean apply, String envName, String template, Date timestamp, boolean betaExpand ) { Matcher matcher = SNAPSHOT_PATTERN.matcher(version); if (matcher.matches()) { version = matcher.group(1) + "~"; @@ -270,7 +271,7 @@ public static String convertToDebianVersion( String version, boolean apply, Stri } else { version += "SNAPSHOT"; } - } else { + } else if (betaExpand) { matcher = BETA_PATTERN.matcher(version); if (matcher.matches()) { if (matcher.group(1) != null) { diff --git a/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java b/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java index ac1e59523..f1b4b1198 100644 --- a/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java +++ b/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java @@ -140,57 +140,57 @@ public void testReplaceVariablesWithinOpenCloseTokens() { public void testVersionConversion() { Calendar cal = new GregorianCalendar(2013, Calendar.FEBRUARY, 17); cal.setTimeZone(TimeZone.getTimeZone("UTC")); - assertEquals("should match", "1.0", Utils.convertToDebianVersion("1.0", false, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~20130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~RC2", Utils.convertToDebianVersion("1.0-RC2", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~alpha3", Utils.convertToDebianVersion("1.0-alpha3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~Beta+4", Utils.convertToDebianVersion("1.0.Beta-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~milestone+4", Utils.convertToDebianVersion("1.0-milestone-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0-a-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0a-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~b+4", Utils.convertToDebianVersion("1.0-b-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~rc7", Utils.convertToDebianVersion("1.0rc7", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~M1", Utils.convertToDebianVersion("1.0.M1", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~M2", Utils.convertToDebianVersion("1.0-M2", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0~M3", Utils.convertToDebianVersion("1.0M3", true, "SNAPSHOT", null, cal.getTime())); - - assertEquals("should match", "1.0+prj+3", Utils.convertToDebianVersion("1.0-prj_3", false, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~20130217000000", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~RC2", Utils.convertToDebianVersion("1.0-prj_3-RC2", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~alpha3", Utils.convertToDebianVersion("1.0-prj_3-alpha3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~Beta+4", Utils.convertToDebianVersion("1.0-prj_3.Beta-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~milestone+4", Utils.convertToDebianVersion("1.0-prj_3-milestone-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~a+4", Utils.convertToDebianVersion("1.0-prj_3-a-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~b+4", Utils.convertToDebianVersion("1.0-prj_3-b-4", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~rc7", Utils.convertToDebianVersion("1.0-prj_3-rc7", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~M1", Utils.convertToDebianVersion("1.0-prj_3.M1", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3~M2", Utils.convertToDebianVersion("1.0-prj_3-M2", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj~M3", Utils.convertToDebianVersion("1.0-prj_M3", true, "SNAPSHOT", null, cal.getTime())); - - assertEquals("should match", "1.0+prj+~M3", Utils.convertToDebianVersion("1.0-prj__-M3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+.+~M3", Utils.convertToDebianVersion("1.0-prj_._-M3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3+~M3", Utils.convertToDebianVersion("1.0-prj_3:M3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c+++++++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime())); - - assertEquals("should match", "1.0+MMM+3", Utils.convertToDebianVersion("1.0-MMM-3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+aaa+3", Utils.convertToDebianVersion("1.0-aaa-3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0+bbb+3", Utils.convertToDebianVersion("1.0-bbb-3", true, "SNAPSHOT", null, cal.getTime())); - assertEquals("should match", "1.0aaa+3", Utils.convertToDebianVersion("1.0aaa-3", true, "SNAPSHOT", null, cal.getTime())); + assertEquals("should match", "1.0", Utils.convertToDebianVersion("1.0", false, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~20130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~RC2", Utils.convertToDebianVersion("1.0-RC2", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~alpha3", Utils.convertToDebianVersion("1.0-alpha3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~Beta+4", Utils.convertToDebianVersion("1.0.Beta-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~milestone+4", Utils.convertToDebianVersion("1.0-milestone-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0-a-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0a-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~b+4", Utils.convertToDebianVersion("1.0-b-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~rc7", Utils.convertToDebianVersion("1.0rc7", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~M1", Utils.convertToDebianVersion("1.0.M1", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~M2", Utils.convertToDebianVersion("1.0-M2", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0~M3", Utils.convertToDebianVersion("1.0M3", true, "SNAPSHOT", null, cal.getTime(), true)); + + assertEquals("should match", "1.0+prj+3", Utils.convertToDebianVersion("1.0-prj_3", false, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~20130217000000", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~RC2", Utils.convertToDebianVersion("1.0-prj_3-RC2", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~alpha3", Utils.convertToDebianVersion("1.0-prj_3-alpha3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~Beta+4", Utils.convertToDebianVersion("1.0-prj_3.Beta-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~milestone+4", Utils.convertToDebianVersion("1.0-prj_3-milestone-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~a+4", Utils.convertToDebianVersion("1.0-prj_3-a-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~b+4", Utils.convertToDebianVersion("1.0-prj_3-b-4", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~rc7", Utils.convertToDebianVersion("1.0-prj_3-rc7", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~M1", Utils.convertToDebianVersion("1.0-prj_3.M1", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3~M2", Utils.convertToDebianVersion("1.0-prj_3-M2", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj~M3", Utils.convertToDebianVersion("1.0-prj_M3", true, "SNAPSHOT", null, cal.getTime(), true)); + + assertEquals("should match", "1.0+prj+~M3", Utils.convertToDebianVersion("1.0-prj__-M3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+.+~M3", Utils.convertToDebianVersion("1.0-prj_._-M3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3+~M3", Utils.convertToDebianVersion("1.0-prj_3:M3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c+++++++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), true)); + + assertEquals("should match", "1.0+MMM+3", Utils.convertToDebianVersion("1.0-MMM-3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+aaa+3", Utils.convertToDebianVersion("1.0-aaa-3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0+bbb+3", Utils.convertToDebianVersion("1.0-bbb-3", true, "SNAPSHOT", null, cal.getTime(), true)); + assertEquals("should match", "1.0aaa+3", Utils.convertToDebianVersion("1.0aaa-3", true, "SNAPSHOT", null, cal.getTime(), true)); } public void testVersionConversionWithTemplate() { Calendar cal = new GregorianCalendar(2013, Calendar.FEBRUARY, 17); - assertEquals("should match", "1.0~20130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "[yyyyMMddHHmmss]", cal.getTime())); - assertEquals("should match", "1.0~130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "[yyMMddHHmmss]", cal.getTime())); - assertEquals("should match", "1.0~20130217", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "[yyyyMMdd]", cal.getTime())); - assertEquals("should match", "1.0~100.20130217", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "100.[yyyyMMdd]", cal.getTime())); - assertEquals("should match", "1.0~100.20130217.50", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "100.[yyyyMMdd].50", cal.getTime())); - assertEquals("should match", "1.0~100.20130217.foo", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "100.[yyyyMMdd].foo", cal.getTime())); + assertEquals("should match", "1.0~20130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "[yyyyMMddHHmmss]", cal.getTime(), true)); + assertEquals("should match", "1.0~130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "[yyMMddHHmmss]", cal.getTime(), true)); + assertEquals("should match", "1.0~20130217", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "[yyyyMMdd]", cal.getTime(), true)); + assertEquals("should match", "1.0~100.20130217", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "100.[yyyyMMdd]", cal.getTime(), true)); + assertEquals("should match", "1.0~100.20130217.50", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "100.[yyyyMMdd].50", cal.getTime(), true)); + assertEquals("should match", "1.0~100.20130217.foo", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "100.[yyyyMMdd].foo", cal.getTime(), true)); } @Test From a1c6e598b5ee33ccd18232d29a23e50c89896b6e Mon Sep 17 00:00:00 2001 From: Oleg Estekhin Date: Fri, 17 Nov 2023 11:41:14 +0300 Subject: [PATCH 2/4] add faling testVersionConversionWithoutBetaExpand test --- .../org/vafer/jdeb/utils/UtilsTestCase.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java b/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java index f1b4b1198..1f67314d9 100644 --- a/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java +++ b/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java @@ -183,6 +183,53 @@ public void testVersionConversion() { assertEquals("should match", "1.0aaa+3", Utils.convertToDebianVersion("1.0aaa-3", true, "SNAPSHOT", null, cal.getTime(), true)); } + @Test + public void testVersionConversionWithoutBetaExpand() { + Calendar cal = new GregorianCalendar(2013, Calendar.FEBRUARY, 17); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + assertEquals("should match", "1.0", Utils.convertToDebianVersion("1.0", false, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~20130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~RC2", Utils.convertToDebianVersion("1.0-RC2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~alpha3", Utils.convertToDebianVersion("1.0-alpha3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~Beta+4", Utils.convertToDebianVersion("1.0.Beta-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~milestone+4", Utils.convertToDebianVersion("1.0-milestone-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0-a-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0a-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~b+4", Utils.convertToDebianVersion("1.0-b-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~rc7", Utils.convertToDebianVersion("1.0rc7", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~M1", Utils.convertToDebianVersion("1.0.M1", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~M2", Utils.convertToDebianVersion("1.0-M2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0~M3", Utils.convertToDebianVersion("1.0M3", true, "SNAPSHOT", null, cal.getTime(), false)); + + assertEquals("should match", "1.0+prj+3", Utils.convertToDebianVersion("1.0-prj_3", false, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~20130217000000", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~RC2", Utils.convertToDebianVersion("1.0-prj_3-RC2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~alpha3", Utils.convertToDebianVersion("1.0-prj_3-alpha3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~Beta+4", Utils.convertToDebianVersion("1.0-prj_3.Beta-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~milestone+4", Utils.convertToDebianVersion("1.0-prj_3-milestone-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~a+4", Utils.convertToDebianVersion("1.0-prj_3-a-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~b+4", Utils.convertToDebianVersion("1.0-prj_3-b-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~rc7", Utils.convertToDebianVersion("1.0-prj_3-rc7", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~M1", Utils.convertToDebianVersion("1.0-prj_3.M1", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3~M2", Utils.convertToDebianVersion("1.0-prj_3-M2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj~M3", Utils.convertToDebianVersion("1.0-prj_M3", true, "SNAPSHOT", null, cal.getTime(), false)); + + assertEquals("should match", "1.0+prj+~M3", Utils.convertToDebianVersion("1.0-prj__-M3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+.+~M3", Utils.convertToDebianVersion("1.0-prj_._-M3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+~M3", Utils.convertToDebianVersion("1.0-prj_3:M3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c+++++++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); + + assertEquals("should match", "1.0+MMM+3", Utils.convertToDebianVersion("1.0-MMM-3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+aaa+3", Utils.convertToDebianVersion("1.0-aaa-3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+bbb+3", Utils.convertToDebianVersion("1.0-bbb-3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0aaa+3", Utils.convertToDebianVersion("1.0aaa-3", true, "SNAPSHOT", null, cal.getTime(), false)); + } + public void testVersionConversionWithTemplate() { Calendar cal = new GregorianCalendar(2013, Calendar.FEBRUARY, 17); assertEquals("should match", "1.0~20130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", "[yyyyMMddHHmmss]", cal.getTime(), true)); From 666b831857bca5ed534b8aa60918f4fdb5bf4069 Mon Sep 17 00:00:00 2001 From: Oleg Estekhin Date: Fri, 17 Nov 2023 11:49:54 +0300 Subject: [PATCH 3/4] fix testVersionConversionWithoutBetaExpand test --- .../org/vafer/jdeb/utils/UtilsTestCase.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java b/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java index 1f67314d9..008920d55 100644 --- a/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java +++ b/src/test/java/org/vafer/jdeb/utils/UtilsTestCase.java @@ -191,36 +191,36 @@ public void testVersionConversionWithoutBetaExpand() { assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0~SNAPSHOT", Utils.convertToDebianVersion("1.0-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0~20130217000000", Utils.convertToDebianVersion("1.0+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~RC2", Utils.convertToDebianVersion("1.0-RC2", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~alpha3", Utils.convertToDebianVersion("1.0-alpha3", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~Beta+4", Utils.convertToDebianVersion("1.0.Beta-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~milestone+4", Utils.convertToDebianVersion("1.0-milestone-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0-a-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~a+4", Utils.convertToDebianVersion("1.0a-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~b+4", Utils.convertToDebianVersion("1.0-b-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~rc7", Utils.convertToDebianVersion("1.0rc7", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~M1", Utils.convertToDebianVersion("1.0.M1", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~M2", Utils.convertToDebianVersion("1.0-M2", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0~M3", Utils.convertToDebianVersion("1.0M3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+RC2", Utils.convertToDebianVersion("1.0-RC2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+alpha3", Utils.convertToDebianVersion("1.0-alpha3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0.Beta+4", Utils.convertToDebianVersion("1.0.Beta-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+milestone+4", Utils.convertToDebianVersion("1.0-milestone-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+a+4", Utils.convertToDebianVersion("1.0-a-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0a+4", Utils.convertToDebianVersion("1.0a-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+b+4", Utils.convertToDebianVersion("1.0-b-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0rc7", Utils.convertToDebianVersion("1.0rc7", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0.M1", Utils.convertToDebianVersion("1.0.M1", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+M2", Utils.convertToDebianVersion("1.0-M2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0M3", Utils.convertToDebianVersion("1.0M3", true, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0+prj+3", Utils.convertToDebianVersion("1.0-prj_3", false, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0+prj+3~SNAPSHOT", Utils.convertToDebianVersion("1.0-prj_3-SNAPSHOT", false, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0+prj+3~20130217000000", Utils.convertToDebianVersion("1.0-prj_3+SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~RC2", Utils.convertToDebianVersion("1.0-prj_3-RC2", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~alpha3", Utils.convertToDebianVersion("1.0-prj_3-alpha3", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~Beta+4", Utils.convertToDebianVersion("1.0-prj_3.Beta-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~milestone+4", Utils.convertToDebianVersion("1.0-prj_3-milestone-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~a+4", Utils.convertToDebianVersion("1.0-prj_3-a-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~b+4", Utils.convertToDebianVersion("1.0-prj_3-b-4", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~rc7", Utils.convertToDebianVersion("1.0-prj_3-rc7", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~M1", Utils.convertToDebianVersion("1.0-prj_3.M1", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3~M2", Utils.convertToDebianVersion("1.0-prj_3-M2", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj~M3", Utils.convertToDebianVersion("1.0-prj_M3", true, "SNAPSHOT", null, cal.getTime(), false)); - - assertEquals("should match", "1.0+prj+~M3", Utils.convertToDebianVersion("1.0-prj__-M3", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+.+~M3", Utils.convertToDebianVersion("1.0-prj_._-M3", true, "SNAPSHOT", null, cal.getTime(), false)); - assertEquals("should match", "1.0+prj+3+~M3", Utils.convertToDebianVersion("1.0-prj_3:M3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+RC2", Utils.convertToDebianVersion("1.0-prj_3-RC2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+alpha3", Utils.convertToDebianVersion("1.0-prj_3-alpha3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3.Beta+4", Utils.convertToDebianVersion("1.0-prj_3.Beta-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+milestone+4", Utils.convertToDebianVersion("1.0-prj_3-milestone-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+a+4", Utils.convertToDebianVersion("1.0-prj_3-a-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+b+4", Utils.convertToDebianVersion("1.0-prj_3-b-4", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+rc7", Utils.convertToDebianVersion("1.0-prj_3-rc7", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3.M1", Utils.convertToDebianVersion("1.0-prj_3.M1", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+M2", Utils.convertToDebianVersion("1.0-prj_3-M2", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+M3", Utils.convertToDebianVersion("1.0-prj_M3", true, "SNAPSHOT", null, cal.getTime(), false)); + + assertEquals("should match", "1.0+prj+M3", Utils.convertToDebianVersion("1.0-prj__-M3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+.+M3", Utils.convertToDebianVersion("1.0-prj_._-M3", true, "SNAPSHOT", null, cal.getTime(), false)); + assertEquals("should match", "1.0+prj+3+M3", Utils.convertToDebianVersion("1.0-prj_3:M3", true, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); assertEquals("should match", "1.0+prj+3+c+~20130217000000", Utils.convertToDebianVersion("1.0-prj_3-c+++++++-SNAPSHOT", true, "SNAPSHOT", null, cal.getTime(), false)); From cf4f4a5e203b0578edf9b859918ceffa10fee8f5 Mon Sep 17 00:00:00 2001 From: Oleg Estekhin Date: Fri, 17 Nov 2023 11:59:14 +0300 Subject: [PATCH 4/4] add betaExpand mojo parameter --- HISTORY.md | 1 + docs/maven.md | 1 + src/main/java/org/vafer/jdeb/maven/DebMojo.java | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index d00e0704c..05891a4cd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ * [CHG] Separate digest settings for creating the deb and signing it * [CHG] Upgraded deps * [FIX] Removed invalid Maven Mojo Deprecation +* [ADD] betaExpand to control rc, alpha and beta version processing ## Version 1.10, released 30.11.2021 diff --git a/docs/maven.md b/docs/maven.md index 0b781a073..7baa407d9 100644 --- a/docs/maven.md +++ b/docs/maven.md @@ -138,6 +138,7 @@ attach | Attach artifact to project snapshotExpand | Expand SNAPSHOT into the content of an environment variable or timestamp. | No; defaults to `false` snapshotEnv | Name of the environment variable. If it's empty defaults to a timestamp. | No; defaults to `SNAPSHOT` snapshotTemplate | Template for replacing the SNAPSHOT value. A timestamp format can be provided in brackets. | No; +betaExpand | Prepend rc, alpha or beta version with `~`. | No; defaults to `true` verbose | Verbose logging | No; defaults to `true`, will be `false` in the future skip | Indicates if an execution should be skipped | No; defaults to `false` skipSubmodules | Skip goal on all submodules | No; defaults to `false` diff --git a/src/main/java/org/vafer/jdeb/maven/DebMojo.java b/src/main/java/org/vafer/jdeb/maven/DebMojo.java index 0df4c798b..29e00c11b 100644 --- a/src/main/java/org/vafer/jdeb/maven/DebMojo.java +++ b/src/main/java/org/vafer/jdeb/maven/DebMojo.java @@ -254,6 +254,12 @@ public class DebMojo extends AbstractMojo { @Parameter private String snapshotTemplate; + /** + * When enabled the separator before a rc, alpha or beta version is replaced with '~'. + */ + @Parameter(defaultValue = "true") + private boolean betaExpand; + /** * If verbose is true more build messages are logged. */ @@ -440,7 +446,7 @@ protected VariableResolver initializeVariableResolver( Map varia * @return the Maven project version */ private String getProjectVersion() { - return Utils.convertToDebianVersion(getProject().getVersion(), this.snapshotExpand, this.snapshotEnv, this.snapshotTemplate, session.getStartTime(), true); + return Utils.convertToDebianVersion(getProject().getVersion(), this.snapshotExpand, this.snapshotEnv, this.snapshotTemplate, session.getStartTime(), this.betaExpand); } /**