Skip to content

Commit

Permalink
#622 fix VersionVersionProperties.Creator (#627)
Browse files Browse the repository at this point in the history
* #622 fix: evaluate also instance VersionVersionProperties.Incrementer to run in right condition if dsl is kotlin
 Test & Documentation

* #622 fix: evaluate also instance VersionVersionProperties.Creator to run in right condition if dsl is kotlin
 Test & Documentation
  • Loading branch information
duschata authored May 26, 2023
1 parent ea801a9 commit c1654da
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/examples/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ scmVersion {
)
)

branchVersionCreator.putAll(
mapOf(
"master" to VersionProperties.Creator { s: String, scmPosition: ScmPosition -> "${s}-${scmPosition.branch}"}
)
)

versionCreator({versionFromTag,scmPosition -> "version"})
snapshotCreator({versionFromTag,scmPosition -> "version"})
versionIncrementer({versionIncrementerContext -> Version})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package pl.allegro.tech.build.axion.release

import org.ajoberstar.grgit.Grgit
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import pl.allegro.tech.build.axion.release.domain.LocalOnlyResolver
import pl.allegro.tech.build.axion.release.domain.properties.PropertiesBuilder
import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties
import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository
import pl.allegro.tech.build.axion.release.infrastructure.di.ScmRepositoryFactory
import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext
import spock.lang.Specification
import spock.lang.TempDir

import static pl.allegro.tech.build.axion.release.domain.scm.ScmPropertiesBuilder.scmProperties

class BranchVersionCreatorKotlinDslTest extends Specification {

@TempDir
File temporaryFolder

ScmRepository repository

VersionResolutionContext context

void setup() {
def rawRepository = Grgit.init(dir: temporaryFolder)

// let's make sure, not to use system wide user settings in tests
rawRepository.repository.jgit.repository.config.baseConfig.clear()

ScmProperties scmProperties = scmProperties(temporaryFolder).build()
ScmRepository scmRepository = ScmRepositoryFactory.create(scmProperties)

context = new VersionResolutionContext(
PropertiesBuilder.properties().build(),
scmRepository,
scmProperties,
temporaryFolder,
new LocalOnlyResolver(true)
)

repository = context.repository()
repository.commit(['*'], 'initial commit')
repository.tag("V1.0.0")

}


def "should not fail using closure as argument for branchVersionIncrementer"() {
given:

new FileTreeBuilder(temporaryFolder).file("build.gradle.kts",
"""
import com.github.zafarkhaja.semver.Version
import pl.allegro.tech.build.axion.release.domain.VersionIncrementerContext
import pl.allegro.tech.build.axion.release.domain.properties.VersionProperties
import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition
plugins {
id ("pl.allegro.tech.build.axion-release")
}
scmVersion {
tag {
prefix.set("V")
}
ignoreUncommittedChanges.set(false)
branchVersionCreator.putAll(
mapOf(
"master" to VersionProperties.Creator { s: String, scmPosition: ScmPosition -> "\${s}-\${scmPosition.branch}"}
)
)
}
project.version = scmVersion.version
""")

when:
def result = GradleRunner.create()
.withProjectDir(temporaryFolder)
.withPluginClasspath()
.withArguments('currentVersion', '-s')
.build()

then:
result.output.contains(" 1.0.1-master-SNAPSHOT")
result.task(":currentVersion").outcome == TaskOutcome.SUCCESS


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class KotlinDslCompatibilityTests extends Specification {
"""
import pl.allegro.tech.build.axion.release.domain.*
import pl.allegro.tech.build.axion.release.domain.properties.*
import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition
plugins {
id("pl.allegro.tech.build.axion-release")
Expand Down Expand Up @@ -90,6 +91,12 @@ class KotlinDslCompatibilityTests extends Specification {
)
)
branchVersionCreator.putAll(
mapOf(
"custom" to VersionProperties.Creator { s: String, scmPosition: ScmPosition -> "\${s}-\${scmPosition.branch}"}
)
)
versionCreator(VersionProperties.Creator({a,b -> "c"}))
versionCreator({a,b -> "c"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class VersionPropertiesFactory {

if (value == null) {
return defaultValue
} else if (!(value instanceof Closure)) {
return converter.call(value)
} else {
} else if ((value instanceof Closure) || (value instanceof VersionProperties.Creator)) {
return value
} else {
return converter.call(value)
}
}
}

0 comments on commit c1654da

Please sign in to comment.