From e733b2c69680e40277f76255fffc12a74ba4b0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirko=20K=C3=B6ster?= Date: Fri, 28 Jul 2023 10:39:31 +0200 Subject: [PATCH] PredefinedSnapshotCreator: unclean snapshot (#544) * ScmPosition: added isClean * PredefinedSnapshotCreator: -unclean-SNAPSHOT * added @Input to new method getIsClean() --- .../domain/PredefinedSnapshotCreator.groovy | 8 +++++++ .../PredefinedSnapshotCreatorTest.groovy | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreatorTest.groovy diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreator.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreator.groovy index ab2ed7a2..8d33830c 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreator.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreator.groovy @@ -11,6 +11,14 @@ enum PredefinedSnapshotCreator { return "-SNAPSHOT"; }), + UNCLEAN('unclean', { String version, ScmPosition position -> + if (!position.isClean) { + return "-unclean-SNAPSHOT" + } else { + return "-SNAPSHOT"; + }; + }), + private final String type final VersionProperties.Creator snapshotCreator diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreatorTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreatorTest.groovy new file mode 100644 index 00000000..c2fad856 --- /dev/null +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedSnapshotCreatorTest.groovy @@ -0,0 +1,23 @@ +package pl.allegro.tech.build.axion.release.domain + +import spock.lang.Specification + +import static pl.allegro.tech.build.axion.release.domain.scm.ScmPositionBuilder.scmPosition + +class PredefinedSnapshotCreatorTest extends Specification { + + def "default snapshot creator should just return -SNAPSHOT"() { + expect: + PredefinedSnapshotCreator.SIMPLE.snapshotCreator.apply('version', scmPosition('master')) == '-SNAPSHOT' + } + + def "unclean snapshot creator should just return -SNAPSHOT when scm is clean"() { + expect: + PredefinedSnapshotCreator.UNCLEAN.snapshotCreator.apply('version', scmPosition('master')) == '-SNAPSHOT' + } + + def "unclean snapshot creator should return -unclean-SNAPSHOT when scm is NOT clean"() { + expect: + PredefinedSnapshotCreator.UNCLEAN.snapshotCreator.apply('version', scmPosition().withBranch('master').withUnclean().build()) == '-unclean-SNAPSHOT' + } +}