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

Commit

Permalink
renamed VersionScheme to VersionSchemes, IVersionScheme to VersionScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquimmnetto committed Apr 5, 2023
1 parent 0b15c59 commit f5d2964
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VersionIntegrationSpec extends IntegrationSpec {
static wrapValueFallback = { Object rawValue, String type, Closure<String> fallback ->
switch (type) {
case "VersionScheme":
if(VersionScheme.isInstance(rawValue)) {
if(VersionSchemes.isInstance(rawValue)) {
return "wooga.gradle.version.VersionScheme.${rawValue.toString()}"
} else {
return "wooga.gradle.version.VersionScheme.valueOf('${rawValue.toString()}')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package wooga.gradle.version

import com.wooga.gradle.PlatformUtils
import com.wooga.gradle.PropertyLookup
import com.wooga.gradle.test.PropertyLocation
import com.wooga.gradle.test.PropertyQueryTaskWriter
import wooga.gradle.version.internal.release.semver.ChangeScope
Expand Down Expand Up @@ -100,10 +99,10 @@ class VersionPluginIntegrationSpec extends VersionIntegrationSpec {
"stage" | "snapshot" | _ | PropertyLocation.environment
"stage" | "final" | _ | PropertyLocation.property
"stage" | "null" | _ | PropertyLocation.none
"versionScheme" | "semver2" | VersionScheme.semver2 | PropertyLocation.environment
"versionScheme" | "semver" | VersionScheme.semver | PropertyLocation.environment
"versionScheme" | "semver2" | VersionScheme.semver2 | PropertyLocation.property
"versionScheme" | "semver" | VersionScheme.semver | PropertyLocation.property
"versionScheme" | "semver2" | VersionSchemes.semver2 | PropertyLocation.environment
"versionScheme" | "semver" | VersionSchemes.semver | PropertyLocation.environment
"versionScheme" | "semver2" | VersionSchemes.semver2 | PropertyLocation.property
"versionScheme" | "semver" | VersionSchemes.semver | PropertyLocation.property
"versionCodeScheme" | "releaseCountBasic" | VersionCodeScheme.releaseCountBasic | PropertyLocation.environment
"versionCodeScheme" | "releaseCount" | VersionCodeScheme.releaseCount | PropertyLocation.environment
"versionCodeScheme" | "semver" | VersionCodeScheme.semver | PropertyLocation.environment
Expand Down Expand Up @@ -155,15 +154,15 @@ class VersionPluginIntegrationSpec extends VersionIntegrationSpec {
where:
property | method | rawValue | type
"versionScheme" | "versionScheme" | "semver" | "String"
"versionScheme" | "versionScheme" | VersionScheme.semver2 | "VersionScheme"
"versionScheme" | "versionScheme" | VersionScheme.semver | "Provider<VersionScheme>"
"versionScheme" | "versionScheme" | VersionScheme.staticMarker | "Provider<VersionScheme>"
"versionScheme" | "versionScheme.set" | VersionScheme.semver2 | "VersionScheme"
"versionScheme" | "versionScheme.set" | VersionScheme.semver | "Provider<VersionScheme>"
"versionScheme" | "versionScheme.set" | VersionScheme.staticMarker | "Provider<VersionScheme>"
"versionScheme" | "versionScheme" | VersionSchemes.semver2 | "VersionScheme"
"versionScheme" | "versionScheme" | VersionSchemes.semver | "Provider<VersionScheme>"
"versionScheme" | "versionScheme" | VersionSchemes.staticMarker | "Provider<VersionScheme>"
"versionScheme" | "versionScheme.set" | VersionSchemes.semver2 | "VersionScheme"
"versionScheme" | "versionScheme.set" | VersionSchemes.semver | "Provider<VersionScheme>"
"versionScheme" | "versionScheme.set" | VersionSchemes.staticMarker | "Provider<VersionScheme>"
"versionScheme" | "setVersionScheme" | "semver" | "String"
"versionScheme" | "setVersionScheme" | VersionScheme.semver2 | "VersionScheme"
"versionScheme" | "setVersionScheme" | VersionScheme.semver | "Provider<VersionScheme>"
"versionScheme" | "setVersionScheme" | VersionSchemes.semver2 | "VersionScheme"
"versionScheme" | "setVersionScheme" | VersionSchemes.semver | "Provider<VersionScheme>"

"versionCodeScheme" | "versionCodeScheme" | "releaseCountBasic" | "String"
"versionCodeScheme" | "versionCodeScheme" | VersionCodeScheme.semver | "VersionCodeScheme"
Expand Down
3 changes: 1 addition & 2 deletions src/main/groovy/wooga/gradle/version/VersionPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package wooga.gradle.version

import org.ajoberstar.grgit.Grgit
import org.eclipse.jgit.errors.RepositoryNotFoundException
import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logging
Expand Down Expand Up @@ -71,7 +70,7 @@ class VersionPlugin implements Plugin<Project> {
def extension = project.extensions.create(VersionPluginExtension, EXTENSION_NAME, DefaultVersionPluginExtension, project)

extension.versionScheme.set(VersionPluginConventions.versionScheme.getStringValueProvider(project).map({
VersionScheme.valueOf(it.trim())
VersionSchemes.valueOf(it.trim())
}))

extension.versionCodeScheme.set(VersionPluginConventions.versionCodeScheme.getStringValueProvider(project).map({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VersionPluginConventions {
static final String UNINITIALIZED_VERSION = '0.1.0-dev.0.uninitialized'

static final PropertyLookup version = new PropertyLookup("VERSION_BUILDER_VERSION", "versionBuilder.version", null)
static final PropertyLookup versionScheme = new PropertyLookup("VERSION_BUILDER_VERSION_SCHEME", ["versionBuilder.versionScheme", "version.scheme"], VersionScheme.semver)
static final PropertyLookup versionScheme = new PropertyLookup("VERSION_BUILDER_VERSION_SCHEME", ["versionBuilder.versionScheme", "version.scheme"], VersionSchemes.semver)
static final PropertyLookup versionCodeScheme = new PropertyLookup("VERSION_BUILDER_VERSION_CODE_SCHEME", "versionBuilder.versionCodeScheme", VersionCodeScheme.none)
static final PropertyLookup versionCodeOffset = new PropertyLookup("VERSION_BUILDER_VERSION_CODE_OFFSET", "versionBuilder.versionCodeOffset", 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ trait VersionPluginExtension implements BaseSpec {
/**
* @return The version scheme being used by the plugin (such as SemVer2)
*/
Property<IVersionScheme> getVersionScheme() {
Property<VersionScheme> getVersionScheme() {
versionScheme
}

private final Property<IVersionScheme> versionScheme = objects.property(IVersionScheme)
private final Property<VersionScheme> versionScheme = objects.property(VersionScheme)

void versionScheme(IVersionScheme value) {
void versionScheme(VersionScheme value) {
setVersionScheme(value)
}

void versionScheme(Provider<IVersionScheme> value) {
void versionScheme(Provider<VersionScheme> value) {
setVersionScheme(value)
}

void setVersionScheme(IVersionScheme value) {
void setVersionScheme(VersionScheme value) {
versionScheme.set(value)
}

void setVersionScheme(Provider<IVersionScheme> value) {
void setVersionScheme(Provider<VersionScheme> value) {
versionScheme.set(value)
}

Expand All @@ -62,7 +62,7 @@ trait VersionPluginExtension implements BaseSpec {
}

void setVersionScheme(String value) {
versionScheme.set(VersionScheme.valueOf(value.trim()))
versionScheme.set(VersionSchemes.valueOf(value.trim()))
}

/**
Expand Down Expand Up @@ -344,7 +344,7 @@ trait VersionPluginExtension implements BaseSpec {
* @throws org.gradle.api.internal.provider.MissingValueException if there is no configured git repository in this extension.
* or empty if none of the scheme strategies can be applied to the arguments.
*/
Provider<ReleaseVersion> inferVersion(IVersionScheme scheme, Provider<String> stageProvider = this.stage,
Provider<ReleaseVersion> inferVersion(VersionScheme scheme, Provider<String> stageProvider = this.stage,
Provider<ChangeScope> scopeProvider = this.scope) {
def strategyProvider = pickStrategy(scheme, stageProvider)
strategyProvider.map { strategy ->
Expand All @@ -357,7 +357,7 @@ trait VersionPluginExtension implements BaseSpec {
}
}

private Provider<VersionStrategy> pickStrategy(IVersionScheme scheme, Provider<String> stageProvider) {
private Provider<VersionStrategy> pickStrategy(VersionScheme scheme, Provider<String> stageProvider) {
return git.map {
new GitStrategyPicker(it).pickStrategy(scheme, stageProvider.orNull)
}.orElse( providers.provider{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* A default strategy can also be provided.
*/
//This has to be a java class (not groovy) because groovy 2 doesn't support java 8 default interface methods.
public interface IVersionScheme { //TODO: Rename to VersionScheme when breaking change
public interface VersionScheme { //TODO: Rename to VersionScheme when breaking change
VersionStrategy getDevelopment();
VersionStrategy getSnapshot();
VersionStrategy getPreRelease();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ import wooga.gradle.version.strategies.opinion.SemverV2WithDefaultStrategies
import wooga.gradle.version.strategies.opinion.UpmStrategies
import wooga.gradle.version.strategies.opinion.WdkNuGetStrategies

//TODO: 3.x Rename to VersionSchemes when breaking change
/**
* Version schemes available for use with this plugin.
* Each scheme consists of at least 4 strategies (development, snapshot, pre-release and final)
* plus additional strategies if so desired. Check IVersionScheme for more details.
*/
enum VersionScheme implements IVersionScheme {
enum VersionSchemes implements VersionScheme {
semver(LegacyNuGetStrategies.DEVELOPMENT,
LegacyNuGetStrategies.SNAPSHOT,
LegacyNuGetStrategies.PRE_RELEASE,
Expand Down Expand Up @@ -72,7 +71,7 @@ enum VersionScheme implements IVersionScheme {
final List<VersionStrategy> strategies
final VersionStrategy defaultStrategy

VersionScheme(VersionStrategy development, VersionStrategy snapshot, VersionStrategy preRelease, VersionStrategy finalStrategy, SemVerStrategy... others) {
VersionSchemes(VersionStrategy development, VersionStrategy snapshot, VersionStrategy preRelease, VersionStrategy finalStrategy, SemVerStrategy... others) {
this.development = development
this.snapshot = snapshot
this.preRelease = preRelease
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package wooga.gradle.version.internal

import org.ajoberstar.grgit.Grgit
import wooga.gradle.version.IVersionScheme
import wooga.gradle.version.VersionScheme
import wooga.gradle.version.internal.release.base.DefaultVersionStrategy
import wooga.gradle.version.internal.release.base.VersionStrategy

Expand All @@ -25,7 +25,7 @@ class GitStrategyPicker {
* If null, the stage to be used in execution will depend if a fallback is set in the selected strategy itself.
* @return Selected VersionStrategy or null if no strategy matches.
*/
VersionStrategy pickStrategy(IVersionScheme scheme, @Nullable String stage) {
VersionStrategy pickStrategy(VersionScheme scheme, @Nullable String stage) {
return pickStrategy(scheme.strategies, scheme.defaultStrategy, stage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package wooga.gradle.version.strategies

import wooga.gradle.version.IVersionScheme

import wooga.gradle.version.ReleaseStage
import wooga.gradle.version.internal.release.opinion.Strategies
import wooga.gradle.version.internal.release.semver.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package wooga.gradle.version.strategies

import wooga.gradle.version.IVersionScheme
import wooga.gradle.version.VersionScheme
import wooga.gradle.version.ReleaseStage
import wooga.gradle.version.internal.release.opinion.Strategies
import wooga.gradle.version.internal.release.semver.SemVerStrategy
Expand Down Expand Up @@ -160,7 +160,7 @@ final class NewSemverV2Strategies {
Strategies.PreRelease.COUNT_COMMITS_SINCE_ANY),
)

static final IVersionScheme scheme = new IVersionScheme() {
static final VersionScheme scheme = new VersionScheme() {
final SemVerStrategy development = DEVELOPMENT
final SemVerStrategy snapshot = SNAPSHOT
final SemVerStrategy preRelease = PRE_RELEASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import wooga.gradle.version.strategies.NewSemverV1Strategies
class NewSemverV1StrategySpec extends ProjectSpec {

public static final String PLUGIN_NAME = 'net.wooga.version'
static final IVersionScheme semverV1Scheme = new IVersionScheme() {
static final VersionScheme semverV1Scheme = new VersionScheme() {
final SemVerStrategy development = NewSemverV1Strategies.DEVELOPMENT
final SemVerStrategy snapshot = NewSemverV1Strategies.SNAPSHOT
final SemVerStrategy preRelease = NewSemverV1Strategies.PRE_RELEASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NewSemverV2StrategySpec extends ProjectSpec {

public static final String PLUGIN_NAME = 'net.wooga.version'

static final IVersionScheme semverV2Scheme = new IVersionScheme() {
static final VersionScheme semverV2Scheme = new VersionScheme() {
final SemVerStrategy development = NewSemverV2Strategies.DEVELOPMENT
final SemVerStrategy snapshot = NewSemverV2Strategies.SNAPSHOT
final SemVerStrategy preRelease = NewSemverV2Strategies.PRE_RELEASE
Expand Down
13 changes: 6 additions & 7 deletions src/test/groovy/wooga/gradle/version/VersionPluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package wooga.gradle.version

import nebula.test.ProjectSpec
import org.ajoberstar.grgit.Grgit
import org.gradle.cache.internal.VersionStrategy
import spock.lang.Ignore
import spock.lang.Unroll
import wooga.gradle.version.internal.ToStringProvider
Expand Down Expand Up @@ -993,12 +992,12 @@ class VersionPluginSpec extends ProjectSpec {

where:
nearestNormal | nearestAny | distance | stage | scope | scheme | branchName | prefixTag | expectedVersion
'1.0.0' | _ | 1 | "ci" | _ | VersionScheme.semver2 | "master" | true | "1.1.0-master.1"
'1.0.0' | _ | 1 | "ci" | _ | VersionScheme.semver2 | "master" | false | "1.1.0-master.1"
'1.0.0' | _ | 1 | "snapshot" | _ | VersionScheme.semver | "master" | true | "1.0.1-master00001"
'1.0.0' | _ | 1 | "snapshot" | _ | VersionScheme.semver | "master" | false | "1.0.1-master00001"
_ | _ | 1 | "ci" | _ | VersionScheme.semver2 | "master" | false | "0.1.0-master.2"
_ | _ | 1 | "snapshot" | _ | VersionScheme.semver | "master" | false | "0.0.1-master00002"
'1.0.0' | _ | 1 | "ci" | _ | VersionSchemes.semver2 | "master" | true | "1.1.0-master.1"
'1.0.0' | _ | 1 | "ci" | _ | VersionSchemes.semver2 | "master" | false | "1.1.0-master.1"
'1.0.0' | _ | 1 | "snapshot" | _ | VersionSchemes.semver | "master" | true | "1.0.1-master00001"
'1.0.0' | _ | 1 | "snapshot" | _ | VersionSchemes.semver | "master" | false | "1.0.1-master00001"
_ | _ | 1 | "ci" | _ | VersionSchemes.semver2 | "master" | false | "0.1.0-master.2"
_ | _ | 1 | "snapshot" | _ | VersionSchemes.semver | "master" | false | "0.0.1-master00002"
nearestAnyTitle = (nearestAny == _) ? "unset" : nearestAny
scopeTitle = (scope == _) ? "unset" : scope
tagPrefix = (prefixTag) ? "v" : ""
Expand Down

0 comments on commit f5d2964

Please sign in to comment.