From d2cab5e2ed0aa95f18212c7fb76ce20fb85dab1c Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Mon, 30 Mar 2020 17:30:42 -0700 Subject: [PATCH] Support for optional colon (:) in root project --- .../ReleasePluginIntegrationSpec.groovy | 54 +++++++++++++++++++ .../plugin/release/ReleasePlugin.groovy | 17 +++--- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy b/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy index 6631fcd..03092f0 100644 --- a/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy +++ b/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy @@ -90,6 +90,14 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec { version.toString().startsWith("0.1.0-snapshot." + getUtcDateForComparison()) } + def 'choose immutableSnapshot version with optional colon (:)'() { + when: + def version = inferredVersionForTask(':immutableSnapshot') + + then: + version.toString().startsWith("0.1.0-snapshot." + getUtcDateForComparison()) + } + def 'choose devSnapshot uncommitted version'() { given: new File(projectDir, 'newfile').createNewFile() @@ -131,6 +139,29 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec { version == normal('0.1.0-rc.1') } + def 'choose candidate version with optional colon (:) for root project'() { + when: + def version = inferredVersionForTask(':candidate') + + then: + version == normal('0.1.0-rc.1') + } + + def 'choose candidate version with optional colon (:) for root project - multi-module'() { + setup: + addSubproject('sub1') + addSubproject('sub2') + git.add(patterns: ['.'] as Set) + git.commit(message: "Update file") + git.push(all: true) + + when: + def version = inferredVersionForTask(':candidate') + + then: + version == normal('0.1.0-rc.1') + } + def 'choose candidate development version'() { git.tag.add(name: 'v2.2.0-rc.1') @@ -178,6 +209,29 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec { version == normal('0.1.0') } + def 'choose release version with optional colon (:) for root project'() { + when: + def version = inferredVersionForTask(':final') + + then: + version == normal('0.1.0') + } + + def 'choose release version with optional colon (:) for root project - multi-module'() { + setup: + addSubproject('sub1') + addSubproject('sub2') + git.add(patterns: ['.'] as Set) + git.commit(message: "Update file") + git.push(all: true) + + when: + def version = inferredVersionForTask(':final') + + then: + version == normal('0.1.0') + } + def 'choose release version, update patch'() { when: def version = inferredVersionForTask('final', '-Prelease.scope=patch') diff --git a/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy b/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy index 17cf2d9..19c8671 100644 --- a/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy +++ b/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy @@ -50,14 +50,19 @@ class ReleasePlugin implements Plugin { static Logger logger = Logging.getLogger(ReleasePlugin) static final String SNAPSHOT_TASK_NAME = 'snapshot' + static final String SNAPSHOT_TASK_NAME_OPTIONAL_COLON = ":$SNAPSHOT_TASK_NAME" static final String SNAPSHOT_SETUP_TASK_NAME = 'snapshotSetup' static final String DEV_SNAPSHOT_TASK_NAME = 'devSnapshot' static final String DEV_SNAPSHOT_SETUP_TASK_NAME = 'devSnapshotSetup' + static final String DEV_SNAPSHOT_SETUP_TASK_NAME_OPTIONAL_COLON = ":$DEV_SNAPSHOT_SETUP_TASK_NAME" static final String IMMUTABLE_SNAPSHOT_TASK_NAME = 'immutableSnapshot' static final String IMMUTABLE_SNAPSHOT_SETUP_TASK_NAME = 'immutableSnapshotSetup' + static final String IMMUTABLE_SNAPSHOT_TASK_NAME_OPTIONAL_COLON = ":$IMMUTABLE_SNAPSHOT_TASK_NAME" static final String CANDIDATE_TASK_NAME = 'candidate' + static final String CANDIDATE_TASK_NAME_OPTIONAL_COLON = ":$CANDIDATE_TASK_NAME" static final String CANDIDATE_SETUP_TASK_NAME = 'candidateSetup' static final String FINAL_TASK_NAME = 'final' + static final String FINAL_TASK_NAME_WITH_OPTIONAL_COLON = ":$FINAL_TASK_NAME" static final String FINAL_SETUP_TASK_NAME = 'finalSetup' static final String RELEASE_CHECK_TASK_NAME = 'releaseCheck' static final String NEBULA_RELEASE_EXTENSION_NAME = 'nebulaRelease' @@ -233,16 +238,16 @@ class ReleasePlugin implements Plugin { } private boolean determineStage(List cliTasks, TaskProvider releaseCheck, boolean replaceDevSnapshots) { - def hasSnapshot = cliTasks.contains(SNAPSHOT_TASK_NAME) - def hasDevSnapshot = cliTasks.contains(DEV_SNAPSHOT_TASK_NAME) - def hasImmutableSnapshot = cliTasks.contains(IMMUTABLE_SNAPSHOT_TASK_NAME) - def hasCandidate = cliTasks.contains(CANDIDATE_TASK_NAME) - def hasFinal = cliTasks.contains(FINAL_TASK_NAME) + def hasSnapshot = cliTasks.contains(SNAPSHOT_TASK_NAME) || cliTasks.contains(SNAPSHOT_TASK_NAME_OPTIONAL_COLON) + def hasDevSnapshot = cliTasks.contains(DEV_SNAPSHOT_TASK_NAME) || cliTasks.contains(DEV_SNAPSHOT_SETUP_TASK_NAME_OPTIONAL_COLON) + def hasImmutableSnapshot = cliTasks.contains(IMMUTABLE_SNAPSHOT_TASK_NAME) || cliTasks.contains(IMMUTABLE_SNAPSHOT_TASK_NAME_OPTIONAL_COLON) + def hasCandidate = cliTasks.contains(CANDIDATE_TASK_NAME) || cliTasks.contains(CANDIDATE_TASK_NAME_OPTIONAL_COLON) + def hasFinal = cliTasks.contains(FINAL_TASK_NAME) || cliTasks.contains(FINAL_TASK_NAME_WITH_OPTIONAL_COLON) if ([hasSnapshot, hasImmutableSnapshot, hasDevSnapshot, hasCandidate, hasFinal].count { it } > 2) { throw new GradleException('Only one of snapshot, immutableSnapshot, devSnapshot, candidate, or final can be specified.') } - def isSnapshotRelease = hasSnapshot || hasDevSnapshot || (!hasCandidate && !hasFinal) + def isSnapshotRelease = hasSnapshot || hasDevSnapshot || hasImmutableSnapshot || (!hasCandidate && !hasFinal) releaseCheck.configure { it.isSnapshotRelease = isSnapshotRelease