Skip to content

Commit

Permalink
Merge pull request #184 from nebula-plugins/release-tasks-support-opt…
Browse files Browse the repository at this point in the history
…ional-colon

Support for optional colon (:) in root project
  • Loading branch information
rpalcolea authored Mar 31, 2020
2 parents 5a3e750 + d2cab5e commit ee2d5f3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
17 changes: 11 additions & 6 deletions src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ class ReleasePlugin implements Plugin<Project> {
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'
Expand Down Expand Up @@ -233,16 +238,16 @@ class ReleasePlugin implements Plugin<Project> {
}

private boolean determineStage(List<String> cliTasks, TaskProvider<ReleaseCheck> 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
Expand Down

0 comments on commit ee2d5f3

Please sign in to comment.