From cf630051f48ad7c93c8e9fffaedc292f5ecb353e Mon Sep 17 00:00:00 2001 From: Joaquim Alvino de Mesquita Neto Date: Wed, 7 Dec 2022 14:21:11 +0100 Subject: [PATCH] fixes bug where plugin breaks on empty scope --- ...rsionPluginExtensionIntegrationSpec.groovy | 78 +++++++++++++++++++ .../DefaultVersionPluginExtension.groovy | 6 +- .../gradle/version/VersionPluginSpec.groovy | 4 - 3 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 src/integrationTest/groovy/wooga/gradle/version/VersionPluginExtensionIntegrationSpec.groovy diff --git a/src/integrationTest/groovy/wooga/gradle/version/VersionPluginExtensionIntegrationSpec.groovy b/src/integrationTest/groovy/wooga/gradle/version/VersionPluginExtensionIntegrationSpec.groovy new file mode 100644 index 0000000..3cd0079 --- /dev/null +++ b/src/integrationTest/groovy/wooga/gradle/version/VersionPluginExtensionIntegrationSpec.groovy @@ -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" + } + + +} diff --git a/src/main/groovy/wooga/gradle/version/internal/DefaultVersionPluginExtension.groovy b/src/main/groovy/wooga/gradle/version/internal/DefaultVersionPluginExtension.groovy index 43cd2ed..a3a84ad 100644 --- a/src/main/groovy/wooga/gradle/version/internal/DefaultVersionPluginExtension.groovy +++ b/src/main/groovy/wooga/gradle/version/internal/DefaultVersionPluginExtension.groovy @@ -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)) diff --git a/src/test/groovy/wooga/gradle/version/VersionPluginSpec.groovy b/src/test/groovy/wooga/gradle/version/VersionPluginSpec.groovy index ca7f102..f1d8da0 100644 --- a/src/test/groovy/wooga/gradle/version/VersionPluginSpec.groovy +++ b/src/test/groovy/wooga/gradle/version/VersionPluginSpec.groovy @@ -101,10 +101,6 @@ class VersionPluginSpec extends ProjectSpec { 'versionBuilder' | VersionPluginExtension } - def findStrategyByName(List strategies, name) { - strategies.find { it.name == name } - } - @Unroll('verify wooga packages version strategy for #tagVersion, #scope and #stage') def "uses custom wooga semver strategies"() {