Skip to content

Commit

Permalink
fix #392 | Allow to get the uncached version (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikbrandon authored Oct 24, 2021
1 parent cfb5d71 commit 905f32c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ markdown_extensions:
anchorlink: true

extra:
version: '1.13.5'
version: '1.13.6'

nav:
- Home: 'index.md'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,53 @@ class ScmVersionExposedApiIntegrationTest extends BaseIntegrationTest {
result.output.contains("Branch: ${position.branch}")
result.task(":outputPosition").outcome == TaskOutcome.SUCCESS
}

def "getUncached should respect changing prefix"() {
given:
repository.tag("v1.2.3")
repository.tag("prefix4.5.6")
repository.tag("another7.8.9")
buildFile("""
task uncachedVersion { doLast {
println "Default prefix: \${scmVersion.uncached.decoratedVersion}"
scmVersion.tag.prefix = "prefix"
println "Custom prefix 1: \${scmVersion.uncached.decoratedVersion}"
scmVersion.tag.prefix = "another"
println "Custom prefix 2: \${scmVersion.uncached.decoratedVersion}"
} }
""")

when:
def result = runGradle('uncachedVersion')

then:
result.output.contains('Default prefix: 1.2.3')
result.output.contains('Custom prefix 1: 4.5.6')
result.output.contains('Custom prefix 2: 7.8.9')
result.task(":uncachedVersion").outcome == TaskOutcome.SUCCESS
}

def "getUncached should not modify cached version"() {
given:
repository.tag("v1.2.3")
repository.tag("prefix4.5.6")
buildFile("""
task uncachedVersion { doLast {
println "Default prefix: \${scmVersion.version}"
scmVersion.tag.prefix = "prefix"
println "Custom prefix: \${scmVersion.uncached.decoratedVersion}"
scmVersion.tag.prefix = "another"
println "Cached version: \${scmVersion.version}"
} }
""")

when:
def result = runGradle('uncachedVersion')

then:
result.output.contains('Default prefix: 1.2.3')
result.output.contains('Custom prefix: 4.5.6')
result.output.contains('Cached version: 1.2.3')
result.task(":uncachedVersion").outcome == TaskOutcome.SUCCESS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,34 @@ class VersionConfig {
}
}

/**
* @deprecated Due to the fact it uses the cached context, which results in returning the same
* version even though project properties got changed. Use {@link #getUncached()} instead.
* @return uncached version, but based on a cached context
*/
@Deprecated
@Nested
VersionService.DecoratedVersion getUncachedVersion() {
ensureContextExists()
return getVersionFromContext(context)
}

/**
* Allows to calculate and get the version, omitting caching mechanisms.
* May be slower for large projects, use then {@link #getVersion()} instead.
* @since 1.13.4
* @return uncached version
*/
@Nested
VersionService.DecoratedVersion getUncached() {
def context = GradleAwareContext.create(project, this)
return getVersionFromContext(context)
}

private static VersionService.DecoratedVersion getVersionFromContext(Context context) {
Properties rules = context.rules()
return context.versionService().currentDecoratedVersion(rules.version, rules.tag, rules.nextVersion)
def versionService = context.versionService()
return versionService.currentDecoratedVersion(rules.version, rules.tag, rules.nextVersion)
}

@Nested
Expand Down

0 comments on commit 905f32c

Please sign in to comment.