From 8631ef163488cd6585f73ba8e4f110cccdb88354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ga=C5=82ek?= Date: Mon, 29 Mar 2021 22:42:32 +0200 Subject: [PATCH] legacy tag prefiex preserved in incrementMinorIfNotOnRelease #391 --- .../release/domain/NextVersionMarker.groovy | 2 +- .../domain/PredefinedVersionIncrementer.groovy | 9 +++++---- .../axion/release/domain/VersionFactory.java | 18 ++++++++++++++---- .../domain/VersionIncrementerContext.java | 12 +++++++++++- .../axion/release/domain/VersionResolver.java | 2 +- .../axion/release/domain/scm/ScmService.java | 4 ++++ 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy index 51e81a70..c1a9e8bb 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy @@ -23,7 +23,7 @@ class NextVersionMarker { nextVersion = nextVersionRules.nextVersion } else { Version currentVersion = Version.valueOf(versionConfig.undecoratedVersion) - VersionIncrementerContext context = new VersionIncrementerContext(currentVersion, repositoryService.position()) + VersionIncrementerContext context = new VersionIncrementerContext(currentVersion, repositoryService.position(), repositoryService.isLegacyDefTagnameRepo()) nextVersion = nextVersionRules.versionIncrementer ? PredefinedVersionIncrementer.versionIncrementerFor(nextVersionRules.versionIncrementer)(context) : versionConfig.versionIncrementer(context) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy index da6771a7..25c9a0e6 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy @@ -4,6 +4,7 @@ import com.github.zafarkhaja.semver.Version import pl.allegro.tech.build.axion.release.TagPrefixConf import java.util.regex.Matcher + import static java.lang.String.format enum PredefinedVersionIncrementer { @@ -21,10 +22,10 @@ enum PredefinedVersionIncrementer { }), INCREMENT_MINOR_IF_NOT_ON_RELEASE_BRANCH('incrementMinorIfNotOnRelease', { VersionIncrementerContext context, Map config -> - if(!config.releaseBranchPattern) { - config.releaseBranchPattern = TagPrefixConf.prefix()+ '/.+' + if (!config.releaseBranchPattern) { + config.releaseBranchPattern = context.isLegacyDefTagnameRepo() ? TagPrefixConf.DEFAULT_LEGACY_PREFIX + '/.+' : TagPrefixConf.prefix() + '/.+' } - if(context.scmPosition.branch ==~ config.releaseBranchPattern) { + if (context.scmPosition.branch ==~ config.releaseBranchPattern) { return context.currentVersion.incrementPatchVersion() } return context.currentVersion.incrementMinorVersion() @@ -45,7 +46,7 @@ enum PredefinedVersionIncrementer { } } - if (config.initialPreReleaseIfNotOnPrerelease != null) { + if (config.initialPreReleaseIfNotOnPrerelease != null) { return context.currentVersion.incrementPatchVersion(String.valueOf(config.initialPreReleaseIfNotOnPrerelease)) } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionFactory.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionFactory.java index 64fd832b..3f18b70b 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionFactory.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionFactory.java @@ -16,17 +16,29 @@ public class VersionFactory { private final TagProperties tagProperties; private final NextVersionProperties nextVersionProperties; private final ScmPosition position; + private final boolean isLegacyDefTagnameRepo; public VersionFactory( VersionProperties versionProperties, TagProperties tagProperties, NextVersionProperties nextVersionProperties, - ScmPosition position + ScmPosition position, + boolean isLegacyDefTagnameRepo ) { this.tagProperties = tagProperties; this.nextVersionProperties = nextVersionProperties; this.versionProperties = versionProperties; this.position = position; + this.isLegacyDefTagnameRepo = isLegacyDefTagnameRepo; + } + + public VersionFactory( + VersionProperties versionProperties, + TagProperties tagProperties, + NextVersionProperties nextVersionProperties, + ScmPosition position + ) { + this(versionProperties, tagProperties, nextVersionProperties, position, false); } public Version versionFromTag(String tag) { @@ -65,9 +77,7 @@ public FinalVersion createFinalVersion(ScmState scmState, Version version) { if (StringGroovyMethods.asBoolean(versionProperties.getForcedVersion())) { finalVersion = Version.valueOf(versionProperties.getForcedVersion()); } else if (incrementVersion) { - finalVersion = versionProperties.getVersionIncrementer().call(new VersionIncrementerContext( - version, position - )); + finalVersion = versionProperties.getVersionIncrementer().call(new VersionIncrementerContext(version, position, isLegacyDefTagnameRepo)); } return new FinalVersion( diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionIncrementerContext.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionIncrementerContext.java index 8cd3360d..cdb34212 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionIncrementerContext.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionIncrementerContext.java @@ -7,10 +7,16 @@ public class VersionIncrementerContext { private final Version currentVersion; private final ScmPosition scmPosition; + private final boolean isLegacyDefTagnameRepo; - public VersionIncrementerContext(Version currentVersion, ScmPosition scmPosition) { + public VersionIncrementerContext(Version currentVersion, ScmPosition scmPosition, boolean isLegacyDefTagnameRepo) { this.currentVersion = currentVersion; this.scmPosition = scmPosition; + this.isLegacyDefTagnameRepo = isLegacyDefTagnameRepo; + } + + public VersionIncrementerContext(Version currentVersion, ScmPosition scmPosition) { + this(currentVersion, scmPosition, false); } public Version getCurrentVersion() { @@ -20,4 +26,8 @@ public Version getCurrentVersion() { public ScmPosition getScmPosition() { return scmPosition; } + + public boolean isLegacyDefTagnameRepo() { + return isLegacyDefTagnameRepo; + } } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java index 4a298512..251359d2 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java @@ -41,7 +41,7 @@ public VersionContext resolveVersion(VersionProperties versionProperties, TagPro projectRootRelativePath, versionProperties.getMonorepoProperties().getDirsToExclude() ); - VersionFactory versionFactory = new VersionFactory(versionProperties, tagProperties, nextVersionProperties, latestChangePosition); + VersionFactory versionFactory = new VersionFactory(versionProperties, tagProperties, nextVersionProperties, latestChangePosition, repository.isLegacyDefTagnameRepo()); VersionInfo versions; if (versionProperties.isUseHighestVersion()) { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java index 9adb389e..1c49ec97 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java @@ -63,4 +63,8 @@ public boolean remoteAttached() { public List lastLogMessages(int messageCount) { return repository.lastLogMessages(messageCount); } + + public boolean isLegacyDefTagnameRepo() { + return repository.isLegacyDefTagnameRepo(); + } }