Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
fixes bug where plugin breaks on empty scope (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquimmnetto authored Dec 8, 2022
1 parent 1e12cef commit 3086b0e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package wooga.gradle.version

import com.wooga.gradle.test.PropertyLocation
import com.wooga.gradle.test.writers.PropertyGetterTaskWriter
import com.wooga.gradle.test.writers.PropertySetterWriter
import org.gradle.api.file.Directory
import spock.lang.Unroll

class VersionPluginExtensionIntegrationSpec extends VersionIntegrationSpec {

def setup() {
buildFile << """
${applyPlugin(VersionPlugin)}
""".stripIndent()
}

@Unroll("can set property versionBuilder.#property with gradle property #gradlePropName=#rawValue")
def "can set extension property with gradle property"() {
given:
set.location = rawValue == null ? PropertyLocation.none : set.location
when:
def propertyQuery = runPropertyQuery(get, set).withSerializer(Directory) {
String dir -> new File(projectDir, dir).absolutePath
}

then:
propertyQuery.matches(expectedValue)

where:
property | gradlePropName | type | rawValue | expectedValue
"stage" | "release.stage" | String | "snapshot" | "snapshot"
"stage" | "release.stage" | String | "rc" | "rc"
"stage" | "release.stage" | String | "final" | "final"
"stage" | "release.stage" | String | "custom" | "custom"
"stage" | "release.stage" | String | null | null
"scope" | "release.scope" | String | "major" | "MAJOR"
"scope" | "release.scope" | String | "minor" | "MINOR"
"scope" | "release.scope" | String | "patch" | "PATCH"
"scope" | "release.scope" | String | "PatCh" | "PATCH"
"scope" | "release.scope" | String | "PATCH" | "PATCH"
"scope" | "release.scope" | String | null | null


set = new PropertySetterWriter("versionBuilder", property)
.set(rawValue, type)
.withPropertyKey(gradlePropName)
.to(PropertyLocation.propertyCommandLine)
get = new PropertyGetterTaskWriter(set)
}

//Line bellow doesn't work on gradle-commons-test framework so I'm doing it myself.
// "stage" | "release.stage" | String | "" | null
@Unroll("can set property versionBuilder.#property with gradle property #gradlePropName=#rawValue")
def "can set extension property with gradle property but w/out gradle-commons-test"() {
given:
buildFile << """
tasks.register("$taskName") {
doLast {
println("[[[$gradlePropName=\${versionBuilder.${property}.orNull}]]]")
}
}
"""

when:
def result = runTasks(taskName, "-P${gradlePropName}=${rawValue}",)

then:
result.standardOutput.contains("[[[${gradlePropName}=${expectedValue}]]]")

where:
property | gradlePropName | type | rawValue | expectedValue
"stage" | "release.stage" | String | "" | ""
"scope" | "release.scope" | String | "" | null
taskName = "getterTask"
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class DefaultVersionPluginExtension implements VersionPluginExtension {
DefaultVersionPluginExtension(Project project) {
this.project = project

scope = VersionPluginConventions.scope.getStringValueProvider(project).map {
ChangeScope.valueOf(it.toUpperCase())
}
scope = VersionPluginConventions.scope.getStringValueProvider(project)
.map {it?.trim()?.empty? null: it }
.map {ChangeScope.valueOf(it.toUpperCase()) }

stage = VersionPluginConventions.stage.getStringValueProvider(project)
releaseBranchPattern.set(VersionPluginConventions.releaseBranchPattern.getStringValueProvider(project))
Expand Down
4 changes: 0 additions & 4 deletions src/test/groovy/wooga/gradle/version/VersionPluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ class VersionPluginSpec extends ProjectSpec {
'versionBuilder' | VersionPluginExtension
}

def findStrategyByName(List<VersionStrategy> strategies, name) {
strategies.find { it.name == name }
}

@Unroll('verify wooga packages version strategy for #tagVersion, #scope and #stage')
def "uses custom wooga semver strategies"() {

Expand Down

0 comments on commit 3086b0e

Please sign in to comment.