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

Commit

Permalink
rename VersionCodeScheme to VersionCodeSchemes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquimmnetto committed Apr 11, 2023
1 parent 3512115 commit 97121e3
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class VersionIntegrationSpec extends IntegrationSpec {
}
break
case "VersionCodeScheme":
if(VersionCodeScheme.isInstance(rawValue)) {
return "wooga.gradle.version.VersionCodeScheme.${rawValue.toString()}"
if(VersionCodeSchemes.isInstance(rawValue)) {
return "wooga.gradle.version.VersionCodeSchemes.${rawValue.toString()}"
} else {
return "wooga.gradle.version.VersionCodeScheme.valueOf('${rawValue.toString()}')"
return "wooga.gradle.version.VersionCodeSchemes.valueOf('${rawValue.toString()}')"
}
break
case "Grgit":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ class VersionPluginIntegrationSpec extends VersionIntegrationSpec {
"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
"versionCodeScheme" | "none" | VersionCodeScheme.none | PropertyLocation.environment
"versionCodeScheme" | "releaseCountBasic" | VersionCodeScheme.releaseCountBasic | PropertyLocation.property
"versionCodeScheme" | "releaseCount" | VersionCodeScheme.releaseCount | PropertyLocation.property
"versionCodeScheme" | "semver" | VersionCodeScheme.semver | PropertyLocation.property
"versionCodeScheme" | "none" | VersionCodeScheme.none | PropertyLocation.property
"versionCodeScheme" | "releaseCountBasic" | VersionCodeSchemes.releaseCountBasic | PropertyLocation.environment
"versionCodeScheme" | "releaseCount" | VersionCodeSchemes.releaseCount | PropertyLocation.environment
"versionCodeScheme" | "semver" | VersionCodeSchemes.semver | PropertyLocation.environment
"versionCodeScheme" | "none" | VersionCodeSchemes.none | PropertyLocation.environment
"versionCodeScheme" | "releaseCountBasic" | VersionCodeSchemes.releaseCountBasic | PropertyLocation.property
"versionCodeScheme" | "releaseCount" | VersionCodeSchemes.releaseCount | PropertyLocation.property
"versionCodeScheme" | "semver" | VersionCodeSchemes.semver | PropertyLocation.property
"versionCodeScheme" | "none" | VersionCodeSchemes.none | PropertyLocation.property
"versionCodeOffset" | 100 | _ | PropertyLocation.environment
"versionCodeOffset" | 200 | _ | PropertyLocation.property
"releaseBranchPattern" | /^m.*/ | _ | PropertyLocation.property
Expand Down Expand Up @@ -167,13 +167,13 @@ class VersionPluginIntegrationSpec extends VersionIntegrationSpec {
"versionScheme" | "setVersionScheme" | VersionSchemes.semver | "Provider<VersionScheme>"

"versionCodeScheme" | "versionCodeScheme" | "releaseCountBasic" | "String"
"versionCodeScheme" | "versionCodeScheme" | VersionCodeScheme.semver | "VersionCodeScheme"
"versionCodeScheme" | "versionCodeScheme" | VersionCodeScheme.releaseCountBasic | "Provider<VersionCodeScheme>"
"versionCodeScheme" | "versionCodeScheme.set" | VersionCodeScheme.semver | "VersionCodeScheme"
"versionCodeScheme" | "versionCodeScheme.set" | VersionCodeScheme.releaseCountBasic | "Provider<VersionCodeScheme>"
"versionCodeScheme" | "versionCodeScheme" | VersionCodeSchemes.semver | "VersionCodeScheme"
"versionCodeScheme" | "versionCodeScheme" | VersionCodeSchemes.releaseCountBasic | "Provider<VersionCodeScheme>"
"versionCodeScheme" | "versionCodeScheme.set" | VersionCodeSchemes.semver | "VersionCodeScheme"
"versionCodeScheme" | "versionCodeScheme.set" | VersionCodeSchemes.releaseCountBasic | "Provider<VersionCodeScheme>"
"versionCodeScheme" | "setVersionCodeScheme" | "releaseCount" | "String"
"versionCodeScheme" | "setVersionCodeScheme" | VersionCodeScheme.none | "VersionCodeScheme"
"versionCodeScheme" | "setVersionCodeScheme" | VersionCodeScheme.releaseCount | "Provider<VersionCodeScheme>"
"versionCodeScheme" | "setVersionCodeScheme" | VersionCodeSchemes.none | "VersionCodeScheme"
"versionCodeScheme" | "setVersionCodeScheme" | VersionCodeSchemes.releaseCount | "Provider<VersionCodeScheme>"

"versionCodeOffset" | "versionCodeOffset" | 1 | "Integer"
"versionCodeOffset" | "versionCodeOffset" | 2 | "Provider<Integer>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package wooga.gradle.version

enum VersionCodeScheme {
enum VersionCodeSchemes {
none,
semverBasic,
semver,
Expand Down
46 changes: 45 additions & 1 deletion src/main/groovy/wooga/gradle/version/VersionPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package wooga.gradle.version
import com.wooga.gradle.extensions.ProviderExtensions
import org.ajoberstar.grgit.Grgit
import org.eclipse.jgit.errors.RepositoryNotFoundException
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logging
Expand All @@ -28,6 +29,11 @@ import org.slf4j.Logger
import wooga.gradle.version.internal.DefaultVersionCodeExtension
import wooga.gradle.version.internal.DefaultVersionPluginExtension
import wooga.gradle.version.internal.ToStringProvider
import wooga.gradle.version.internal.VersionCode
import wooga.gradle.version.internal.release.base.PrefixVersionParser
import wooga.gradle.version.internal.release.base.ReleaseVersion
import wooga.gradle.version.internal.release.git.GitVersionRepository
import wooga.gradle.version.internal.release.semver.ChangeScope

class VersionPlugin implements Plugin<Project> {
static String EXTENSION_NAME = "versionBuilder"
Expand All @@ -54,6 +60,7 @@ class VersionPlugin implements Plugin<Project> {
}

protected static VersionPluginExtension createAndConfigureExtension(Project project) {

def extension = project.extensions.create(VersionPluginExtension, EXTENSION_NAME, DefaultVersionPluginExtension, project)
Provider<String> gitRoot = VersionPluginConventions.gitRoot.getStringValueProvider(project,
project.rootProject.projectDir.path
Expand All @@ -76,13 +83,50 @@ class VersionPlugin implements Plugin<Project> {
}))

extension.versionCodeScheme.convention(VersionPluginConventions.versionCodeScheme.getStringValueProvider(project).map({
VersionCodeScheme.valueOf(it.trim())
VersionCodeSchemes.valueOf(it.trim())
}))

extension.versionCodeOffset.convention(VersionPluginConventions.versionCodeOffset.getIntegerValueProvider(project))

extension.prefix.convention(VersionPluginConventions.prefix.getStringValueProvider(project))
extension.stage.convention(VersionPluginConventions.stage.getStringValueProvider(project))
extension.releaseBranchPattern.convention(VersionPluginConventions.releaseBranchPattern.getStringValueProvider(project))
extension.mainBranchPattern.convention(VersionPluginConventions.mainBranchPattern.getStringValueProvider(project))

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

extension.version.convention(VersionPluginConventions.version.getStringValueProvider(project)
.map {new ReleaseVersion(version: it) }
.orElse(inferVersionIfGitIsPresent(project, extension))
.orElse(new ReleaseVersion(version: VersionPluginConventions.UNINITIALIZED_VERSION))
)

extension.versionCode.convention(extension.versionCodeScheme.map({ VersionCodeSchemes scheme ->
def version = extension.version.map { it.version }.orNull
return VersionCode.Schemes
.fromExternal(scheme)
.versionCodeFor(version, extension.versionRepo.orNull, extension.versionCodeOffset.getOrElse(0))
}.memoize()))

extension.stage.convention(VersionPluginConventions.stage.getStringValueProvider(project))
extension.releaseBranchPattern.set(VersionPluginConventions.releaseBranchPattern.getStringValueProvider(project))
extension.mainBranchPattern.set(VersionPluginConventions.mainBranchPattern.getStringValueProvider(project))

return extension
}

private static Provider<ReleaseVersion> inferVersionIfGitIsPresent(Project project, VersionPluginExtension extension) {
def inferredVersion = ProviderExtensions.mapOnce(extension.git) { Grgit git ->
def version = extension.inferVersion(extension.versionScheme.get(), extension.stage, extension.scope)
.orElse(project.provider {
throw new GradleException('No version strategies were selected. Run build with --info for more detail.')
}).get()
project.logger.warn('Inferred project: {}, version: {}', project.name, version.version)
return version
} as Provider<ReleaseVersion>

return inferredVersion.orElse(new ReleaseVersion(version: VersionPluginConventions.UNINITIALIZED_VERSION))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VersionPluginConventions {
static final PropertyLookup versionCodeScheme = new PropertyLookup(
"VERSION_BUILDER_VERSION_CODE_SCHEME",
"versionBuilder.versionCodeScheme",
VersionCodeScheme.none)
VersionCodeSchemes.none)

static final PropertyLookup versionCodeOffset = new PropertyLookup(
"VERSION_BUILDER_VERSION_CODE_OFFSET",
Expand Down
Loading

0 comments on commit 97121e3

Please sign in to comment.