diff --git a/docs/configuration/authorization.md b/docs/configuration/authorization.md index 00b25378..0039ec4d 100644 --- a/docs/configuration/authorization.md +++ b/docs/configuration/authorization.md @@ -35,15 +35,15 @@ from or key in form of String. scmVersion { repository { - customKey = project.file('keys/my_secret_key') + customKeyFile.set(project.file('keys/my_secret_key')) } } task loadKeyPassword << { - scmVersion.repository.customKeyPassword = loadPasswordFromSecureStorageOrSomething() + scmVersion.repository.customKeyPassword.set( loadPasswordFromSecureStorageOrSomething()) // you can load the key from secure storage as well! - scmVersion.repository.customKey = loadKeyFromSecureStorageOrSomething() + scmVersion.repository.customKey.set( loadKeyFromSecureStorageOrSomething()) } task release { @@ -70,5 +70,5 @@ made via `scmVersion.repository.customUsername` and `scmVersion.repository.customPassword` properties: task loadGitHubToken << { - scmVersion.repository.customUsername = loadGitHubTokenFromSomewhere() + scmVersion.repository.customUsername.set(loadGitHubTokenFromSomewhere()) } diff --git a/docs/configuration/basic_usage.md b/docs/configuration/basic_usage.md index 542d72d5..0174692e 100644 --- a/docs/configuration/basic_usage.md +++ b/docs/configuration/basic_usage.md @@ -47,7 +47,7 @@ apply plugin: 'pl.allegro.tech.build.axion-release' ``` scmVersion { tag { - prefix = 'my-project-name' + prefix.set("my-project-name") } } @@ -117,7 +117,7 @@ my-service my-service-client ``` -Use the `projectDirs` configuration parameter within a `monorepos` block to identify submodules +Use the `exclude()` configuration parameter within a `monorepos` block to identify submodules that should be excluded from consideration when calculating whether to increment the version of the parent project. Typically, you would do this in the top level project, assuming that submodules are named after the directory they appear in: @@ -125,7 +125,7 @@ project, assuming that submodules are named after the directory they appear in: ``` scmVersion { monorepos { - projectDirs = project.subprojects.collect({p -> p.name}) + exclude(project.subprojects.collect({p -> p.name})) } } ``` @@ -133,9 +133,9 @@ scmVersion { Version calculation rules: 1. Changes to files within a submodule increment that submodule's version only. 2. Changes to a submodule do not cause a change to the parent project's version if -the parent is set to ignore that submodule, via `projectDirs`. +the parent is set to ignore that submodule, via `exclude()`. 3. Changes to files in the parent project but which are not in a submodule identified via -`projectDirs` will cause the parent project's version to increment but not the +`exclude()` will cause the parent project's version to increment but not the versions of any submodules. If this is desired then consider wiring the `createRelease` or `release` tasks of the submodules to be dependencies of the tasks of the same name in the parent. diff --git a/docs/configuration/checks.md b/docs/configuration/checks.md index 3e2c2431..0f1bbe84 100644 --- a/docs/configuration/checks.md +++ b/docs/configuration/checks.md @@ -6,9 +6,9 @@ using `scmVersion.checks` properties: scmVersion { checks { - uncommittedChanges = false - aheadOfRemote = false - snapshotDependencies = false + uncommittedChanges.set(false) + aheadOfRemote.set(false) + snapshotDependencies.set(false) } } diff --git a/docs/configuration/dry_run.md b/docs/configuration/dry_run.md index e8136284..fb1a76ac 100644 --- a/docs/configuration/dry_run.md +++ b/docs/configuration/dry_run.md @@ -34,7 +34,7 @@ Local only mode can be switch on either using command line flag: or by altering configuration: scmVersion { - localOnly = true + localOnly.set(true) } Flag has precedence over configuration. Local only mode is evaluated diff --git a/docs/configuration/extensions.md b/docs/configuration/extensions.md index d2c4ed87..edd1834e 100644 --- a/docs/configuration/extensions.md +++ b/docs/configuration/extensions.md @@ -18,7 +18,7 @@ will print additional message: import pl.allegro.tech.build.axion.release.OutputCurrentVersionTask task customTask(type: OutputCurrentVersionTask) { - versionConfig = new VersionConfig(project) + versionConfig = project.objects.newInstance(VersionConfig,project.rootProject.layout.projectDirectory) } customTask.doFirst { diff --git a/docs/configuration/next_version.md b/docs/configuration/next_version.md index e4aba76d..e0a40e8a 100644 --- a/docs/configuration/next_version.md +++ b/docs/configuration/next_version.md @@ -45,8 +45,8 @@ using `scmVersion.nextVersion.suffix` and scmVersion { nextVersion { - suffix = 'alpha' - separator = '-' + suffix.set("alpha") + separator.set("-") } } @@ -56,7 +56,7 @@ documentation to see what serializers and deserializers are: scmVersion { nextVersion { - serializer = { nextVersionConfig, version -> ...} - deserializer = { nextVersionConfig, position -> ...} + serializer( { nextVersionConfig, version -> ...}) + deserializer( { nextVersionConfig, position -> ...}) } } diff --git a/docs/configuration/overview.md b/docs/configuration/overview.md index e7fee68a..b5fa0a2d 100644 --- a/docs/configuration/overview.md +++ b/docs/configuration/overview.md @@ -7,73 +7,71 @@ All `axion-release-plugin` configuration options: repository { // doc: Repository - type = 'git' // type of repository - directory = project.rootProject.file('./') // repository location - remote = 'origin' // remote name + type.set("git") // type of repository + directory.set(project.rootProject.file("./")) // repository location + remote.set("origin") // remote name // doc: Authorization - customKey = 'AAasaDDSSD...' or project.file('myKey') // custom authorization key (file or String) - customKeyPassword = 'secret' // key password + customKey.set("AAasaDDSSD...") // custom authorization key + customKeyFile.set(project.file("myKey")) // custom authorization key (from file) + customKeyPassword.set("secret") // key password } // doc: Dry run - localOnly = false // never connect to remote + localOnly.set(false) // never connect to remote // doc: Uncommitted changes - ignoreUncommittedChanges = true // should uncommitted changes force version bump + ignoreUncommittedChanges.set(true) // should uncommitted changes force version bump // doc: Version / Tag with highest version - useHighestVersion = false // Defaults as false, setting to true will find the highest visible version in the commit tree + useHighestVersion.set(false) // Defaults as false, setting to true will find the highest visible version in the commit tree // doc: Version / Sanitization - sanitizeVersion = true // should created version be sanitized, true by default - - // doc: Basic usage / Basic configuration - foldersToExclude = ['submodule1', 'submodule2'] // ignore changes in these subdirs when calculating changes to parent + sanitizeVersion.set(true) // should created version be sanitized, true by default tag { // doc: Version / Parsing - prefix = 'tag-prefix' // prefix to be used, 'v' by default, empty String means no prefix - branchPrefix = [ // set different prefix per branch - 'legacy/.*' : 'legacy' - ] - - versionSeparator = '-' // separator between prefix and version number, '' by default, empty String means no separator - serialize = { tag, version -> ... } // creates tag name from raw version - deserialize = { tag, position, tagName -> ... } // reads raw version from tag - initialVersion = { tag, position -> ... } // returns initial version if none found, 0.1.0 by default + prefix.set("tag-prefix") // prefix to be used, "v" by default, empty String means no prefix + branchPrefix.putAll( [ // set different prefix per branch + "legacy/.*" : "legacy" + ]) + + versionSeparator.set("-") // separator between prefix and version number, "" by default, empty String means no separator + serialize({ tag, version -> ... }) // creates tag name from raw version + deserialize( { tag, position, tagName -> ... }) // reads raw version from tag + initialVersion({ tag, position -> ... }) // returns initial version if none found, 0.1.0 by default } nextVersion { // doc: Next version markers - suffix = 'alpha' // tag suffix - separator = '-' // separator between version and suffix - serializer = { nextVersionConfig, version -> ... } // append suffix to version tag - deserializer = { nextVersionConfig, position -> ... } // strip suffix off version tag + suffix.set("alpha") // tag suffix + separator.set("-") // separator between version and suffix + serializer({ nextVersionConfig, version -> ... }) // append suffix to version tag + deserializer({ nextVersionConfig, position -> ... }) // strip suffix off version tag } // doc: Version / Decorating - versionCreator { version, position -> ... } // creates version visible for Gradle from raw version and current position in scm - versionCreator 'versionWithBranch' // use one of predefined version creators - branchVersionCreator = [ // use different creator per branch - 'feature/.*': 'default' - ] + versionCreator({ version, position -> ... }) // creates version visible for Gradle from raw version and current position in scm + versionCreator("versionWithBranch") // use one of predefined version creators + branchVersionCreator.putAll( [ // use different creator per branch + "feature/.*": "default" + ]) // doc: Version / Snapshot - snapshotCreator { version, position -> ... } // customize 'snapshot' suffix for version not on tag + snapshotCreator({ version, position -> ... }) // customize "snapshot" suffix for version not on tag // doc: Version / Incrementing - versionIncrementer {context, config -> ...} // closure that increments a version from the raw version, current position in scm and config - versionIncrementer 'incrementPatch' // use one of predefined version incrementing rules - branchVersionIncrementer = [ // use different incrementer per branch - 'feature/.*': 'incrementMinor' - ] + versionIncrementer({context, config -> ...}) // closure that increments a version from the raw version, current position in scm and config + versionIncrementer("incrementPatch") // use one of predefined version incrementing rules + branchVersionIncrementer.putAll( [ // use different incrementer per branch + "feature/.*": "incrementMinor" + ]) // doc: Pre/post release hooks - createReleaseCommit true // should create empty commit to annotate release in commit history, false by default - releaseCommitMessage { version, position -> ... } // custom commit message if commits are created + createReleaseCommit.set(true) // should create empty commit to annotate release in commit history, false by default + releaseCommitMessage({ version, position -> ... }) // custom commit message if commits are created // doc: Pre-release checks checks { - uncommittedChanges = false // permanently disable uncommitted changes check - aheadOfRemote = false // permanently disable ahead of remote check + uncommittedChanges.set(false) // permanently disable uncommitted changes check + aheadOfRemote.set(false) // permanently disable ahead of remote check } } diff --git a/docs/configuration/repository.md b/docs/configuration/repository.md index c6191d29..c9a232ac 100644 --- a/docs/configuration/repository.md +++ b/docs/configuration/repository.md @@ -9,7 +9,7 @@ property: scmVersion { repository { - directory = project.rootProject.file('../') + directory.set(project.rootProject.file('../')) } } @@ -17,7 +17,7 @@ You can also change remote used to push changes: scmVersion { repository { - remote = 'myRemote' + remote.set("myRemote") } } @@ -32,7 +32,7 @@ allowed even when a local branch is not checked out: scmVersion { repository { - pushTagsOnly = true + pushTagsOnly.set(true) } } diff --git a/docs/configuration/uncommitted_changes.md b/docs/configuration/uncommitted_changes.md index b961ec00..fd65a1b2 100644 --- a/docs/configuration/uncommitted_changes.md +++ b/docs/configuration/uncommitted_changes.md @@ -8,7 +8,7 @@ In order to treat uncommitted changes as trigger for version increment, change setting: scmVersion { - ignoreUncommittedChanges = false + ignoreUncommittedChanges.set(false) } This changes behavior from: diff --git a/docs/configuration/version.md b/docs/configuration/version.md index 2ffd16ae..e80b5c84 100644 --- a/docs/configuration/version.md +++ b/docs/configuration/version.md @@ -27,7 +27,7 @@ calculating current version. Prefix can be set using scmVersion { tag { - prefix = 'my-prefix' + prefix.set("my-prefix") } } @@ -38,10 +38,10 @@ version prefix on `legacy-` branches): scmVersion { tag { - prefix = 'default-prefix' - branchPrefix = [ - 'legacy.*' : 'legacy-prefix' - ] + prefix.set("default-prefix") + branchPrefix.putAll( [ + "legacy.*" : "legacy-prefix" + ]) } } @@ -87,7 +87,7 @@ analysed. In order to activate this feature: scmVersion { - useHighestVersion = true + useHighestVersion.set(true) } With a tree similar to this: @@ -131,7 +131,7 @@ deserialization config object and position in SCM: scmVersion { tag { - deserialize = {config, position, tagName -> ...} + deserialize({config, position, tagName -> ...}) } } @@ -162,7 +162,7 @@ serialization config object and version: scmVersion { tag { - serialize = {config, version -> ...} + serialize({config, version -> ...}) } } @@ -177,7 +177,7 @@ that will construct initial version: scmVersion { tag { - initialVersion = {config, position -> ...} + initialVersion({config, position -> ...}) } } @@ -201,7 +201,7 @@ You can set one of predefined rules via `scmVersion.versionIncrementer` method: scmVersion { - versionIncrementer 'incrementPatch' + versionIncrementer('incrementPatch') } Or via `release.versionIncrementer` command line argument, which @@ -212,14 +212,14 @@ overrides any other incrementer settings: If rule accepts parameters, they can be passed via configuration map: scmVersion { - versionIncrementer 'someIncrementer', [:] + versionIncrementer('someIncrementer', [:]) } Alternatively you can specify a custom rule by setting a closure that would accept a context object and return a `Version` object: scmVersion { - versionIncrementer { context -> ... } + versionIncrementer({ context -> ... }) } The context object passed to closure contains the following: @@ -234,11 +234,11 @@ either closure, name of predefined incrementer or name and list of arguments in case predefined incrementer requires configuration: scmVersion { - branchVersionIncrementer = [ + branchVersionIncrementer.putAll( [ 'feature/.*' : 'incrementMinor', 'bugfix/.*' : { c -> c.currentVersion.incrementPatchVersion() }, 'legacy/.*' : [ 'incrementMinorIfNotOnRelease', [releaseBranchPattern: 'legacy/release.*'] ] - ] + ]) } If none matches current branch, incrementer set in `versionIncrementer` @@ -250,7 +250,7 @@ This rule uses additional parameter `releaseBranchPattern` (by default it's set to `v/.+`): scmVersion { - versionIncrementer 'incrementMinorIfNotOnRelease', [releaseBranchPattern: 'v.*'] + versionIncrementer('incrementMinorIfNotOnRelease', [releaseBranchPattern: 'v.*']) } ### incrementPrerelease @@ -259,7 +259,7 @@ This rule uses additional parameter `initialPreReleaseIfNotOnPrerelease` (by def it's empty): scmVersion { - versionIncrementer 'incrementPrerelease', [initialPreReleaseIfNotOnPrerelease: 'rc1'] + versionIncrementer('incrementPrerelease', [initialPreReleaseIfNotOnPrerelease: 'rc1']) } ## Decorating @@ -273,7 +273,7 @@ request if you have something useful!). Decoration phase is conducted by method: scmVersion { - versionCreator 'versionWithBranch' + versionCreator('versionWithBranch') } Or via `release.versionCreator` command line argument, which overrides @@ -285,10 +285,10 @@ You can also set decorators per branches that match specific regular expression: scmVersion { - branchVersionCreator = [ + branchVersionCreator.putAll( [ 'feature/.*': { version, position -> ...}, 'bugfix/.*': 'simple' - ] + ]) } Per-branch version creators must be closures, there is no support for @@ -304,16 +304,16 @@ This is the default version creator that does nothing: It might be useful when you want some branches to do *nothing*: scmVersion { - branchVersionCreator = [ + branchVersionCreator.putAll([ 'feature/.*': { version, position -> ...}, 'release/.*': 'simple' - ] + ]) } #### versionWithBranch scmVersion { - versionCreator 'versionWithBranch' + versionCreator('versionWithBranch') } This version creator appends branch name to version unless you are on @@ -338,7 +338,7 @@ By default, when not on tag, `-SNAPSHOT` suffix is appended It can be customized by scmVersion { - snapshotCreator: { version, position -> ...} + snapshotCreator({ version, position -> ...}) } Snapshot creator can be implemented by creating closure: @@ -362,5 +362,5 @@ You can switch off version sanitization via `scmVersion.sanitizeVersion` property: scmVersion { - sanitizeVersion = false + sanitizeVersion.set(false) } diff --git a/docs/examples/examples.md b/docs/examples/examples.md index a6a2b35f..52098dad 100644 --- a/docs/examples/examples.md +++ b/docs/examples/examples.md @@ -7,7 +7,7 @@ and each version has branch name appended (unless on master). This allows us on of branches that are ready for testing: scmVersion { - versionCreator 'versionWithBranch' + versionCreator("versionWithBranch") } @@ -16,17 +16,17 @@ of branches that are ready for testing: This replacement pattern will update any `version* x.x.x` occurrences in README.md and create release commit: scmVersion { - versionCreator 'versionWithBranch' + versionCreator("versionWithBranch") hooks { - pre 'fileUpdate', [file: 'README.md', pattern: {v,p -> /(version.) $v/}, replacement: {v, p -> "\$1 $v"}] - pre 'commit' + pre("fileUpdate", [file: "README.md", pattern: {v,p -> /(version.) $v/}, replacement: {v, p -> "\$1 $v"}]) + pre("commit") } } ## Use with Gradle Kotlin DSL -As of v1.13.8, configuration constructs are compatible with Gradle's Kotlin DSL. As the configuration is richly typed, IDE code completion will be available (for IDEs that provide this for Gradle Kotlin DSL build scripts) +As of v1.13.8, configuration constructs are compatible with Gradle"s Kotlin DSL. As the configuration is richly typed, IDE code completion will be available (for IDEs that provide this for Gradle Kotlin DSL build scripts) with these key configuration objects available for reference: * [VersionConfig](https://github.com/allegro/axion-release-plugin/blob/main/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy) * [TagNameSerializationConfig](https://github.com/allegro/axion-release-plugin/blob/main/src/main/groovy/pl/allegro/tech/build/axion/release/domain/TagNameSerializationConfig.groovy) @@ -40,31 +40,27 @@ A full example showing most configurable elements: ```kotlin scmVersion { - localOnly = true - useHighestVersion = true + localOnly.set(true) + useHighestVersion.set(true) tag { - prefix = "release" - versionSeparator = "/" + prefix.set("release") + versionSeparator.set("/") // configure via function calls - setDeserializer({ tagProperties,scmPostion,String -> "tag" }) - setSerializer( { tagProperties,version -> "tag" }) - - // or, assign to existing variables - serialize = TagProperties.Serializer({ tagProperties,version -> "tag" }) - deserialize = TagProperties.Deserializer({ tagProperties,scmPostion,String -> "tag" }) + deserializer({ tagProperties,scmPostion,String -> "tag" }) + serializer( { tagProperties,version -> "tag" }) } repository { - type = "git" + type.set("git") } checks { - setAheadOfRemote(false) - setSnapshotDependencies(true) + aheadOfRemote.set(false) + snapshotDependencies.set(true) } nextVersion { // function calls - setDeserializer( { nextVersionProperties,scmPosition,tag -> "version" }) - setSerializer( {nextVersionProperties,version -> "version"}) + deserializer( { nextVersionProperties,scmPosition,tag -> "version" }) + serializer( {nextVersionProperties,version -> "version"}) } hooks { pre({println("here")}) @@ -103,13 +99,8 @@ scmVersion { monorepos { } - versionCreator = VersionProperties.Creator({versionFromTag,scmPosition -> "version"}) versionCreator({versionFromTag,scmPosition -> "version"}) - - snapshotCreator = VersionProperties.Creator({versionFromTag,scmPosition -> "version"}) snapshotCreator({versionFromTag,scmPosition -> "version"}) - - versionIncrementer = VersionProperties.Incrementer({versionIncrementerContext -> Version}) versionIncrementer({versionIncrementerContext -> Version}) } diff --git a/src/integration/groovy/pl/allegro/tech/build/axion/release/BaseIntegrationTest.groovy b/src/integration/groovy/pl/allegro/tech/build/axion/release/BaseIntegrationTest.groovy index 28511b2d..2cba83ab 100644 --- a/src/integration/groovy/pl/allegro/tech/build/axion/release/BaseIntegrationTest.groovy +++ b/src/integration/groovy/pl/allegro/tech/build/axion/release/BaseIntegrationTest.groovy @@ -3,14 +3,16 @@ package pl.allegro.tech.build.axion.release import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner +import java.nio.file.Files + class BaseIntegrationTest extends RepositoryBasedTest { File buildFile() { - return new FileTreeBuilder(temporaryFolder).file("build.gradle","") + return new FileTreeBuilder(temporaryFolder).file("build.gradle", "") } File newFile(String name) { - return new FileTreeBuilder(temporaryFolder).file(name,"") + return new FileTreeBuilder(temporaryFolder).file(name, "") } void buildFile(String contents) { @@ -37,7 +39,27 @@ class BaseIntegrationTest extends RepositoryBasedTest { } BuildResult runGradle(String... arguments) { - return gradle().withArguments(arguments).build() + def args = [] + args.addAll(arguments) + args.add("--stacktrace") + args.add("--configuration-cache") + args.add("--warning-mode=fail") + + try { + return gradle().withArguments(args).build() + } + finally { + def ccDir = new File(temporaryFolder, "build/reports/configuration-cache") + if (ccDir.exists() && ccDir.isDirectory()) { + def dirName = ccDir.listFiles().first().name + def ccReport = new File(ccDir, dirName).listFiles().first() + def name = "${ccReport.parentFile.name}-${ccReport.name}" + def targetFile = new File(System.getProperty("java.io.tmpdir"), name) + targetFile.delete() + Files.copy(ccReport.toPath(), targetFile.toPath()) + println("Configuration cache report available @ file://${targetFile.absolutePath}") + } + } } BuildResult runGradleAndFail(String... arguments) { diff --git a/src/integration/groovy/pl/allegro/tech/build/axion/release/ExtendingTasksIntegrationTest.groovy b/src/integration/groovy/pl/allegro/tech/build/axion/release/ExtendingTasksIntegrationTest.groovy deleted file mode 100644 index bb4f7e45..00000000 --- a/src/integration/groovy/pl/allegro/tech/build/axion/release/ExtendingTasksIntegrationTest.groovy +++ /dev/null @@ -1,44 +0,0 @@ -package pl.allegro.tech.build.axion.release - -import spock.lang.Unroll - -class ExtendingTasksIntegrationTest extends BaseIntegrationTest { - - @Unroll - def "should allow on creating task that extends #task"() { - given: - vanillaBuildFile(""" - plugins { - id 'pl.allegro.tech.build.axion-release' apply false - } - - import pl.allegro.tech.build.axion.release.domain.VersionConfig - import pl.allegro.tech.build.axion.release.${task} - - task customTask(type: ${task}) { - versionConfig = new VersionConfig(project) - } - - customTask.doFirst { - println "Check for this message" - } - """) - - when: - def result = runGradle('customTask', '-Prelease.dryRun', '-Prelease.disableChecks', '-Prelease.version=1.2.3', '-s') - - then: - result.output.contains('Check for this message') - - where: - task << [ - 'CreateReleaseTask', - 'MarkNextVersionTask', - 'OutputCurrentVersionTask', - 'PushReleaseTask', - 'ReleaseTask', - 'VerifyReleaseTask' - ] - } - -} diff --git a/src/integration/groovy/pl/allegro/tech/build/axion/release/KotlinDslCompatibilityTests.groovy b/src/integration/groovy/pl/allegro/tech/build/axion/release/KotlinDslCompatibilityTests.groovy index b08de5b2..45a03f59 100644 --- a/src/integration/groovy/pl/allegro/tech/build/axion/release/KotlinDslCompatibilityTests.groovy +++ b/src/integration/groovy/pl/allegro/tech/build/axion/release/KotlinDslCompatibilityTests.groovy @@ -21,39 +21,31 @@ class KotlinDslCompatibilityTests extends Specification { } scmVersion { - localOnly = true - useHighestVersion = true + localOnly.set(true) + useHighestVersion.set(true) tag { - prefix = "release" - versionSeparator = "/" + prefix.set("release") + versionSeparator.set("/") // configure via function calls - setDeserializer({ a,b,c -> "d" }) - setSerializer( { a,b -> "c" }) + deserializer({ a,b,c -> "d" }) + serializer( { a,b -> "c" }) - // assignment via Kotlin property extension -// tagNameSerializer = { a,b -> "c" } -// tagNameDeserializer = { a,b,c -> "d" } - - // assignment to existing variables - serialize = TagProperties.Serializer({a,b -> "c"}) - deserialize = TagProperties.Deserializer({a,b,c -> "d"}) + // assignment to existing properties + serialize.set(TagProperties.Serializer({a,b -> "c"})) + deserialize.set(TagProperties.Deserializer({a,b,c -> "d"})) } repository { - type = "git" + type.set("git") } checks { - setAheadOfRemote(false) - setSnapshotDependencies(true) + aheadOfRemote.set(false) + snapshotDependencies.set(true) } nextVersion { // function calls - setDeserializer( { a,b,c -> "d" }) - setSerializer( {a,b -> "c"}) - - // assignment via Kotlin property extension -// versionSerializer = {a,b -> "c"} -// versionDeserializer = {a,b,c -> "d" } + deserializer( { a,b,c -> "d" }) + serializer( {a,b -> "c"}) } hooks { pre({println("here")}) @@ -92,13 +84,13 @@ class KotlinDslCompatibilityTests extends Specification { monorepos { } - versionCreator = VersionProperties.Creator({a,b -> "c"}) + versionCreator(VersionProperties.Creator({a,b -> "c"})) versionCreator({a,b -> "c"}) - snapshotCreator = VersionProperties.Creator({a,b -> "c"}) + snapshotCreator(VersionProperties.Creator({a,b -> "c"})) snapshotCreator({a,b -> "c"}) - versionIncrementer = VersionProperties.Incrementer({a -> null}) + versionIncrementer(VersionProperties.Incrementer({a -> null})) versionIncrementer({a -> null}) } @@ -109,7 +101,7 @@ class KotlinDslCompatibilityTests extends Specification { def result = GradleRunner.create() .withProjectDir(temporaryFolder) .withPluginClasspath() - .withArguments('currentVersion', '--stacktrace') + .withArguments('currentVersion') .build() then: diff --git a/src/integration/groovy/pl/allegro/tech/build/axion/release/MultiModuleProjectIntegrationTest.groovy b/src/integration/groovy/pl/allegro/tech/build/axion/release/MultiModuleProjectIntegrationTest.groovy index 1fb84ec2..32f1643f 100644 --- a/src/integration/groovy/pl/allegro/tech/build/axion/release/MultiModuleProjectIntegrationTest.groovy +++ b/src/integration/groovy/pl/allegro/tech/build/axion/release/MultiModuleProjectIntegrationTest.groovy @@ -54,7 +54,7 @@ class MultiModuleProjectIntegrationTest extends BaseIntegrationTest { buildFile(''' scmVersion { monorepos { - projectDirs = project.subprojects.collect({p -> p.name}) + exclude(project.subprojects.collect({p -> p.name})) } } ''' diff --git a/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy b/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy index f9a1a3d4..361e946d 100644 --- a/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy +++ b/src/integration/groovy/pl/allegro/tech/build/axion/release/SimpleIntegrationTest.groovy @@ -98,12 +98,12 @@ class SimpleIntegrationTest extends BaseIntegrationTest { result.output.contains(fullPrefix() +'blabla') } - def "should use initial verison setting"() { + def "should use initial version setting"() { given: buildFile(""" scmVersion { tag { - initialVersion = { t, p -> '0.0.1' } + initialVersion({ t, p -> '0.0.1' }) } } """) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/BaseAxionTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/BaseAxionTask.groovy new file mode 100644 index 00000000..4a305715 --- /dev/null +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/BaseAxionTask.groovy @@ -0,0 +1,25 @@ +package pl.allegro.tech.build.axion.release + +import org.gradle.api.DefaultTask +import org.gradle.api.file.ProjectLayout +import org.gradle.api.provider.ProviderFactory +import org.gradle.api.tasks.Nested +import pl.allegro.tech.build.axion.release.domain.VersionConfig +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext + +import javax.inject.Inject + +abstract class BaseAxionTask extends DefaultTask { + @Nested + VersionConfig versionConfig + + @Inject + protected abstract ProjectLayout getLayout(); + + @Inject + protected abstract ProviderFactory getProviders(); + + protected VersionResolutionContext resolutionContext() { + return VersionResolutionContext.create(versionConfig, layout.projectDirectory) + } +} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/CreateReleaseTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/CreateReleaseTask.groovy index 99daf83e..c8715f2a 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/CreateReleaseTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/CreateReleaseTask.groovy @@ -1,26 +1,16 @@ package pl.allegro.tech.build.axion.release -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional + import org.gradle.api.tasks.TaskAction import pl.allegro.tech.build.axion.release.domain.Releaser -import pl.allegro.tech.build.axion.release.domain.VersionConfig -import pl.allegro.tech.build.axion.release.infrastructure.di.Context -import pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext - -class CreateReleaseTask extends DefaultTask { +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext - @Input - @Optional - VersionConfig versionConfig +abstract class CreateReleaseTask extends BaseAxionTask { @TaskAction void release() { - VersionConfig config = GradleAwareContext.configOrCreateFromProject(project, versionConfig) - Context context = GradleAwareContext.create(project, config) + VersionResolutionContext context = resolutionContext() Releaser releaser = context.releaser() releaser.release(context.rules()) } - } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/MarkNextVersionTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/MarkNextVersionTask.groovy index 36b073b7..d281fe3d 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/MarkNextVersionTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/MarkNextVersionTask.groovy @@ -1,30 +1,18 @@ package pl.allegro.tech.build.axion.release -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional + import org.gradle.api.tasks.TaskAction import pl.allegro.tech.build.axion.release.domain.NextVersionMarker -import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.properties.Properties -import pl.allegro.tech.build.axion.release.infrastructure.di.Context -import pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext - -class MarkNextVersionTask extends DefaultTask { - - @Input - @Optional - VersionConfig versionConfig +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext +abstract class MarkNextVersionTask extends BaseAxionTask { @TaskAction void release() { - VersionConfig config = GradleAwareContext.configOrCreateFromProject(project, versionConfig) - Context context = GradleAwareContext.create(project, config) - + VersionResolutionContext context = resolutionContext() NextVersionMarker marker = new NextVersionMarker(context.scmService()) Properties rules = context.rules() - marker.markNextVersion(rules.nextVersion, rules.tag, config) + marker.markNextVersion(rules.nextVersion, rules.tag, versionConfig) } - } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy index 4ea53976..dbc80565 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/OutputCurrentVersionTask.groovy @@ -1,29 +1,31 @@ package pl.allegro.tech.build.axion.release -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Nested +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskAction -import pl.allegro.tech.build.axion.release.domain.VersionConfig -import pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext import pl.allegro.tech.build.axion.release.infrastructure.output.OutputWriter -class OutputCurrentVersionTask extends DefaultTask { +import javax.inject.Inject - @Nested +abstract class OutputCurrentVersionTask extends BaseAxionTask { + + @Input @Optional - VersionConfig versionConfig + abstract Property getQuiet() + @Inject OutputCurrentVersionTask() { this.outputs.upToDateWhen { false } + getQuiet().convention(providers.gradleProperty("release.quiet").map({true}) + .orElse(false)) } @TaskAction void output() { - boolean quiet = project.hasProperty('release.quiet') - VersionConfig config = GradleAwareContext.configOrCreateFromProject(project, versionConfig) + boolean quiet = getQuiet().get() - String outputContent = config.version + String outputContent = versionConfig.version if (!quiet) { outputContent = '\nProject version: ' + outputContent } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/PushReleaseTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/PushReleaseTask.groovy index 35a91f52..3c3ce0d2 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/PushReleaseTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/PushReleaseTask.groovy @@ -1,30 +1,20 @@ package pl.allegro.tech.build.axion.release -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional + import org.gradle.api.tasks.TaskAction import pl.allegro.tech.build.axion.release.domain.Releaser -import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult -import pl.allegro.tech.build.axion.release.infrastructure.di.Context -import pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext - -class PushReleaseTask extends DefaultTask { +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext - @Input - @Optional - VersionConfig versionConfig +abstract class PushReleaseTask extends BaseAxionTask { @TaskAction void release() { - VersionConfig config = GradleAwareContext.configOrCreateFromProject(project, versionConfig) - Context context = GradleAwareContext.create(project, config) - + VersionResolutionContext context = resolutionContext() Releaser releaser = context.releaser() ScmPushResult result = releaser.pushRelease() - if(!result.success) { + if (!result.success) { def message = result.remoteMessage.orElse("Unknown error during push") logger.error("remote message: ${message}") throw new ReleaseFailedException(message) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy index b2370f7d..2891bc58 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy @@ -2,34 +2,39 @@ package pl.allegro.tech.build.axion.release import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.Task +import pl.allegro.tech.build.axion.release.domain.SnapshotDependenciesChecker import pl.allegro.tech.build.axion.release.domain.VersionConfig +import pl.allegro.tech.build.axion.release.util.FileLoader -class ReleasePlugin implements Plugin { +abstract class ReleasePlugin implements Plugin { public static final String VERSION_EXTENSION = 'scmVersion' - public static final String VERIFY_RELEASE_TASK = 'verifyRelease' - public static final String RELEASE_TASK = 'release' - public static final String CREATE_RELEASE_TASK = 'createRelease' - public static final String PUSH_RELEASE_TASK = 'pushRelease' - public static final String MARK_NEXT_VERSION_TASK = 'markNextVersion' - public static final String CURRENT_VERSION_TASK = 'currentVersion' - public static final String DRY_RUN_FLAG = 'release.dryRun' - @Override void apply(Project project) { - project.extensions.create(VERSION_EXTENSION, VersionConfig, project) + FileLoader.setRoot(project.rootDir) + + def versionConfig = project.extensions.create(VERSION_EXTENSION, VersionConfig, project.rootProject.layout.projectDirectory) + + project.tasks.withType(BaseAxionTask).configureEach( { + it.versionConfig = versionConfig + }) project.tasks.register(VERIFY_RELEASE_TASK, VerifyReleaseTask) { group = 'Release' description = 'Verifies code is ready for release.' + snapshotDependencies.addAll( + project.provider({ + SnapshotDependenciesChecker checker = new SnapshotDependenciesChecker(); + return checker.snapshotVersions(project) + }) + ) } project.tasks.register(RELEASE_TASK, ReleaseTask) { diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy index a91b18b1..5a4158ff 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy @@ -1,25 +1,15 @@ package pl.allegro.tech.build.axion.release -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskAction import pl.allegro.tech.build.axion.release.domain.Releaser -import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult -import pl.allegro.tech.build.axion.release.infrastructure.di.Context -import pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext -class ReleaseTask extends DefaultTask { - - @Input - @Optional - VersionConfig versionConfig +abstract class ReleaseTask extends BaseAxionTask { @TaskAction void release() { - VersionConfig config = GradleAwareContext.configOrCreateFromProject(project, versionConfig) - Context context = GradleAwareContext.create(project, config) + VersionResolutionContext context = resolutionContext() Releaser releaser = context.releaser() ScmPushResult result = releaser.releaseAndPush(context.rules()) @@ -29,8 +19,4 @@ class ReleaseTask extends DefaultTask { throw new ReleaseFailedException(message) } } - - void setVersionConfig(VersionConfig versionConfig) { - this.versionConfig = versionConfig - } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseTask.groovy index 610d5aaa..5b0664e9 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseTask.groovy @@ -1,70 +1,72 @@ package pl.allegro.tech.build.axion.release -import org.gradle.api.DefaultTask +import org.gradle.api.provider.SetProperty import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskAction import pl.allegro.tech.build.axion.release.domain.LocalOnlyResolver -import pl.allegro.tech.build.axion.release.domain.SnapshotDependenciesChecker -import pl.allegro.tech.build.axion.release.domain.VersionConfig -import pl.allegro.tech.build.axion.release.domain.properties.ChecksProperties import pl.allegro.tech.build.axion.release.domain.scm.ScmChangesPrinter import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository -import pl.allegro.tech.build.axion.release.infrastructure.di.Context -import pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext -class VerifyReleaseTask extends DefaultTask { +abstract class VerifyReleaseTask extends BaseAxionTask { @Input - @Optional - VersionConfig versionConfig + abstract SetProperty getSnapshotDependencies() @TaskAction void verify() { - VersionConfig config = GradleAwareContext.configOrCreateFromProject(project, versionConfig) - Context context = GradleAwareContext.create(project, config) + VersionResolutionContext context = resolutionContext() ScmRepository repository = context.repository() ScmChangesPrinter changesPrinter = context.changesPrinter() - - boolean dryRun = context.rules().dryRun - ChecksProperties checksRules = context.rules().checks LocalOnlyResolver localOnlyResolver = context.localOnlyResolver() - if (checksRules.checkUncommittedChanges) { + def dryRun = versionConfig.dryRun.get() + + checkUncommittedChanges(repository, changesPrinter, dryRun) + checkAheadOfRemote(repository, localOnlyResolver, dryRun) + checkSnapshotDependencies() + } + + private void checkUncommittedChanges(ScmRepository repository, ScmChangesPrinter changesPrinter, boolean dryRun) { + if (versionConfig.checks.checkUncommittedChanges().get()) { boolean uncommittedChanges = repository.checkUncommittedChanges() - project.logger.quiet("Looking for uncommitted changes.. ${uncommittedChanges ? 'FAILED' : ''}") + logger.quiet("Looking for uncommitted changes.. ${uncommittedChanges ? 'FAILED' : ''}") if (uncommittedChanges) { changesPrinter.printChanges() if (!dryRun) { throw new IllegalStateException("There are uncommitted files in your repository - can't release. " + - "See above for list of all changes.") + "See above for list of all changes.") } } } else { - project.logger.quiet('Skipping uncommitted changes check') + logger.quiet('Skipping uncommitted changes check') } + } - boolean remoteAttached = repository.remoteAttached(config.repository.remote) - if (checksRules.checkAheadOfRemote && !localOnlyResolver.localOnly(remoteAttached)) { + private void checkAheadOfRemote(ScmRepository repository, LocalOnlyResolver localOnlyResolver, boolean dryRun) { + boolean remoteAttached = repository.remoteAttached(versionConfig.repository.remote.get()) + def localOnly = localOnlyResolver.localOnly(remoteAttached) + if (versionConfig.checks.checkAheadOfRemote().get() && !localOnly) { boolean aheadOfRemote = repository.checkAheadOfRemote() - project.logger.quiet("Checking if branch is ahead of remote.. ${aheadOfRemote ? 'FAILED' : ''}") + logger.quiet("Checking if branch is ahead of remote.. ${aheadOfRemote ? 'FAILED' : ''}") if (aheadOfRemote && !dryRun) { throw new IllegalStateException("Current branch is ahead of remote counterpart - can't release.") } } else { - project.logger.quiet("Skipping ahead of remote check") + logger.quiet("Skipping ahead of remote check") } + } - if (checksRules.checkSnapshotDependencies) { - SnapshotDependenciesChecker checker = new SnapshotDependenciesChecker(); - Collection snapshotVersions = checker.snapshotVersions(project) - project.logger.quiet("Checking for snapshot versions.. ${!snapshotVersions.empty ? 'FAILED' : ''}") + private void checkSnapshotDependencies() { + if (versionConfig.checks.checkSnapshotDependencies().get()) { + def snapshotVersions = snapshotDependencies.get() + logger.quiet("Checking for snapshot versions.. ${!snapshotVersions.empty ? 'FAILED' : ''}") if (!snapshotVersions.empty) { throw new IllegalStateException("The project uses snapshot versions - can't release. Snapshots found: " + snapshotVersions) } } else { - project.logger.quiet("Skipping snapshot dependencies check") + logger.quiet("Skipping snapshot dependencies check") } } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/BaseExtension.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/BaseExtension.groovy new file mode 100644 index 00000000..c22a453a --- /dev/null +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/BaseExtension.groovy @@ -0,0 +1,29 @@ +package pl.allegro.tech.build.axion.release.domain + +import org.gradle.api.file.ProjectLayout +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Provider +import org.gradle.api.provider.ProviderFactory + +import javax.inject.Inject + +abstract class BaseExtension { + @Inject + protected abstract ProviderFactory getProviders() + + @Inject + protected abstract ProjectLayout getLayout() + + @Inject + protected abstract ObjectFactory getObjects(); + + protected Provider gradleProperty(String name) { + // forUseAtConfigurationTime() required to make tests happy + // TODO: Gradle 7.2+ deprecates forUseAtConfigurationTime(), remove at some future time + return providers.gradleProperty(name).forUseAtConfigurationTime() + } + + protected Provider gradlePropertyPresent(String name) { + return gradleProperty(name).map({true}) + } +} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy index 5bcdb32f..47424c2a 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarker.groovy @@ -1,14 +1,15 @@ package pl.allegro.tech.build.axion.release.domain import com.github.zafarkhaja.semver.Version -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger +import org.slf4j.Logger +import org.slf4j.LoggerFactory import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties import pl.allegro.tech.build.axion.release.domain.properties.TagProperties import pl.allegro.tech.build.axion.release.domain.scm.ScmService class NextVersionMarker { - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(NextVersionMarker) + private static final Logger logger = LoggerFactory.getLogger(NextVersionMarker) private final ScmService repositoryService @@ -26,7 +27,7 @@ class NextVersionMarker { VersionIncrementerContext context = new VersionIncrementerContext(currentVersion, repositoryService.position(), repositoryService.isLegacyDefTagnameRepo()) nextVersion = nextVersionRules.versionIncrementer ? PredefinedVersionIncrementer.versionIncrementerFor(nextVersionRules.versionIncrementer).apply(context) : - versionConfig.versionIncrementer.apply(context) + versionConfig.versionIncrementer.get().apply(context) logger.info("Next Version not specified. Creating next version with default incrementer: $nextVersion") } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy index ade944f3..d8053e9f 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementer.groovy @@ -25,7 +25,7 @@ enum PredefinedVersionIncrementer { INCREMENT_MINOR_IF_NOT_ON_RELEASE_BRANCH('incrementMinorIfNotOnRelease', { VersionIncrementerContext context, Map config -> if (!config.releaseBranchPattern) { - config.releaseBranchPattern = context.isLegacyDefTagnameRepo() ? TagPrefixConf.DEFAULT_LEGACY_PREFIX + '/.+' : TagPrefixConf.prefix() + '/.+' + config.releaseBranchPattern = context.isLegacyDefTagnameRepo() ? TagPrefixConf.DEFAULT_LEGACY_PREFIX + '/.+' : TagPrefixConf.defaultPrefix() + '/.+' } if (context.scmPosition.branch ==~ config.releaseBranchPattern) { return context.currentVersion.incrementPatchVersion() diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfig.groovy index e60fb3f0..fa99609b 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfig.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfig.groovy @@ -1,35 +1,98 @@ package pl.allegro.tech.build.axion.release.domain +import org.gradle.api.file.Directory +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputDirectory import org.gradle.api.tasks.Optional -class RepositoryConfig { +import javax.inject.Inject + +abstract class RepositoryConfig extends BaseExtension { + + private static final String CUSTOM_KEY_PROPERTY = 'release.customKey' + private static final String CUSTOM_KEY_FILE_PROPERTY = 'release.customKeyFile' + private static final String CUSTOM_KEY_PASSWORD_PROPERTY = 'release.customKeyPassword' + private static final String USERNAME_PROPERTY = 'release.customUsername' + private static final String PASSWORD_PROPERTY = 'release.customPassword' + private static final String RELEASE_PUSH_TAGS_ONLY_PROPERTY = 'release.pushTagsOnly' + private static final String ATTACH_REMOTE_PROPERTY = 'release.attachRemote' + private static final String OVERRIDDEN_BRANCH_NAME = 'release.overriddenBranchName' + private static final String DISABLE_SSH_AGENT = 'release.disableSshAgent' + private static final String FETCH_TAGS_PROPERTY = 'release.fetchTags' + + + @Inject + RepositoryConfig(Directory repositoryDirectory) { + pushTagsOnly.convention(false) + type.convention("git") + remote.convention("origin") + + customUsername.convention(gradleProperty(USERNAME_PROPERTY)) + customPassword.convention(gradleProperty(PASSWORD_PROPERTY)) + customKeyPassword.convention(gradleProperty(CUSTOM_KEY_PASSWORD_PROPERTY)) + customKey.convention(gradleProperty(CUSTOM_KEY_PROPERTY)) + customKeyFile.convention(gradleProperty(CUSTOM_KEY_FILE_PROPERTY) + .map({ layout.projectDirectory.file(it) })) + directory.convention(repositoryDirectory) + } @Input - String type = 'git' + @Optional + abstract Property getType() @InputDirectory - File directory + @Optional + abstract DirectoryProperty getDirectory() + + @Input + @Optional + abstract Property getRemote() @Input - String remote = 'origin' + @Optional + abstract Property getCustomKey() @Input @Optional - def customKey + abstract RegularFileProperty getCustomKeyFile() @Input @Optional - String customKeyPassword + abstract Property getCustomKeyPassword() @Input @Optional - String customUsername + abstract Property getCustomUsername() @Input - String customPassword = '' + @Optional + abstract Property getCustomPassword() @Input - boolean pushTagsOnly = false + @Optional + abstract Property getPushTagsOnly() + + Provider pushTagsOnly() { + gradlePropertyPresent(RELEASE_PUSH_TAGS_ONLY_PROPERTY).orElse(pushTagsOnly) + } + + Provider attachRemote() { + gradleProperty(ATTACH_REMOTE_PROPERTY) + } + + Provider overriddenBranch() { + gradleProperty(OVERRIDDEN_BRANCH_NAME) + } + + Provider disableSshAgent() { + gradlePropertyPresent(DISABLE_SSH_AGENT).orElse(false) + } + + Provider fetchTags() { + gradlePropertyPresent(FETCH_TAGS_PROPERTY).orElse(false) + } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfigFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfigFactory.groovy deleted file mode 100644 index 00ca141d..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfigFactory.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain - -import org.gradle.api.Project -import pl.allegro.tech.build.axion.release.util.FileLoader - -class RepositoryConfigFactory { - - private static final String CUSTOM_KEY_PROPERTY = 'release.customKey' - - private static final String CUSTOM_KEY_FILE_PROPERTY = 'release.customKeyFile' - - private static final String CUSTOM_KEY_PASSWORD_PROPERTY = 'release.customKeyPassword' - - private static final String USERNAME_PROPERTY = 'release.customUsername' - - private static final String PASSWORD_PROPERTY = 'release.customPassword' - - - static RepositoryConfig create(Project project) { - RepositoryConfig config = new RepositoryConfig() - config.directory = project.rootDir - - if (project.hasProperty(CUSTOM_KEY_PASSWORD_PROPERTY)) { - config.customKeyPassword = project.property(CUSTOM_KEY_PASSWORD_PROPERTY) - } - - if (project.hasProperty(CUSTOM_KEY_PROPERTY)) { - config.customKey = project.property(CUSTOM_KEY_PROPERTY) - } else if (project.hasProperty(CUSTOM_KEY_FILE_PROPERTY)) { - config.customKey = FileLoader.readFrom(project.property(CUSTOM_KEY_FILE_PROPERTY)) - } - - if(project.hasProperty(USERNAME_PROPERTY)) { - config.customUsername = project.property(USERNAME_PROPERTY) - } - if(project.hasProperty(PASSWORD_PROPERTY)) { - config.customPassword = project.property(PASSWORD_PROPERTY) - } - - return config - } -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/TagNameSerializationConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/TagNameSerializationConfig.groovy index ee5d4f9a..02181dd2 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/TagNameSerializationConfig.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/TagNameSerializationConfig.groovy @@ -1,37 +1,62 @@ package pl.allegro.tech.build.axion.release.domain +import org.gradle.api.provider.MapProperty +import org.gradle.api.provider.Property import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Nested +import org.gradle.api.tasks.Internal +import pl.allegro.tech.build.axion.release.TagPrefixConf import pl.allegro.tech.build.axion.release.domain.properties.TagProperties import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition -class TagNameSerializationConfig { +abstract class TagNameSerializationConfig extends BaseExtension { + + TagNameSerializationConfig() { + serialize.convention(TagNameSerializer.DEFAULT.serializer) + deserialize.convention(TagNameSerializer.DEFAULT.deserializer) + initialVersion.convention(defaultInitialVersion()) + prefix.convention(TagPrefixConf.defaultPrefix()) + versionSeparator.convention(TagPrefixConf.defaultSeparator()) + } @Input - String prefix + abstract Property getPrefix() @Input - Map branchPrefix = [:] + abstract MapProperty getBranchPrefix() @Input - String versionSeparator + abstract Property getVersionSeparator() + + @Internal + abstract Property getSerialize() + + @Internal + abstract Property getDeserialize() - @Nested - TagProperties.Serializer serialize = TagNameSerializer.DEFAULT.serializer + @Internal + abstract Property getInitialVersion() + @Deprecated void setSerializer(TagProperties.Serializer serializer) { - this.serialize = serializer + this.serialize.set(serializer) } - @Nested - TagProperties.Deserializer deserialize = TagNameSerializer.DEFAULT.deserializer + void serializer(TagProperties.Serializer serializer) { + this.serialize.set(serializer) + } + @Deprecated void setDeserializer(TagProperties.Deserializer deserializer) { - this.deserialize = deserializer + this.deserialize.set(deserializer) + } + + void deserializer(TagProperties.Deserializer deserializer) { + this.deserialize.set(deserializer) } - @Nested - TagProperties.InitialVersionSupplier initialVersion = defaultInitialVersion() + void initialVersion(TagProperties.InitialVersionSupplier versionSupplier){ + this.initialVersion.set(versionSupplier) + } private static TagProperties.InitialVersionSupplier defaultInitialVersion() { return { TagProperties rules, ScmPosition position -> diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy index b6fc2e13..2b863bc0 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy @@ -1,94 +1,149 @@ package pl.allegro.tech.build.axion.release.domain import org.gradle.api.Action -import org.gradle.api.Project +import org.gradle.api.file.Directory +import org.gradle.api.provider.MapProperty +import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Nested -import pl.allegro.tech.build.axion.release.ReleasePlugin +import org.gradle.api.tasks.Optional import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig -import pl.allegro.tech.build.axion.release.domain.properties.Properties import pl.allegro.tech.build.axion.release.domain.properties.VersionProperties -import pl.allegro.tech.build.axion.release.infrastructure.di.Context -import pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext -import pl.allegro.tech.build.axion.release.util.FileLoader +import pl.allegro.tech.build.axion.release.infrastructure.di.MemoizedVersionSupplier +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionSupplier import javax.inject.Inject import java.util.regex.Pattern -import static pl.allegro.tech.build.axion.release.TagPrefixConf.* +import static pl.allegro.tech.build.axion.release.TagPrefixConf.defaultPrefix -class VersionConfig { +abstract class VersionConfig extends BaseExtension { + private final VersionSupplier versionSupplier = new VersionSupplier() + private final MemoizedVersionSupplier cachedVersionSupplier = new MemoizedVersionSupplier() - private final Project project + private static final String DRY_RUN_FLAG = 'release.dryRun' + private static final String IGNORE_UNCOMMITTED_CHANGES_PROPERTY = 'release.ignoreUncommittedChanges' + private static final String FORCE_SNAPSHOT_PROPERTY = 'release.forceSnapshot' + private static final String USE_HIGHEST_VERSION_PROPERTY = 'release.useHighestVersion' + private static final String LOCAL_ONLY = "release.localOnly" + private static final String FORCE_VERSION_PROPERTY = 'release.version' + private static final String DEPRECATED_FORCE_VERSION_PROPERTY = 'release.forceVersion' + private static final String VERSION_INCREMENTER_PROPERTY = 'release.versionIncrementer' + private static final String VERSION_CREATOR_PROPERTY = 'release.versionCreator' - @Input - boolean localOnly = false - - @Input - boolean dryRun + @Inject + VersionConfig(Directory repositoryDirectory) { + getDryRun().convention(gradlePropertyPresent(DRY_RUN_FLAG).orElse(false)) + getLocalOnly().convention(false) + getIgnoreUncommittedChanges().convention(true) + getUseHighestVersion().convention(false) + getReleaseBranchPattern().convention(Pattern.compile('^' + defaultPrefix() + '(/.*)?$')) + getSanitizeVersion().convention(true) + getCreateReleaseCommit().convention(false) + getVersionCreator().convention(PredefinedVersionCreator.SIMPLE.versionCreator) + getVersionIncrementer().convention((VersionProperties.Incrementer) { VersionIncrementerContext context -> return context.currentVersion.incrementPatchVersion() }) + getSnapshotCreator().convention(PredefinedSnapshotCreator.SIMPLE.snapshotCreator) + getReleaseCommitMessage().convention(PredefinedReleaseCommitMessageCreator.DEFAULT.commitMessageCreator) + repository = objects.newInstance(RepositoryConfig, repositoryDirectory) + } - @Input - boolean ignoreUncommittedChanges = true + @Nested + final RepositoryConfig repository - @Input - boolean useHighestVersion = false + @Nested + final TagNameSerializationConfig tag = objects.newInstance(TagNameSerializationConfig) @Nested - RepositoryConfig repository + final ChecksConfig checks = objects.newInstance(ChecksConfig) @Nested - TagNameSerializationConfig tag = new TagNameSerializationConfig() + final NextVersionConfig nextVersion = objects.newInstance(NextVersionConfig) @Nested - VersionProperties.Creator versionCreator = PredefinedVersionCreator.SIMPLE.versionCreator + final HooksConfig hooks = objects.newInstance(HooksConfig) @Nested - VersionProperties.Creator snapshotCreator = PredefinedSnapshotCreator.SIMPLE.snapshotCreator + final MonorepoConfig monorepoConfig = objects.newInstance(MonorepoConfig) @Input - Map branchVersionCreator = [:] + @Optional + abstract Property getLocalOnly() - @Nested - VersionProperties.Incrementer versionIncrementer = { VersionIncrementerContext context -> return context.currentVersion.incrementPatchVersion() } + @Input + @Optional + abstract Property getDryRun() @Input - Map branchVersionIncrementer = [:] + @Optional + abstract Property getIgnoreUncommittedChanges() @Input - Pattern releaseBranchPattern = Pattern.compile('^'+ prefix() + '(/.*)?$') + @Optional + abstract Property getUseHighestVersion(); - @Nested - ChecksConfig checks = new ChecksConfig() + @Input + @Optional + abstract MapProperty getBranchVersionIncrementer(); @Input - boolean sanitizeVersion = true + @Optional + abstract Property getReleaseBranchPattern(); @Input - boolean createReleaseCommit = false + @Optional + abstract Property getSanitizeVersion() - @Nested - PredefinedReleaseCommitMessageCreator.CommitMessageCreator releaseCommitMessage = PredefinedReleaseCommitMessageCreator.DEFAULT.commitMessageCreator + @Input + @Optional + abstract Property getCreateReleaseCommit() - @Nested - NextVersionConfig nextVersion = new NextVersionConfig() + @Internal + abstract Property getVersionCreator() - @Nested - HooksConfig hooks = new HooksConfig() + @Internal + abstract Property getSnapshotCreator() - @Nested - MonorepoConfig monorepoConfig = new MonorepoConfig() + @Internal + abstract MapProperty getBranchVersionCreator() - private Context context + @Internal + abstract Property getVersionIncrementer() - private VersionService.DecoratedVersion resolvedVersion = null + @Internal + abstract Property getReleaseCommitMessage() - @Inject - VersionConfig(Project project) { - this.project = project - FileLoader.setRoot(project.rootDir) + Provider ignoreUncommittedChanges() { + gradlePropertyPresent(IGNORE_UNCOMMITTED_CHANGES_PROPERTY) + .orElse(ignoreUncommittedChanges) + } + + Provider forceSnapshot() { + gradlePropertyPresent(FORCE_SNAPSHOT_PROPERTY).orElse(false) + } + + Provider useHighestVersion() { + gradlePropertyPresent(USE_HIGHEST_VERSION_PROPERTY).orElse(useHighestVersion) + } - this.repository = RepositoryConfigFactory.create(project) - this.dryRun = project.hasProperty(ReleasePlugin.DRY_RUN_FLAG) + Provider localOnly() { + gradlePropertyPresent(LOCAL_ONLY).orElse(localOnly) + } + + Provider forcedVersion() { + gradleProperty(FORCE_VERSION_PROPERTY) + .orElse(gradleProperty(DEPRECATED_FORCE_VERSION_PROPERTY)) + .map({it.trim()}) + .map({ it.isBlank() ? null : it}) + } + + Provider versionIncrementerType() { + gradleProperty(VERSION_INCREMENTER_PROPERTY) + } + + Provider versionCreatorType() { + gradleProperty(VERSION_CREATOR_PROPERTY) } void repository(Action action) { @@ -111,129 +166,92 @@ class VersionConfig { action.execute(hooks) } + void monorepos(Action action) { + action.execute(monorepoConfig) + } + void versionCreator(String type) { - this.versionCreator = PredefinedVersionCreator.versionCreatorFor(type) + this.versionCreator.set(PredefinedVersionCreator.versionCreatorFor(type)) } @Deprecated void releaseCommitMessage(PredefinedReleaseCommitMessageCreator.CommitMessageCreator commitMessageCreator) { - this.releaseCommitMessage = commitMessageCreator + this.releaseCommitMessage.set(commitMessageCreator) } @Deprecated void createReleaseCommit(boolean createReleaseCommit) { - this.createReleaseCommit = createReleaseCommit + this.createReleaseCommit.set(createReleaseCommit) } void versionCreator(VersionProperties.Creator versionCreator) { - this.versionCreator = versionCreator + this.versionCreator.set(versionCreator) } void snapshotCreator(VersionProperties.Creator snapshotCreator) { - this.snapshotCreator = snapshotCreator + this.snapshotCreator.set(snapshotCreator) } void branchVersionCreator(Map creators) { - this.branchVersionCreator = creators + this.branchVersionCreator.putAll(creators) } void branchVersionCreators(Map creators) { - this.branchVersionCreator = creators + this.branchVersionCreator.putAll(creators) } void versionIncrementer(String ruleName) { - this.versionIncrementer = PredefinedVersionIncrementer.versionIncrementerFor(ruleName) + this.versionIncrementer.set(PredefinedVersionIncrementer.versionIncrementerFor(ruleName)) } void versionIncrementer(String ruleName, Map configuration) { - this.versionIncrementer = PredefinedVersionIncrementer.versionIncrementerFor(ruleName, configuration) + this.versionIncrementer.set(PredefinedVersionIncrementer.versionIncrementerFor(ruleName, configuration)) } void versionIncrementer(VersionProperties.Incrementer versionIncrementer) { - this.versionIncrementer = versionIncrementer + this.versionIncrementer.set(versionIncrementer) } void branchVersionIncrementer(Map creators) { - this.branchVersionIncrementer = creators - } - - @Input - String getVersion() { - ensureVersionExists() - return resolvedVersion.decoratedVersion + this.branchVersionIncrementer.putAll(creators) } - @Input - String getPreviousVersion() { - ensureVersionExists() - return resolvedVersion.previousVersion + Provider versionProvider() { + def cachedVersionSupplier = this.cachedVersionSupplier + providers.provider( { cachedVersionSupplier.resolve(this,layout.projectDirectory)}) } - @Input - String getUndecoratedVersion() { - ensureVersionExists() - return resolvedVersion.undecoratedVersion + Provider uncachedVersionProvider() { + def versionSupplier = this.versionSupplier + providers.provider( { versionSupplier.resolve(this, layout.projectDirectory)}) } - @Nested - VersionScmPosition getScmPosition() { - ensureVersionExists() - return new VersionScmPosition( - resolvedVersion.position.revision, - resolvedVersion.position.shortRevision, - resolvedVersion.position.branch - ) - } - - private void ensureVersionExists() { - if (resolvedVersion == null) { - resolvedVersion = getUncachedVersion() - } - } - - /** - * @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) + return uncachedVersionProvider().get() } - private static VersionService.DecoratedVersion getVersionFromContext(Context context) { - Properties rules = context.rules() - def versionService = context.versionService() - return versionService.currentDecoratedVersion(rules.version, rules.tag, rules.nextVersion) + @Input + String getVersion() { + return versionProvider().map({ it.decoratedVersion}).get() } - @Nested - VersionService getVersionService() { - ensureContextExists() - return context.versionService() + @Input + String getPreviousVersion() { + return versionProvider().map({ it.previousVersion}).get() } - private void ensureContextExists() { - if (context == null) { - this.context = GradleAwareContext.create(project, this) - } + @Input + String getUndecoratedVersion() { + return versionProvider().map({ it.undecoratedVersion}).get() } - void monorepos(Action action) { - action.execute(monorepoConfig) + @Nested + VersionScmPosition getScmPosition() { + return versionProvider().map({ new VersionScmPosition( + it.position.revision, + it.position.shortRevision, + it.position.branch + )}).get() } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/hooks/HooksConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/hooks/HooksConfig.groovy index 9610f918..b78a00ca 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/hooks/HooksConfig.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/hooks/HooksConfig.groovy @@ -1,16 +1,17 @@ package pl.allegro.tech.build.axion.release.domain.hooks +import org.gradle.api.provider.ListProperty +import org.gradle.api.tasks.Internal +import pl.allegro.tech.build.axion.release.domain.BaseExtension import pl.allegro.tech.build.axion.release.domain.hooks.ReleaseHookFactory.CustomAction -import org.gradle.api.tasks.Input +abstract class HooksConfig extends BaseExtension { -class HooksConfig { + @Internal + abstract ListProperty getPreReleaseHooks() - @Input - List preReleaseHooks = [] - - @Input - List postReleaseHooks = [] + @Internal + abstract ListProperty getPostReleaseHooks() void pre(ReleaseHookAction action) { pre({HookContext c -> action.act(c)}) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmChangesPrinter.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmChangesPrinter.groovy index 0729e246..4721074a 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmChangesPrinter.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmChangesPrinter.groovy @@ -1,7 +1,5 @@ package pl.allegro.tech.build.axion.release.domain.scm interface ScmChangesPrinter { - void printChanges() - } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy index 2b95d6a4..02346a64 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy @@ -1,6 +1,7 @@ package pl.allegro.tech.build.axion.release.infrastructure -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger +import org.slf4j.Logger +import org.slf4j.LoggerFactory import pl.allegro.tech.build.axion.release.domain.scm.ScmIdentity import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition import pl.allegro.tech.build.axion.release.domain.scm.ScmPushOptions @@ -12,7 +13,7 @@ import java.util.regex.Pattern class DummyRepository implements ScmRepository { - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(DummyRepository) + private static final Logger logger = LoggerFactory.getLogger(DummyRepository) DummyRepository() { } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DryRepository.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/NoOpRepository.groovy similarity index 82% rename from src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DryRepository.groovy rename to src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/NoOpRepository.groovy index 0e1b4fa6..9878c06d 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DryRepository.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/NoOpRepository.groovy @@ -1,22 +1,18 @@ package pl.allegro.tech.build.axion.release.infrastructure -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger -import pl.allegro.tech.build.axion.release.domain.scm.ScmIdentity -import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition -import pl.allegro.tech.build.axion.release.domain.scm.ScmPushOptions -import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult -import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository -import pl.allegro.tech.build.axion.release.domain.scm.TagsOnCommit +import org.gradle.api.logging.Logger +import org.gradle.api.logging.Logging +import pl.allegro.tech.build.axion.release.domain.scm.* import java.util.regex.Pattern -class DryRepository implements ScmRepository { +class NoOpRepository implements ScmRepository { - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(DryRepository) + private static final Logger logger = Logging.getLogger(NoOpRepository.class); private final ScmRepository delegateRepository - DryRepository(ScmRepository delegateRepository) { + NoOpRepository(ScmRepository delegateRepository) { this.delegateRepository = delegateRepository } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ChecksPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ChecksPropertiesFactory.groovy deleted file mode 100644 index deb0053e..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ChecksPropertiesFactory.groovy +++ /dev/null @@ -1,37 +0,0 @@ -package pl.allegro.tech.build.axion.release.infrastructure.config - -import org.gradle.api.Project -import pl.allegro.tech.build.axion.release.domain.ChecksConfig -import pl.allegro.tech.build.axion.release.domain.properties.ChecksProperties - -class ChecksPropertiesFactory { - - private static final String DISABLE_UNCOMMITTED_CHANGES_CHECK = "release.disableUncommittedCheck" - - private static final String DISABLE_AHEAD_OF_REMOTE_CHECK = "release.disableRemoteCheck" - - private static final String DISABLE_SNAPSHOT_DEPENDENCIES_CHECK = "release.disableSnapshotsCheck" - - private static final String DISABLE_CHECKS = "release.disableChecks" - - static ChecksProperties create(Project project, ChecksConfig config) { - return new ChecksProperties( - checkUncommittedChanges(project, config), - checkAheadOfRemote(project, config), - checkSnapshotDependencies(project, config) - ) - } - - private static boolean checkUncommittedChanges(Project project, ChecksConfig config) { - return project.hasProperty(DISABLE_CHECKS) || project.hasProperty(DISABLE_UNCOMMITTED_CHANGES_CHECK) ? false : config.uncommittedChanges - } - - private static boolean checkAheadOfRemote(Project project, ChecksConfig config) { - return project.hasProperty(DISABLE_CHECKS) || project.hasProperty(DISABLE_AHEAD_OF_REMOTE_CHECK) ? false : config.aheadOfRemote - } - - private static boolean checkSnapshotDependencies(Project project, ChecksConfig config) { - return project.hasProperty(DISABLE_CHECKS) || project.hasProperty(DISABLE_SNAPSHOT_DEPENDENCIES_CHECK) ? false : config.snapshotDependencies - } - -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/HooksPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/HooksPropertiesFactory.groovy index 7a5da47b..54ef9930 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/HooksPropertiesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/HooksPropertiesFactory.groovy @@ -7,11 +7,10 @@ import pl.allegro.tech.build.axion.release.domain.properties.HooksProperties class HooksPropertiesFactory { static HooksProperties create(VersionConfig versionConfig, HooksConfig config) { - if(versionConfig.createReleaseCommit) { - versionConfig.hooks.pre('commit', versionConfig.releaseCommitMessage) + if(versionConfig.createReleaseCommit.get()) { + versionConfig.hooks.pre('commit', versionConfig.releaseCommitMessage.get()) } - return new HooksProperties(config.preReleaseHooks, config.postReleaseHooks) + return new HooksProperties(config.preReleaseHooks.get(), config.postReleaseHooks.get()) } - } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactory.groovy index 50eedb55..202c5c70 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactory.groovy @@ -1,16 +1,11 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project + import pl.allegro.tech.build.axion.release.domain.LocalOnlyResolver import pl.allegro.tech.build.axion.release.domain.VersionConfig class LocalOnlyResolverFactory { - - private static final String LOCAL_ONLY = "release.localOnly" - - static LocalOnlyResolver create(Project project, VersionConfig config) { - boolean baseValue = project.hasProperty(LOCAL_ONLY) || config.localOnly - return new LocalOnlyResolver(baseValue) + static LocalOnlyResolver create(VersionConfig config) { + return new LocalOnlyResolver(config.localOnly().get()) } - } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/NextVersionPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/NextVersionPropertiesFactory.groovy deleted file mode 100644 index caa18356..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/NextVersionPropertiesFactory.groovy +++ /dev/null @@ -1,39 +0,0 @@ -package pl.allegro.tech.build.axion.release.infrastructure.config - -import org.gradle.api.Project -import pl.allegro.tech.build.axion.release.domain.NextVersionConfig -import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties - -class NextVersionPropertiesFactory { - - private static final String NEXT_VERSION_PROPERTY = "release.version" - - private static final String NEXT_VERSION_INCREMENTER_PROPERTY = "release.incrementer" - - private static final String DEPRECATED_NEXT_VERSION_PROPERTY = "release.nextVersion" - - static NextVersionProperties create(Project project, NextVersionConfig config) { - if (config.suffix == null || config.suffix.isEmpty()) { - String message = "scmVersion.nextVersion.suffix can't be empty! Empty suffix will prevent axion-release from distinguishing nextVersion from regular versions"; - project.logger.error(message) - throw new IllegalArgumentException(message) - } - - String nextVersion = project.hasProperty(NEXT_VERSION_PROPERTY) ? project.property(NEXT_VERSION_PROPERTY) : null - String versionIncrementerName = project.hasProperty(NEXT_VERSION_INCREMENTER_PROPERTY) ? project.property(NEXT_VERSION_INCREMENTER_PROPERTY) : null - - if (nextVersion == null && project.hasProperty(DEPRECATED_NEXT_VERSION_PROPERTY)) { - project.logger.warn("Using deprecated parameter: $DEPRECATED_NEXT_VERSION_PROPERTY! Use $NEXT_VERSION_PROPERTY instead.") - nextVersion = project.property(DEPRECATED_NEXT_VERSION_PROPERTY) - } - - return new NextVersionProperties( - nextVersion, - config.suffix, - config.separator, - versionIncrementerName, - config.serializer, - config.deserializer) - } - -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy index 7a1b6999..57d0f888 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy @@ -1,8 +1,7 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project + import pl.allegro.tech.build.axion.release.TagPrefixConf -import pl.allegro.tech.build.axion.release.ReleasePlugin import pl.allegro.tech.build.axion.release.domain.TagNameSerializationConfig import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.properties.Properties @@ -11,18 +10,17 @@ import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository class RulesFactory { - static Properties create(Project project, VersionConfig versionConfig, ScmRepository repository) { + static Properties create(VersionConfig versionConfig, ScmRepository repository) { ScmPosition position = repository.currentPosition() setDefaultPrefix(versionConfig.tag, repository) - return new Properties( - project.hasProperty(ReleasePlugin.DRY_RUN_FLAG), - VersionPropertiesFactory.create(project, versionConfig, position.branch), + versionConfig.dryRun.get(), + VersionPropertiesFactory.create(versionConfig, position.branch), TagPropertiesFactory.create(versionConfig.tag, position.branch), - ChecksPropertiesFactory.create(project, versionConfig.checks), - NextVersionPropertiesFactory.create(project, versionConfig.nextVersion), + versionConfig.checks, + versionConfig.nextVersion.nextVersionProperties(), HooksPropertiesFactory.create(versionConfig, versionConfig.hooks) ) } @@ -34,10 +32,10 @@ class RulesFactory { tag.setVersionSeparator(TagPrefixConf.DEFAULT_LEGACY_SEP) } else { if (tag.getPrefix() == null) { - tag.setPrefix(TagPrefixConf.prefix()) + tag.setPrefix(TagPrefixConf.defaultPrefix()) } if (tag.getVersionSeparator() == null) { - tag.setVersionSeparator(TagPrefixConf.separator()) + tag.setVersionSeparator(TagPrefixConf.defaultSeparator()) } } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactory.groovy index cf088a30..53bb2e36 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactory.groovy @@ -7,16 +7,22 @@ import pl.allegro.tech.build.axion.release.util.FileLoader class ScmIdentityFactory { static ScmIdentity create(RepositoryConfig config, boolean disableSshAgent) { - ScmIdentity identity - if (config.customKey) { - identity = ScmIdentity.keyIdentity(FileLoader.readIfFile(config.customKey), config.customKeyPassword) - } else if (config.customUsername) { - identity = ScmIdentity.usernameIdentity(config.customUsername, config.customPassword) - } else if (disableSshAgent) { - identity = ScmIdentity.defaultIdentityWithoutAgents() - } else { - identity = ScmIdentity.defaultIdentity() + if (config.customKey.isPresent()) { + return ScmIdentity.keyIdentity(config.customKey.get(), config.customKeyPassword.get()) } - return identity + + if (config.customKeyFile.isPresent()) { + return ScmIdentity.keyIdentity(FileLoader.readFrom(config.customKeyFile.get().asFile), config.customKeyPassword.get()) + } + + if (config.customUsername.isPresent()) { + return ScmIdentity.usernameIdentity(config.customUsername.get(), config.customPassword.get()) + } + + if (disableSshAgent) { + return ScmIdentity.defaultIdentityWithoutAgents() + } + + return ScmIdentity.defaultIdentity() } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy index 595e95f4..1b3e595d 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactory.groovy @@ -1,33 +1,21 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project + import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties class ScmPropertiesFactory { - - private static final String ATTACH_REMOTE_PROPERTY = 'release.attachRemote' - - private static final String FETCH_TAGS_PROPERTY = 'release.fetchTags' - - private static final String RELEASE_PUSH_TAGS_ONLY_PROPERTY = 'release.pushTagsOnly' - - private static final String DISABLE_SSH_AGENT = 'release.disableSshAgent' - - private static final String OVERRIDDEN_BRANCH_NAME = 'release.overriddenBranchName' - - static ScmProperties create(Project project, VersionConfig config) { + static ScmProperties create(VersionConfig config) { return new ScmProperties( - config.repository.type, - config.repository.directory, - config.repository.remote, - (boolean) project.hasProperty(RELEASE_PUSH_TAGS_ONLY_PROPERTY) ? true : config.repository.pushTagsOnly, - project.hasProperty(FETCH_TAGS_PROPERTY), - project.hasProperty(ATTACH_REMOTE_PROPERTY), - (String) (project.hasProperty(ATTACH_REMOTE_PROPERTY) ? project.property(ATTACH_REMOTE_PROPERTY) : null), - (String) (project.hasProperty(OVERRIDDEN_BRANCH_NAME) ? project.property(OVERRIDDEN_BRANCH_NAME) : null), - ScmIdentityFactory.create(config.repository, project.hasProperty(DISABLE_SSH_AGENT)) + config.repository.type.get(), + config.repository.directory.asFile.get(), + config.repository.remote.get(), + config.repository.pushTagsOnly().get(), + config.repository.fetchTags().get(), + config.repository.attachRemote().isPresent(), + config.repository.attachRemote().getOrNull(), + config.repository.overriddenBranch().getOrNull(), + ScmIdentityFactory.create(config.repository, config.repository.disableSshAgent().get()) ) } - } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactory.groovy index d34c0947..dce937a7 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactory.groovy @@ -10,19 +10,18 @@ class TagPropertiesFactory { static TagProperties create(TagNameSerializationConfig config, String currentBranch) { return new TagProperties( findPrefix(config, currentBranch), - config.versionSeparator, - config.serialize, - config.deserialize, - config.initialVersion + config.versionSeparator.get(), + config.serialize.get(), + config.deserialize.get(), + config.initialVersion.get() ) } private static String findPrefix(TagNameSerializationConfig config, String currentBranch) { - String prefix = config.branchPrefix.findResult { pattern, prefix -> + String prefix = config.branchPrefix.get().findResult { pattern, prefix -> Pattern.compile(pattern).matcher(currentBranch).matches() ? prefix : null } - return prefix ?: config.prefix + return prefix ?: config.prefix.get() } - } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactory.groovy index a5382d76..9522eb26 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactory.groovy @@ -1,6 +1,6 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project + import pl.allegro.tech.build.axion.release.domain.PredefinedVersionCreator import pl.allegro.tech.build.axion.release.domain.PredefinedVersionIncrementer import pl.allegro.tech.build.axion.release.domain.VersionConfig @@ -11,53 +11,29 @@ import java.util.regex.Pattern class VersionPropertiesFactory { - private static final String DEPRECATED_FORCE_VERSION_PROPERTY = 'release.forceVersion' - - private static final String FORCE_VERSION_PROPERTY = 'release.version' - - private static final String IGNORE_UNCOMMITTED_CHANGES_PROPERTY = 'release.ignoreUncommittedChanges' - - private static final String FORCE_SNAPSHOT_PROPERTY = 'release.forceSnapshot' - - private static final String USE_HIGHEST_VERSION_PROPERTY = 'release.useHighestVersion' - - private static final String VERSION_INCREMENTER_PROPERTY = 'release.versionIncrementer' - - private static final String VERSION_CREATOR_PROPERTY = 'release.versionCreator' - - static VersionProperties create(Project project, VersionConfig config, String currentBranch) { - String forceVersionValue = project.hasProperty(FORCE_VERSION_PROPERTY) ? project.property(FORCE_VERSION_PROPERTY) : null - if (forceVersionValue == null) { - forceVersionValue = project.hasProperty(DEPRECATED_FORCE_VERSION_PROPERTY) ? project.property(DEPRECATED_FORCE_VERSION_PROPERTY) : null - } - - boolean ignoreUncommittedChanges = project.hasProperty(IGNORE_UNCOMMITTED_CHANGES_PROPERTY) ?: config.ignoreUncommittedChanges - boolean forceSnapshot = project.hasProperty(FORCE_SNAPSHOT_PROPERTY) - - boolean useHighestVersion = project.hasProperty(USE_HIGHEST_VERSION_PROPERTY) ?: config.useHighestVersion - + static VersionProperties create(VersionConfig config, String currentBranch) { return new VersionProperties( - forceVersionValue?.trim() ? forceVersionValue.trim() : null, - forceSnapshot, - ignoreUncommittedChanges, - findVersionCreator(project, config, currentBranch), - config.snapshotCreator, - findVersionIncrementer(project, config, currentBranch), - config.sanitizeVersion, - useHighestVersion, - MonorepoPropertiesFactory.create(project, config.monorepoConfig, currentBranch) + config.forcedVersion().getOrNull(), + config.forceSnapshot().get(), + config.ignoreUncommittedChanges().get(), + findVersionCreator(config, currentBranch), + config.snapshotCreator.get(), + findVersionIncrementer(config, currentBranch), + config.sanitizeVersion.get(), + config.useHighestVersion().get(), + config.monorepoConfig ) } - private static VersionProperties.Incrementer findVersionIncrementer(Project project, VersionConfig config, String currentBranch) { - if (project.hasProperty(VERSION_INCREMENTER_PROPERTY)) { - return PredefinedVersionIncrementer.versionIncrementerFor(project.property(VERSION_INCREMENTER_PROPERTY), [:]) + private static VersionProperties.Incrementer findVersionIncrementer(VersionConfig config, String currentBranch) { + if( config.versionIncrementerType().isPresent()) { + return PredefinedVersionIncrementer.versionIncrementerFor(config.versionIncrementerType().get(), [:]) } return findVersionIncrementer( currentBranch, - config.branchVersionIncrementer, - { VersionIncrementerContext a -> config.versionIncrementer.apply(a) }, + config.branchVersionIncrementer.get(), + { VersionIncrementerContext a -> config.versionIncrementer.get().apply(a) }, { v -> if (v instanceof List) { return PredefinedVersionIncrementer.versionIncrementerFor(v[0], v[1]) @@ -67,24 +43,24 @@ class VersionPropertiesFactory { ) } - private static VersionProperties.Creator findVersionCreator(Project project, VersionConfig config, String currentBranch) { - if (project.hasProperty(VERSION_CREATOR_PROPERTY)) { - return PredefinedVersionCreator.versionCreatorFor(project.property(VERSION_CREATOR_PROPERTY)) + private static VersionProperties.Creator findVersionCreator(VersionConfig config, String currentBranch) { + if (config.versionCreatorType().isPresent()) { + return PredefinedVersionCreator.versionCreatorFor(config.versionCreatorType().get()) } return find( currentBranch, - config.branchVersionCreator, - config.versionCreator, + config.branchVersionCreator.get(), + config.versionCreator.get(), { String s -> PredefinedVersionCreator.versionCreatorFor(s) } ) } private static VersionProperties.Incrementer findVersionIncrementer(String currentBranch, - Map collection, - VersionProperties.Incrementer defaultValue, - Closure converter) { + Map collection, + VersionProperties.Incrementer defaultValue, + Closure converter) { Object value = collection?.findResult { pattern, value -> Pattern.matches(pattern, currentBranch) ? value : null } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/GradleAwareContext.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/GradleAwareContext.groovy deleted file mode 100644 index b209fa6a..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/GradleAwareContext.groovy +++ /dev/null @@ -1,34 +0,0 @@ -package pl.allegro.tech.build.axion.release.infrastructure.di - -import org.gradle.api.Project -import pl.allegro.tech.build.axion.release.domain.VersionConfig -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.config.LocalOnlyResolverFactory -import pl.allegro.tech.build.axion.release.infrastructure.config.RulesFactory -import pl.allegro.tech.build.axion.release.infrastructure.config.ScmPropertiesFactory - -class GradleAwareContext { - - static Context create(Project project, VersionConfig versionConfig) { - ScmProperties scmProperties = ScmPropertiesFactory.create(project, versionConfig) - ScmRepository scmRepository = ScmRepositoryFactory.create(scmProperties) - - return new Context( - RulesFactory.create(project, versionConfig, scmRepository), - scmRepository, - scmProperties, - project.projectDir, - LocalOnlyResolverFactory.create(project, versionConfig) - ) - } - - static VersionConfig configOrCreateFromProject(Project project, VersionConfig versionConfig) { - return versionConfig == null ? config(project) : versionConfig - } - - static VersionConfig config(Project project) { - return project.extensions.getByType(VersionConfig) - } - -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactory.groovy index 5c74a9eb..ea53d54c 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactory.groovy @@ -1,6 +1,7 @@ package pl.allegro.tech.build.axion.release.infrastructure.di -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger +import org.gradle.api.logging.Logger +import org.gradle.api.logging.Logging 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.domain.scm.ScmRepositoryUnavailableException @@ -8,8 +9,7 @@ import pl.allegro.tech.build.axion.release.infrastructure.DummyRepository import pl.allegro.tech.build.axion.release.infrastructure.git.GitRepository class ScmRepositoryFactory { - - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(ScmRepositoryFactory) + private static final Logger logger = Logging.getLogger(ScmRepositoryFactory.class); private static final String GIT = 'git' diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/Context.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy similarity index 51% rename from src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/Context.groovy rename to src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy index d5c6ecae..a35c4506 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/Context.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionResolutionContext.groovy @@ -1,5 +1,6 @@ package pl.allegro.tech.build.axion.release.infrastructure.di +import org.gradle.api.file.Directory import pl.allegro.tech.build.axion.release.domain.* import pl.allegro.tech.build.axion.release.domain.hooks.ReleaseHooksRunner import pl.allegro.tech.build.axion.release.domain.properties.Properties @@ -7,13 +8,14 @@ import pl.allegro.tech.build.axion.release.domain.scm.ScmChangesPrinter 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.domain.scm.ScmService -import pl.allegro.tech.build.axion.release.infrastructure.DryRepository +import pl.allegro.tech.build.axion.release.infrastructure.NoOpRepository +import pl.allegro.tech.build.axion.release.infrastructure.config.LocalOnlyResolverFactory +import pl.allegro.tech.build.axion.release.infrastructure.config.RulesFactory +import pl.allegro.tech.build.axion.release.infrastructure.config.ScmPropertiesFactory import pl.allegro.tech.build.axion.release.infrastructure.git.GitChangesPrinter import pl.allegro.tech.build.axion.release.infrastructure.git.GitRepository -class Context { - - private final Map instances = [:] +class VersionResolutionContext { private final Properties rules @@ -23,18 +25,30 @@ class Context { private final LocalOnlyResolver localOnlyResolver - Context(Properties rules, ScmRepository scmRepository, ScmProperties scmProperties, File projectRoot, LocalOnlyResolver localOnlyResolver) { + private final VersionService versionService + + private VersionResolutionContext(Properties rules, ScmRepository scmRepository, + ScmProperties scmProperties, File projectRoot, + LocalOnlyResolver localOnlyResolver) { this.rules = rules this.scmRepository = scmRepository this.scmProperties = scmProperties this.localOnlyResolver = localOnlyResolver - - instances[ScmRepository] = scmRepository - instances[VersionService] = new VersionService(new VersionResolver(scmRepository, scmProperties.directory.toPath().relativize(projectRoot.toPath()).toString())) + this.versionService = new VersionService(new VersionResolver(scmRepository, + scmProperties.directory.toPath().relativize(projectRoot.toPath()).toString())) } - private T get(Class clazz) { - return (T) instances[clazz] + static VersionResolutionContext create(VersionConfig versionConfig, Directory projectDirectory) { + ScmProperties scmProperties = ScmPropertiesFactory.create(versionConfig) + ScmRepository scmRepository = ScmRepositoryFactory.create(scmProperties) + + return new VersionResolutionContext( + RulesFactory.create(versionConfig, scmRepository), + scmRepository, + scmProperties, + projectDirectory.asFile, + LocalOnlyResolverFactory.create(versionConfig) + ) } Properties rules() { @@ -42,7 +56,7 @@ class Context { } ScmRepository repository() { - return rules.dryRun ? new DryRepository(get(ScmRepository)) : get(ScmRepository) + return rules.dryRun ? new NoOpRepository(scmRepository) : scmRepository } ScmService scmService() { @@ -54,7 +68,7 @@ class Context { } VersionService versionService() { - return get(VersionService) + return versionService } Releaser releaser() { @@ -66,6 +80,6 @@ class Context { } ScmChangesPrinter changesPrinter() { - return new GitChangesPrinter(get(ScmRepository) as GitRepository) + return new GitChangesPrinter(scmRepository as GitRepository) } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionSupplier.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionSupplier.groovy new file mode 100644 index 00000000..562124af --- /dev/null +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/VersionSupplier.groovy @@ -0,0 +1,28 @@ +package pl.allegro.tech.build.axion.release.infrastructure.di + +import org.gradle.api.file.Directory +import pl.allegro.tech.build.axion.release.domain.VersionConfig +import pl.allegro.tech.build.axion.release.domain.VersionService +import pl.allegro.tech.build.axion.release.domain.properties.Properties + +class VersionSupplier { + VersionService.DecoratedVersion resolve(VersionConfig config, Directory projectDirectory) { + def context = VersionResolutionContext.create(config, projectDirectory) + Properties rules = context.rules() + def versionService = context.versionService() + return versionService.currentDecoratedVersion(rules.version, rules.tag, rules.nextVersion) + } +} + +class MemoizedVersionSupplier { + private VersionService.DecoratedVersion version + private final VersionSupplier versionSupplier = new VersionSupplier() + + VersionService.DecoratedVersion resolve(VersionConfig config, Directory projectDirectory) { + if(version != null) { + return version + } + version = versionSupplier.resolve(config, projectDirectory) + return version + } +} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/output/OutputWriter.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/output/OutputWriter.groovy index 3974ec40..362fbd38 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/output/OutputWriter.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/output/OutputWriter.groovy @@ -1,10 +1,10 @@ package pl.allegro.tech.build.axion.release.infrastructure.output -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger +import org.gradle.api.logging.Logger +import org.gradle.api.logging.Logging class OutputWriter { - - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(OutputWriter) + private static final Logger logger = Logging.getLogger(OutputWriter.class); void println(String text) { logger.quiet(text) diff --git a/src/main/java/pl/allegro/tech/build/axion/release/TagPrefixConf.java b/src/main/java/pl/allegro/tech/build/axion/release/TagPrefixConf.java index 5e36315e..808cae13 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/TagPrefixConf.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/TagPrefixConf.java @@ -4,28 +4,21 @@ public final class TagPrefixConf { private TagPrefixConf() { } - private static String defaultPrefix = "v"; - private static String defaultSeparator = ""; + private static final String DEFAULT_PREFIX = "v"; + private static final String DEFAULT_SEPARATOR = ""; public final static String DEFAULT_LEGACY_PREFIX = "release"; public final static String DEFAULT_LEGACY_SEP = "-"; - public static String prefix() { - return defaultPrefix; + public static String defaultPrefix() { + return DEFAULT_PREFIX; } - public static void setDefPrefix(String prefix) { - defaultPrefix = prefix; - } - public static void setDefSeparator(String sep) { - defaultSeparator = sep; - } - - public static String separator() { - return defaultSeparator; + public static String defaultSeparator() { + return DEFAULT_SEPARATOR; } public static String fullPrefix() { - return defaultPrefix + defaultSeparator; + return DEFAULT_PREFIX + DEFAULT_SEPARATOR; } public static String fullLegacyPrefix() { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java index efb469af..015c3a37 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java @@ -1,38 +1,55 @@ package pl.allegro.tech.build.axion.release.domain; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; import org.gradle.api.tasks.Input; -public class ChecksConfig { +import javax.inject.Inject; + +@SuppressWarnings("UnstableApiUsage") +public abstract class ChecksConfig extends BaseExtension { + + private static final String DISABLE_UNCOMMITTED_CHANGES_CHECK = "release.disableUncommittedCheck"; + private static final String DISABLE_AHEAD_OF_REMOTE_CHECK = "release.disableRemoteCheck"; + private static final String DISABLE_SNAPSHOT_DEPENDENCIES_CHECK = "release.disableSnapshotsCheck"; + private static final String DISABLE_CHECKS = "release.disableChecks"; + @Input - private boolean aheadOfRemote = true; + public abstract Property getAheadOfRemote(); @Input - private boolean uncommittedChanges = true; + public abstract Property getUncommittedChanges(); @Input - private boolean snapshotDependencies = true; + public abstract Property getSnapshotDependencies(); - public void setAheadOfRemote(boolean aheadOfRemote) { - this.aheadOfRemote = aheadOfRemote; + @Inject + public ChecksConfig() { + getAheadOfRemote().convention(true); + getUncommittedChanges().convention(true); + getSnapshotDependencies().convention(true); } - public void setUncommittedChanges(boolean uncommittedChanges) { - this.uncommittedChanges = uncommittedChanges; + public Provider checkUncommittedChanges() { + return enabled(DISABLE_UNCOMMITTED_CHANGES_CHECK) + .orElse(getUncommittedChanges()); } - public void setSnapshotDependencies(boolean snapshotDependencies) { - this.snapshotDependencies = snapshotDependencies; + public Provider checkAheadOfRemote() { + return enabled(DISABLE_AHEAD_OF_REMOTE_CHECK) + .orElse(getAheadOfRemote()); } - public boolean isAheadOfRemote() { - return aheadOfRemote; + public Provider checkSnapshotDependencies() { + return enabled(DISABLE_SNAPSHOT_DEPENDENCIES_CHECK) + .orElse(getSnapshotDependencies()); } - public boolean isUncommittedChanges() { - return uncommittedChanges; + private Provider enabled(String property) { + // if either property is present this feature isn't enabled + return gradlePropertyPresent(DISABLE_CHECKS) + .orElse(gradlePropertyPresent(property)) + .map(it -> false); } - public boolean isSnapshotDependencies() { - return snapshotDependencies; - } } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/LocalOnlyResolver.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/LocalOnlyResolver.java index 27b931cd..df36f06e 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/LocalOnlyResolver.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/LocalOnlyResolver.java @@ -4,8 +4,8 @@ public class LocalOnlyResolver { private final boolean localOnly; - public LocalOnlyResolver(boolean baseValue) { - this.localOnly = baseValue; + public LocalOnlyResolver(boolean localOnly) { + this.localOnly = localOnly; } public boolean localOnly(boolean remoteAttached) { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java index cf34edd3..030aa3c5 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java @@ -1,19 +1,24 @@ package pl.allegro.tech.build.axion.release.domain; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Internal; import java.util.LinkedList; import java.util.List; -public class MonorepoConfig { +public abstract class MonorepoConfig extends BaseExtension { + @Input + public abstract ListProperty getProjectDirs(); + @Internal - private List projectDirs = new LinkedList<>(); + public ListProperty getExcludeDirs() { return getProjectDirs(); } - public List getProjectDirs() { - return projectDirs; + public void exclude(String dir) { + getProjectDirs().add(dir); } - public void setProjectDirs(List projectDirs) { - this.projectDirs = projectDirs; + public void exclude(List dirs) { + getProjectDirs().addAll(dirs); } } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java index 9ed76511..6a57c863 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java @@ -1,59 +1,87 @@ package pl.allegro.tech.build.axion.release.domain; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; +import org.gradle.api.provider.ProviderFactory; import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.Nested; +import org.gradle.api.tasks.Internal; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties; import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties.*; -public class NextVersionConfig { - @Input - private String suffix = "alpha"; +import javax.inject.Inject; + +@SuppressWarnings("UnstableApiUsage") +public abstract class NextVersionConfig extends BaseExtension { + private static final Logger logger = LoggerFactory.getLogger(NextVersionConfig.class); + + private static final String NEXT_VERSION_INCREMENTER_PROPERTY = "release.incrementer"; + private static final String NEXT_VERSION_PROPERTY = "release.version"; + private static final String DEPRECATED_NEXT_VERSION_PROPERTY = "release.nextVersion"; + + @Inject + public NextVersionConfig() { + getSuffix().convention("alpha"); + getSeparator().convention("-"); + getSerializer().convention(NextVersionSerializer.DEFAULT.serializer); + getDeserializer().convention(NextVersionSerializer.DEFAULT.deserializer); + } @Input - private String separator = "-"; + public abstract Property getSuffix(); - @Nested - private Serializer serializer = NextVersionSerializer.DEFAULT.serializer; + @Input + public abstract Property getSeparator(); - @Nested - private Deserializer deserializer = NextVersionSerializer.DEFAULT.deserializer; + @Internal + public abstract Property getSerializer(); - public void setSerializer(String type) { - this.serializer = NextVersionSerializer.find(type).serializer; - } + @Internal + public abstract Property getDeserializer(); - public void setSerializer(Serializer c) { - this.serializer = c; + public void serializer(String type) { + getSerializer().set(NextVersionSerializer.find(type).serializer); } - public void setDeserializer(String type) { - this.deserializer = NextVersionSerializer.valueOf(type).deserializer; + public void deserializer(String type) { + getDeserializer().set(NextVersionSerializer.valueOf(type).deserializer); } - public void setDeserializer(Deserializer c) { - this.deserializer = c; + public void serializer(Serializer serializer) { + getSerializer().set(serializer); } - public String getSuffix() { - return suffix; + public void deserializer(Deserializer deserializer) { + getDeserializer().set(deserializer); } - public void setSuffix(String suffix) { - this.suffix = suffix; - } + public NextVersionProperties nextVersionProperties() { - public String getSeparator() { - return separator; - } + if (getSuffix().get().isEmpty()) { + String message = "scmVersion.nextVersion.suffix can't be empty! Empty suffix will prevent axion-release from distinguishing nextVersion from regular versions"; + throw new IllegalArgumentException(message); + } - public void setSeparator(String separator) { - this.separator = separator; + return new NextVersionProperties(nextVersion().getOrNull(), + getSuffix().get(), + getSeparator().get(), + versionIncrementerName().getOrNull(), + getSerializer().get(), + getDeserializer().get() + ); } - public Serializer getSerializer() { - return serializer; + private Provider versionIncrementerName() { + return gradleProperty(NEXT_VERSION_INCREMENTER_PROPERTY); } - public Deserializer getDeserializer() { - return deserializer; + private Provider nextVersion() { + return gradleProperty(NEXT_VERSION_PROPERTY) + .orElse(gradleProperty(DEPRECATED_NEXT_VERSION_PROPERTY) + .map(it -> { + logger.warn("Using deprecated property: " + DEPRECATED_NEXT_VERSION_PROPERTY + "! Use " + NEXT_VERSION_PROPERTY + " instead."); + return it; + })); } } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/Releaser.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/Releaser.java index ef134aad..5fc78d94 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/Releaser.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/Releaser.java @@ -1,8 +1,9 @@ package pl.allegro.tech.build.axion.release.domain; import com.github.zafarkhaja.semver.Version; +import org.gradle.api.logging.Logger; +import org.gradle.api.logging.Logging; import pl.allegro.tech.build.axion.release.domain.hooks.ReleaseHooksRunner; -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger; import pl.allegro.tech.build.axion.release.domain.properties.Properties; import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult; import pl.allegro.tech.build.axion.release.domain.scm.ScmService; @@ -11,7 +12,7 @@ public class Releaser { - private final ReleaseLogger logger = ReleaseLogger.Factory.logger(Releaser.class); + private static final Logger logger = Logging.getLogger(Releaser.class); private final VersionService versionService; private final ScmService repository; private final ReleaseHooksRunner hooksRunner; diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java index 6be82989..738b5ab1 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java @@ -38,7 +38,7 @@ public VersionResolver(ScmRepository repository, String projectRootRelativePath) public VersionContext resolveVersion(VersionProperties versionProperties, TagProperties tagProperties, NextVersionProperties nextVersionProperties) { ScmPosition latestChangePosition = repository.positionOfLastChangeIn( - projectRootRelativePath, versionProperties.getMonorepoProperties().getDirsToExclude() + projectRootRelativePath, versionProperties.getMonorepoConfig().getProjectDirs().get() ); VersionFactory versionFactory = new VersionFactory(versionProperties, tagProperties, nextVersionProperties, latestChangePosition, repository.isLegacyDefTagnameRepo()); @@ -104,7 +104,6 @@ private VersionInfo readVersions( onLatestVersion = repository.isIdenticalForPath(projectRootRelativePath, latestChangePosition.getRevision(),tagCommitRevision); } - return new VersionInfo( currentVersion, previousVersion, diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionService.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionService.java index 9e7fe183..abd44517 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionService.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/VersionService.java @@ -36,13 +36,11 @@ public DecoratedVersion currentDecoratedVersion(VersionProperties versionPropert finalVersion = finalVersion + versionProperties.getSnapshotCreator().apply(version, versionContext.getPosition()); } - return new DecoratedVersion(versionContext.getVersion().toString(), finalVersion, versionContext.getPosition(), versionContext.getPreviousVersion().toString()); } public static class DecoratedVersion { - private final String undecoratedVersion; private final String decoratedVersion; private final ScmPosition position; diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/hooks/HookContext.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/hooks/HookContext.java index cd3315f6..61f9da6e 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/hooks/HookContext.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/hooks/HookContext.java @@ -1,8 +1,9 @@ package pl.allegro.tech.build.axion.release.domain.hooks; import com.github.zafarkhaja.semver.Version; +import org.gradle.api.logging.Logger; +import org.gradle.api.logging.Logging; import pl.allegro.tech.build.axion.release.domain.VersionService; -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger; import pl.allegro.tech.build.axion.release.domain.properties.Properties; import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition; import pl.allegro.tech.build.axion.release.domain.scm.ScmService; @@ -12,8 +13,7 @@ import java.util.List; public class HookContext { - - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(HookContext.class); + private static final Logger logger = Logging.getLogger(HookContext.class); private final VersionService versionService; private final ScmService scmService; @@ -77,7 +77,7 @@ public void push() { scmService.push(); } - public static ReleaseLogger getLogger() { + public static Logger getLogger() { return logger; } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/DefaultReleaseLoggerFactory.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/DefaultReleaseLoggerFactory.java deleted file mode 100644 index d168ede5..00000000 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/DefaultReleaseLoggerFactory.java +++ /dev/null @@ -1,337 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain.logging; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.Marker; - -public class DefaultReleaseLoggerFactory implements ReleaseLoggerFactory { - - @Override - public ReleaseLogger logger(Class clazz) { - return new Slf4jReleaseLogger(LoggerFactory.getLogger(clazz)); - } - - @Override - public ReleaseLogger logger(String name) { - return new Slf4jReleaseLogger(LoggerFactory.getLogger(name)); - } - - private static class Slf4jReleaseLogger implements ReleaseLogger, Logger { - - private final Logger logger; - - public Slf4jReleaseLogger(Logger logger) { - this.logger = logger; - } - - @Override - public void quiet(String message) { - logger.info(message); - } - - @Override - public String getName() { - return logger.getName(); - } - - @Override - public boolean isTraceEnabled() { - return logger.isTraceEnabled(); - } - - @Override - public void trace(String s) { - logger.trace(s); - } - - @Override - public void trace(String s, Object o) { - logger.trace(s, o); - } - - @Override - public void trace(String s, Object o, Object o1) { - logger.trace(s, o, o1); - } - - @Override - public void trace(String s, Object... objects) { - logger.trace(s, objects); - } - - @Override - public void trace(String s, Throwable throwable) { - logger.trace(s, throwable); - } - - @Override - public boolean isTraceEnabled(Marker marker) { - return logger.isTraceEnabled(marker); - } - - @Override - public void trace(Marker marker, String s) { - logger.trace(marker, s); - } - - @Override - public void trace(Marker marker, String s, Object o) { - logger.trace(marker, s, o); - } - - @Override - public void trace(Marker marker, String s, Object o, Object o1) { - logger.trace(marker, s, o, o1); - } - - @Override - public void trace(Marker marker, String s, Object... objects) { - logger.trace(marker, s, objects); - } - - @Override - public void trace(Marker marker, String s, Throwable throwable) { - logger.trace(marker, s, throwable); - } - - @Override - public boolean isDebugEnabled() { - return logger.isDebugEnabled(); - } - - @Override - public void debug(String s) { - logger.debug(s); - } - - @Override - public void debug(String s, Object o) { - logger.debug(s, o); - } - - @Override - public void debug(String s, Object o, Object o1) { - logger.debug(s, o, o1); - } - - @Override - public void debug(String s, Object... objects) { - logger.debug(s, objects); - } - - @Override - public void debug(String s, Throwable throwable) { - logger.debug(s, throwable); - } - - @Override - public boolean isDebugEnabled(Marker marker) { - return logger.isDebugEnabled(marker); - } - - @Override - public void debug(Marker marker, String s) { - logger.debug(marker, s); - } - - @Override - public void debug(Marker marker, String s, Object o) { - logger.debug(marker, s, o); - } - - @Override - public void debug(Marker marker, String s, Object o, Object o1) { - logger.debug(marker, s, o, o1); - } - - @Override - public void debug(Marker marker, String s, Object... objects) { - logger.debug(marker, s, objects); - } - - @Override - public void debug(Marker marker, String s, Throwable throwable) { - logger.debug(marker, s, throwable); - } - - @Override - public boolean isInfoEnabled() { - return logger.isInfoEnabled(); - } - - @Override - public void info(String s) { - logger.info(s); - } - - @Override - public void info(String s, Object o) { - logger.info(s, o); - } - - @Override - public void info(String s, Object o, Object o1) { - logger.info(s, o, o1); - } - - @Override - public void info(String s, Object... objects) { - logger.info(s, objects); - } - - @Override - public void info(String s, Throwable throwable) { - logger.info(s, throwable); - } - - @Override - public boolean isInfoEnabled(Marker marker) { - return logger.isInfoEnabled(marker); - } - - @Override - public void info(Marker marker, String s) { - logger.info(marker, s); - } - - @Override - public void info(Marker marker, String s, Object o) { - logger.info(marker, s, o); - } - - @Override - public void info(Marker marker, String s, Object o, Object o1) { - logger.info(marker, s, o, o1); - } - - @Override - public void info(Marker marker, String s, Object... objects) { - logger.info(marker, s, objects); - } - - @Override - public void info(Marker marker, String s, Throwable throwable) { - logger.info(marker, s, throwable); - } - - @Override - public boolean isWarnEnabled() { - return logger.isWarnEnabled(); - } - - @Override - public void warn(String s) { - logger.warn(s); - } - - @Override - public void warn(String s, Object o) { - logger.warn(s, o); - } - - @Override - public void warn(String s, Object... objects) { - logger.warn(s, objects); - } - - @Override - public void warn(String s, Object o, Object o1) { - logger.warn(s, o, o1); - } - - @Override - public void warn(String s, Throwable throwable) { - logger.warn(s, throwable); - } - - @Override - public boolean isWarnEnabled(Marker marker) { - return logger.isWarnEnabled(marker); - } - - @Override - public void warn(Marker marker, String s) { - logger.warn(marker, s); - } - - @Override - public void warn(Marker marker, String s, Object o) { - logger.warn(marker, s, o); - } - - @Override - public void warn(Marker marker, String s, Object o, Object o1) { - logger.warn(marker, s, o, o1); - } - - @Override - public void warn(Marker marker, String s, Object... objects) { - logger.warn(marker, s, objects); - } - - @Override - public void warn(Marker marker, String s, Throwable throwable) { - logger.warn(marker, s, throwable); - } - - @Override - public boolean isErrorEnabled() { - return logger.isErrorEnabled(); - } - - @Override - public void error(String s) { - logger.error(s); - } - - @Override - public void error(String s, Object o) { - logger.error(s, o); - } - - @Override - public void error(String s, Object o, Object o1) { - logger.error(s, o, o1); - } - - @Override - public void error(String s, Object... objects) { - logger.error(s, objects); - } - - @Override - public void error(String s, Throwable throwable) { - logger.error(s, throwable); - } - - @Override - public boolean isErrorEnabled(Marker marker) { - return logger.isErrorEnabled(marker); - } - - @Override - public void error(Marker marker, String s) { - logger.error(marker, s); - } - - @Override - public void error(Marker marker, String s, Object o) { - logger.error(marker, s, o); - } - - @Override - public void error(Marker marker, String s, Object o, Object o1) { - logger.error(marker, s, o, o1); - } - - @Override - public void error(Marker marker, String s, Object... objects) { - logger.error(marker, s, objects); - } - - @Override - public void error(Marker marker, String s, Throwable throwable) { - logger.error(marker, s, throwable); - } - } -} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/ReleaseLogger.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/ReleaseLogger.java deleted file mode 100644 index 9c22e6fb..00000000 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/ReleaseLogger.java +++ /dev/null @@ -1,34 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain.logging; - -import pl.allegro.tech.build.axion.release.infrastructure.output.GradleReleaseLoggerFactory; - -public interface ReleaseLogger { - - void trace(String message); - - void debug(String message); - - void info(String message); - - void warn(String message); - - void error(String message); - - void quiet(String message); - - class Factory { - private static ReleaseLoggerFactory factory = new GradleReleaseLoggerFactory(); - - public static void initialize(ReleaseLoggerFactory factory) { - Factory.factory = factory; - } - - public static ReleaseLogger logger(Class clazz) { - return factory.logger(clazz); - } - - public static ReleaseLogger logger(String name) { - return factory.logger(name); - } - } -} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/ReleaseLoggerFactory.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/ReleaseLoggerFactory.java deleted file mode 100644 index ae6e6343..00000000 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/logging/ReleaseLoggerFactory.java +++ /dev/null @@ -1,7 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain.logging; - -public interface ReleaseLoggerFactory { - ReleaseLogger logger(Class clazz); - - ReleaseLogger logger(String name); -} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/ChecksProperties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/ChecksProperties.java deleted file mode 100644 index 1f963276..00000000 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/ChecksProperties.java +++ /dev/null @@ -1,34 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain.properties; - -public class ChecksProperties { - - private final boolean checkUncommittedChanges; - private final boolean checkAheadOfRemote; - private final boolean checkSnapshotDependencies; - - public ChecksProperties( - boolean checkUncommittedChanges, - boolean checkAheadOfRemote, - boolean checkSnapshotDependencies - ) { - this.checkUncommittedChanges = checkUncommittedChanges; - this.checkAheadOfRemote = checkAheadOfRemote; - this.checkSnapshotDependencies = checkSnapshotDependencies; - } - - public final boolean getCheckUncommittedChanges() { - return checkUncommittedChanges; - } - - public final boolean isCheckUncommittedChanges() { - return checkUncommittedChanges; - } - - public final boolean isCheckAheadOfRemote() { - return checkAheadOfRemote; - } - - public final boolean isCheckSnapshotDependencies() { - return checkSnapshotDependencies; - } -} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/MonorepoProperties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/MonorepoProperties.java deleted file mode 100644 index f43070c2..00000000 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/MonorepoProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain.properties; - -import groovy.transform.Immutable; - -import java.util.Collections; -import java.util.List; - -public class MonorepoProperties { - - private final List dirsToExclude; - - public MonorepoProperties() { - this.dirsToExclude = Collections.emptyList(); - } - - public MonorepoProperties(List dirsToExclude) { - this.dirsToExclude = Collections.unmodifiableList(dirsToExclude); - } - - public List getDirsToExclude() { - return dirsToExclude; - } -} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/NextVersionProperties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/NextVersionProperties.java index 261cc279..84b03dbb 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/NextVersionProperties.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/NextVersionProperties.java @@ -4,10 +4,12 @@ public class NextVersionProperties { + @FunctionalInterface public interface Serializer { String apply(NextVersionProperties nextVersionProperties, String version); } + @FunctionalInterface public interface Deserializer { String apply(NextVersionProperties nextVersionProperties, ScmPosition position, String tag); } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/Properties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/Properties.java index 5f697597..327af5ee 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/Properties.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/Properties.java @@ -1,11 +1,13 @@ package pl.allegro.tech.build.axion.release.domain.properties; +import pl.allegro.tech.build.axion.release.domain.ChecksConfig; + public class Properties { private final boolean dryRun; private final VersionProperties version; private final TagProperties tag; - private final ChecksProperties checks; + private final ChecksConfig checks; private final NextVersionProperties nextVersion; private final HooksProperties hooks; @@ -13,7 +15,7 @@ public Properties( boolean dryRun, VersionProperties version, TagProperties tag, - ChecksProperties checks, + ChecksConfig checks, NextVersionProperties nextVersion, HooksProperties hooks ) { @@ -37,7 +39,7 @@ public final TagProperties getTag() { return tag; } - public final ChecksProperties getChecks() { + public final ChecksConfig getChecks() { return checks; } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/VersionProperties.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/VersionProperties.java index f86c0295..a8e323cd 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/VersionProperties.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/properties/VersionProperties.java @@ -1,6 +1,7 @@ package pl.allegro.tech.build.axion.release.domain.properties; import com.github.zafarkhaja.semver.Version; +import pl.allegro.tech.build.axion.release.domain.MonorepoConfig; import pl.allegro.tech.build.axion.release.domain.VersionIncrementerContext; import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition; @@ -22,7 +23,7 @@ public interface Incrementer { private final Incrementer versionIncrementer; private final boolean sanitizeVersion; private final boolean useHighestVersion; - private final MonorepoProperties monorepoProperties; + private final MonorepoConfig monorepoConfig; public VersionProperties( String forcedVersion, @@ -33,7 +34,7 @@ public VersionProperties( Incrementer versionIncrementer, boolean sanitizeVersion, boolean useHighestVersion, - MonorepoProperties monorepoProperties + MonorepoConfig monorepoConfig ) { this.forcedVersion = forcedVersion; this.forceSnapshot = forceSnapshot; @@ -43,7 +44,7 @@ public VersionProperties( this.versionIncrementer = versionIncrementer; this.sanitizeVersion = sanitizeVersion; this.useHighestVersion = useHighestVersion; - this.monorepoProperties = monorepoProperties; + this.monorepoConfig = monorepoConfig; } public boolean forceVersion() { @@ -82,7 +83,7 @@ public final boolean isUseHighestVersion() { return useHighestVersion; } - public MonorepoProperties getMonorepoProperties() { - return monorepoProperties; + public MonorepoConfig getMonorepoConfig() { + return monorepoConfig; } } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java index 1c49ec97..497d0db5 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java @@ -1,14 +1,15 @@ package pl.allegro.tech.build.axion.release.domain.scm; +import org.gradle.api.logging.Logger; +import org.gradle.api.logging.Logging; import pl.allegro.tech.build.axion.release.domain.LocalOnlyResolver; -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger; import java.util.List; import java.util.Optional; public class ScmService { + private static final Logger logger = Logging.getLogger(ScmService.class); - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(ScmService.class); private final LocalOnlyResolver localOnlyResolver; private final ScmProperties scmProperties; private ScmRepository repository; diff --git a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactory.java b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactory.java deleted file mode 100644 index 15aca034..00000000 --- a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactory.java +++ /dev/null @@ -1,11 +0,0 @@ -package pl.allegro.tech.build.axion.release.infrastructure.config; - -import org.gradle.api.Project; -import pl.allegro.tech.build.axion.release.domain.MonorepoConfig; -import pl.allegro.tech.build.axion.release.domain.properties.MonorepoProperties; - -public class MonorepoPropertiesFactory { - public static MonorepoProperties create(Project project, MonorepoConfig config, String currentBranch) { - return new MonorepoProperties(config.getProjectDirs()); - } -} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java index 742648ad..4a3f6dad 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java @@ -1,33 +1,62 @@ package pl.allegro.tech.build.axion.release.infrastructure.git; -import org.eclipse.jgit.api.*; +import org.eclipse.jgit.api.AddCommand; +import org.eclipse.jgit.api.FetchCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.LogCommand; +import org.eclipse.jgit.api.PushCommand; +import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.NoHeadException; +import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.errors.RepositoryNotFoundException; -import org.eclipse.jgit.lib.*; +import org.eclipse.jgit.lib.AnyObjectId; +import org.eclipse.jgit.lib.BranchTrackingStatus; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevSort; import org.eclipse.jgit.revwalk.RevWalk; -import org.eclipse.jgit.transport.*; +import org.eclipse.jgit.transport.PushResult; +import org.eclipse.jgit.transport.RemoteConfig; +import org.eclipse.jgit.transport.RemoteRefUpdate; +import org.eclipse.jgit.transport.TagOpt; +import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.treewalk.filter.PathFilter; import org.eclipse.jgit.util.io.DisabledOutputStream; -import org.eclipse.jgit.diff.DiffFormatter; -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger; -import pl.allegro.tech.build.axion.release.domain.scm.*; +import org.gradle.api.logging.Logger; +import org.gradle.api.logging.Logging; +import pl.allegro.tech.build.axion.release.domain.scm.ScmException; +import pl.allegro.tech.build.axion.release.domain.scm.ScmIdentity; +import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition; +import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties; +import pl.allegro.tech.build.axion.release.domain.scm.ScmPushOptions; +import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult; +import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository; +import pl.allegro.tech.build.axion.release.domain.scm.ScmRepositoryUnavailableException; +import pl.allegro.tech.build.axion.release.domain.scm.TagsOnCommit; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import static pl.allegro.tech.build.axion.release.TagPrefixConf.*; +import static pl.allegro.tech.build.axion.release.TagPrefixConf.fullLegacyPrefix; public class GitRepository implements ScmRepository { + private static final Logger logger = Logging.getLogger(GitRepository.class); - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(GitRepository.class); private static final String GIT_TAG_PREFIX = "refs/tags/"; private final TransportConfigFactory transportConfigFactory = new TransportConfigFactory(); diff --git a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/SshAgentIdentityRepositoryFactory.java b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/SshAgentIdentityRepositoryFactory.java index fd97dbd1..7132402c 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/SshAgentIdentityRepositoryFactory.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/SshAgentIdentityRepositoryFactory.java @@ -8,7 +8,8 @@ import com.jcraft.jsch.agentproxy.connector.SSHAgentConnector; import com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory; import com.jcraft.jsch.agentproxy.usocket.NCUSocketFactory; -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger; +import org.gradle.api.logging.Logger; +import org.gradle.api.logging.Logging; import java.io.PrintWriter; import java.io.StringWriter; @@ -23,7 +24,7 @@ */ class SshAgentIdentityRepositoryFactory { - private static final ReleaseLogger logger = ReleaseLogger.Factory.logger(SshAgentIdentityRepositoryFactory.class); + private static final Logger logger = Logging.getLogger(SshAgentIdentityRepositoryFactory.class); static Optional tryToCreateIdentityRepository() { Connector connector; diff --git a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/output/GradleReleaseLoggerFactory.java b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/output/GradleReleaseLoggerFactory.java deleted file mode 100644 index 5a7b3a02..00000000 --- a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/output/GradleReleaseLoggerFactory.java +++ /dev/null @@ -1,393 +0,0 @@ -package pl.allegro.tech.build.axion.release.infrastructure.output; - -import org.gradle.api.logging.LogLevel; -import org.gradle.api.logging.Logger; -import org.gradle.api.logging.Logging; -import org.slf4j.Marker; -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLogger; -import pl.allegro.tech.build.axion.release.domain.logging.ReleaseLoggerFactory; - -public class GradleReleaseLoggerFactory implements ReleaseLoggerFactory { - @Override - public ReleaseLogger logger(Class clazz) { - return new GradleReleaseLogger(Logging.getLogger(clazz)); - } - - @Override - public ReleaseLogger logger(String name) { - return new GradleReleaseLogger(Logging.getLogger(name)); - } - - private static class GradleReleaseLogger implements ReleaseLogger, Logger { - private final Logger logger; - - public GradleReleaseLogger(Logger logger) { - this.logger = logger; - } - - @Override - public boolean isLifecycleEnabled() { - return logger.isLifecycleEnabled(); - } - - @Override - public void debug(String s, Object... objects) { - logger.debug(s, objects); - } - - @Override - public void lifecycle(String s) { - logger.lifecycle(s); - } - - @Override - public void lifecycle(String s, Object... objects) { - logger.lifecycle(s, objects); - } - - @Override - public void lifecycle(String s, Throwable throwable) { - logger.lifecycle(s, throwable); - } - - @Override - public boolean isQuietEnabled() { - return logger.isQuietEnabled(); - } - - @Override - public void quiet(String s) { - logger.quiet(s); - } - - @Override - public void quiet(String s, Object... objects) { - logger.quiet(s, objects); - } - - @Override - public void info(String s, Object... objects) { - logger.info(s, objects); - } - - @Override - public void quiet(String s, Throwable throwable) { - logger.quiet(s, throwable); - } - - @Override - public boolean isEnabled(LogLevel logLevel) { - return logger.isEnabled(logLevel); - } - - @Override - public void log(LogLevel logLevel, String s) { - logger.log(logLevel, s); - } - - @Override - public void log(LogLevel logLevel, String s, Object... objects) { - logger.log(logLevel, s, objects); - } - - @Override - public void log(LogLevel logLevel, String s, Throwable throwable) { - logger.log(logLevel, s, throwable); - } - - @Override - public String getName() { - return logger.getName(); - } - - @Override - public boolean isTraceEnabled() { - return logger.isTraceEnabled(); - } - - @Override - public void trace(String s) { - logger.trace(s); - } - - @Override - public void trace(String s, Object o) { - logger.trace(s, o); - } - - @Override - public void trace(String s, Object o, Object o1) { - logger.trace(s, o, o1); - } - - @Override - public void trace(String s, Object... objects) { - logger.trace(s, objects); - } - - @Override - public void trace(String s, Throwable throwable) { - logger.trace(s, throwable); - } - - @Override - public boolean isTraceEnabled(Marker marker) { - return logger.isTraceEnabled(marker); - } - - @Override - public void trace(Marker marker, String s) { - logger.trace(marker, s); - } - - @Override - public void trace(Marker marker, String s, Object o) { - logger.trace(marker, s, o); - } - - @Override - public void trace(Marker marker, String s, Object o, Object o1) { - logger.trace(marker, s, o, o1); - } - - @Override - public void trace(Marker marker, String s, Object... objects) { - logger.trace(marker, s, objects); - } - - @Override - public void trace(Marker marker, String s, Throwable throwable) { - logger.trace(marker, s, throwable); - } - - @Override - public boolean isDebugEnabled() { - return logger.isDebugEnabled(); - } - - @Override - public void debug(String s) { - logger.debug(s); - } - - @Override - public void debug(String s, Object o) { - logger.debug(s, o); - } - - @Override - public void debug(String s, Object o, Object o1) { - logger.debug(s, o, o1); - } - - @Override - public void debug(String s, Throwable throwable) { - logger.debug(s, throwable); - } - - @Override - public boolean isDebugEnabled(Marker marker) { - return logger.isDebugEnabled(marker); - } - - @Override - public void debug(Marker marker, String s) { - logger.debug(marker, s); - } - - @Override - public void debug(Marker marker, String s, Object o) { - logger.debug(marker, s, o); - } - - @Override - public void debug(Marker marker, String s, Object o, Object o1) { - logger.debug(marker, s, o, o1); - } - - @Override - public void debug(Marker marker, String s, Object... objects) { - logger.debug(marker, s, objects); - } - - @Override - public void debug(Marker marker, String s, Throwable throwable) { - logger.debug(marker, s, throwable); - } - - @Override - public boolean isInfoEnabled() { - return logger.isInfoEnabled(); - } - - @Override - public void info(String s) { - logger.info(s); - } - - @Override - public void info(String s, Object o) { - logger.info(s, o); - } - - @Override - public void info(String s, Object o, Object o1) { - logger.info(s, o, o1); - } - - @Override - public void info(String s, Throwable throwable) { - logger.info(s, throwable); - } - - @Override - public boolean isInfoEnabled(Marker marker) { - return logger.isInfoEnabled(marker); - } - - @Override - public void info(Marker marker, String s) { - logger.info(marker, s); - } - - @Override - public void info(Marker marker, String s, Object o) { - logger.info(marker, s, o); - } - - @Override - public void info(Marker marker, String s, Object o, Object o1) { - logger.info(marker, s, o, o1); - } - - @Override - public void info(Marker marker, String s, Object... objects) { - logger.info(marker, s, objects); - } - - @Override - public void info(Marker marker, String s, Throwable throwable) { - logger.info(marker, s, throwable); - } - - @Override - public boolean isWarnEnabled() { - return logger.isWarnEnabled(); - } - - @Override - public void warn(String s) { - logger.warn(s); - } - - @Override - public void warn(String s, Object o) { - logger.warn(s, o); - } - - @Override - public void warn(String s, Object... objects) { - logger.warn(s, objects); - } - - @Override - public void warn(String s, Object o, Object o1) { - logger.warn(s, o, o1); - } - - @Override - public void warn(String s, Throwable throwable) { - logger.warn(s, throwable); - } - - @Override - public boolean isWarnEnabled(Marker marker) { - return logger.isWarnEnabled(marker); - } - - @Override - public void warn(Marker marker, String s) { - logger.warn(marker, s); - } - - @Override - public void warn(Marker marker, String s, Object o) { - logger.warn(marker, s, o); - } - - @Override - public void warn(Marker marker, String s, Object o, Object o1) { - logger.warn(marker, s, o, o1); - } - - @Override - public void warn(Marker marker, String s, Object... objects) { - logger.warn(marker, s, objects); - } - - @Override - public void warn(Marker marker, String s, Throwable throwable) { - logger.warn(marker, s, throwable); - } - - @Override - public boolean isErrorEnabled() { - return logger.isErrorEnabled(); - } - - @Override - public void error(String s) { - logger.error(s); - } - - @Override - public void error(String s, Object o) { - logger.error(s, o); - } - - @Override - public void error(String s, Object o, Object o1) { - logger.error(s, o, o1); - } - - @Override - public void error(String s, Object... objects) { - logger.error(s, objects); - } - - @Override - public void error(String s, Throwable throwable) { - logger.error(s, throwable); - } - - @Override - public boolean isErrorEnabled(Marker marker) { - return logger.isErrorEnabled(marker); - } - - @Override - public void error(Marker marker, String s) { - logger.error(marker, s); - } - - @Override - public void error(Marker marker, String s, Object o) { - logger.error(marker, s, o); - } - - @Override - public void error(Marker marker, String s, Object o, Object o1) { - logger.error(marker, s, o, o1); - } - - @Override - public void error(Marker marker, String s, Object... objects) { - logger.error(marker, s, objects); - } - - @Override - public void error(Marker marker, String s, Throwable throwable) { - logger.error(marker, s, throwable); - } - } -} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/util/FileLoader.java b/src/main/java/pl/allegro/tech/build/axion/release/util/FileLoader.java index 3c2306b4..0707b8e3 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/util/FileLoader.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/util/FileLoader.java @@ -27,14 +27,6 @@ public static String readFrom(Object file) { } } - public static String readIfFile(Object potentialFile) { - if (potentialFile instanceof File) { - return readFrom(potentialFile); - } - - return ((String) (potentialFile)); - } - public static File asFile(Object file) { if (file instanceof File) { return ((File) (file)); diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/Fixtures.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/Fixtures.groovy new file mode 100644 index 00000000..b97cc478 --- /dev/null +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/Fixtures.groovy @@ -0,0 +1,44 @@ +package pl.allegro.tech.build.axion.release + +import org.gradle.api.Project +import org.gradle.api.internal.project.ProjectInternal +import org.gradle.initialization.GradlePropertiesController +import org.gradle.testfixtures.ProjectBuilder +import pl.allegro.tech.build.axion.release.domain.ChecksConfig +import pl.allegro.tech.build.axion.release.domain.MonorepoConfig +import pl.allegro.tech.build.axion.release.domain.NextVersionConfig +import pl.allegro.tech.build.axion.release.domain.RepositoryConfig +import pl.allegro.tech.build.axion.release.domain.VersionConfig + +final class Fixtures { + static project(Map properties = [:]) { + def project = ProjectBuilder.builder().build() + project.file("gradle.properties").withWriter { writer -> + properties.each { + writer.println("${it.key}=${it.value}") + } + } + (project as ProjectInternal).services.get(GradlePropertiesController.class).loadGradlePropertiesFrom(project.projectDir) + return project + } + + static repositoryConfig(Project project = Fixtures.project()) { + return project.objects.newInstance(RepositoryConfig, project.rootProject.layout.projectDirectory) + } + + static versionConfig(Project project = Fixtures.project()) { + return project.objects.newInstance(VersionConfig, project.rootProject.layout.projectDirectory) + } + + static checksConfig(Project project = Fixtures.project()) { + return project.objects.newInstance(ChecksConfig) + } + + static monorepoConfig(Project project = Fixtures.project()) { + return project.objects.newInstance(MonorepoConfig) + } + + static nextVersionConfig(Project project = Fixtures.project()) { + return project.objects.newInstance(NextVersionConfig) + } +} diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/RepositoryBasedTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/RepositoryBasedTest.groovy index 9adb473e..c3b21243 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/RepositoryBasedTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/RepositoryBasedTest.groovy @@ -5,7 +5,7 @@ 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.Context +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext import pl.allegro.tech.build.axion.release.infrastructure.di.ScmRepositoryFactory import spock.lang.Specification import spock.lang.TempDir @@ -17,7 +17,7 @@ class RepositoryBasedTest extends Specification { @TempDir File temporaryFolder - Context context + VersionResolutionContext context ScmRepository repository @@ -30,7 +30,7 @@ class RepositoryBasedTest extends Specification { ScmProperties scmProperties = scmProperties(temporaryFolder).build() ScmRepository scmRepository = ScmRepositoryFactory.create(scmProperties) - context = new Context( + context = new VersionResolutionContext( PropertiesBuilder.properties().build(), scmRepository, scmProperties, diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarkerTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarkerTest.groovy index e6c2dfcb..83ead695 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarkerTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionMarkerTest.groovy @@ -1,16 +1,14 @@ package pl.allegro.tech.build.axion.release.domain import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.RepositoryBasedTest -import pl.allegro.tech.build.axion.release.TagPrefixConf import pl.allegro.tech.build.axion.release.domain.hooks.ReleaseHooksRunner import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties import pl.allegro.tech.build.axion.release.domain.properties.TagProperties import pl.allegro.tech.build.axion.release.domain.scm.ScmService import static pl.allegro.tech.build.axion.release.TagPrefixConf.* -import static pl.allegro.tech.build.axion.release.TagPrefixConf.prefix import static pl.allegro.tech.build.axion.release.domain.properties.NextVersionPropertiesBuilder.nextVersionProperties import static pl.allegro.tech.build.axion.release.domain.properties.TagPropertiesBuilder.tagProperties @@ -22,9 +20,9 @@ class NextVersionMarkerTest extends RepositoryBasedTest { private Releaser releaser - Project project = ProjectBuilder.builder().build() + Project project = Fixtures.project() - VersionConfig config = new VersionConfig(project) + VersionConfig config = Fixtures.versionConfig(project) def setup() { repository = context.repository() diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementerTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementerTest.groovy index 69a7f9e8..3668eb79 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementerTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/PredefinedVersionIncrementerTest.groovy @@ -1,9 +1,6 @@ package pl.allegro.tech.build.axion.release.domain import com.github.zafarkhaja.semver.Version -import pl.allegro.tech.build.axion.release.TagPrefixConf -import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition -import pl.allegro.tech.build.axion.release.domain.scm.ScmPositionBuilder import spock.lang.Specification import static pl.allegro.tech.build.axion.release.TagPrefixConf.* @@ -31,7 +28,7 @@ class PredefinedVersionIncrementerTest extends Specification { def "should increment minor if not on release branch and incrementMinorIfNotOnRelease used"() { expect: - versionIncrementerFor('incrementMinorIfNotOnRelease', [releaseBranchPattern: (prefix() +'.*')]).apply(context) == Version.valueOf('0.2.0') + versionIncrementerFor('incrementMinorIfNotOnRelease', [releaseBranchPattern: (defaultPrefix() +'.*')]).apply(context) == Version.valueOf('0.2.0') } def "should increment patch if on release branch and incrementMinorIfNotOnRelease used"() { @@ -41,7 +38,7 @@ class PredefinedVersionIncrementerTest extends Specification { def "should delegate to first matching incrementer when branchSpecific rule used"() { expect: - versionIncrementerFor('branchSpecific', [(prefix() + '.*'): 'incrementPatch', 'master': 'incrementMinor']).apply(context) == Version.valueOf('0.2.0') + versionIncrementerFor('branchSpecific', [(defaultPrefix() + '.*'): 'incrementPatch', 'master': 'incrementMinor']).apply(context) == Version.valueOf('0.2.0') } def "should increment prerelease version when incrementPrerelease rule used"() { diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfigFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfigFactoryTest.groovy index 18049dc9..a6dd4342 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfigFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/RepositoryConfigFactoryTest.groovy @@ -2,99 +2,101 @@ package pl.allegro.tech.build.axion.release.domain import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder +import pl.allegro.tech.build.axion.release.Fixtures import spock.lang.Specification class RepositoryConfigFactoryTest extends Specification { def "should set repository directory to rootProject dir by default"() { given: - Project project = ProjectBuilder.builder().build() + Project project = Fixtures.project() when: - RepositoryConfig config = RepositoryConfigFactory.create(project) + RepositoryConfig config = Fixtures.repositoryConfig(project) then: - config.directory == project.rootDir + config.directory.asFile.get() == project.rootDir } def "should not initialize authorization options when no flags on project"() { given: - Project project = ProjectBuilder.builder().build() + Project project = Fixtures.project() when: - RepositoryConfig config = RepositoryConfigFactory.create(project) + RepositoryConfig config = Fixtures.repositoryConfig(project) then: - !config.customKeyPassword - !config.customKey - !config.customUsername - config.customPassword == '' + !config.customKeyPassword.isPresent() + !config.customKey.isPresent() + !config.customUsername.isPresent() + !config.customPassword.isPresent() } def "should set authorization options when custom key and password provided"() { given: - Project project = ProjectBuilder.builder().build() - project.extensions.extraProperties.set('release.customKey', 'key') - project.extensions.extraProperties.set('release.customKeyPassword', 'password') + Project project = Fixtures.project( + ["release.customKey": "key", "release.customKeyPassword": "password"]) when: - RepositoryConfig config = RepositoryConfigFactory.create(project) + RepositoryConfig config = Fixtures.repositoryConfig(project) then: - config.customKey == 'key' - config.customKeyPassword == 'password' + config.customKey.get() == "key" + config.customKeyPassword.get() == "password" } - +/* def "should read key from file when 'release.customKeyFile' property used"() { given: - Project project = ProjectBuilder.builder().build() + Project project = Fixtures.project( + [ + 'release.customKeyFile': './keyFile', + 'release.customKeyPassword': 'password'] + ) File keyFile = project.file('./keyFile') keyFile.createNewFile() keyFile << 'keyFile' - project.extensions.extraProperties.set('release.customKeyFile', keyFile.canonicalPath) - project.extensions.extraProperties.set('release.customKeyPassword', 'password') - when: - RepositoryConfig config = RepositoryConfigFactory.create(project) + RepositoryConfig config = Fixtures.repositoryConfig(project) then: - config.customKey == 'keyFile' - config.customKeyPassword == 'password' + config.customKeyFile.asFile.get() == './keyFile' + config.customKeyPassword.get() == 'password' } def "should prefer explicit custom key before key read from file when both 'release.customKey*' properties used"() { given: - Project project = ProjectBuilder.builder().build() + Project project = Fixtures.project( + ['release.customKey': 'key', + 'release.customKeyFile': './keyFile', + 'release.customKeyPassword': 'password'] + ) File keyFile = project.file('./keyFile') keyFile.createNewFile() keyFile << 'keyFile' - project.extensions.extraProperties.set('release.customKey', 'key') - project.extensions.extraProperties.set('release.customKeyFile', keyFile.canonicalPath) - project.extensions.extraProperties.set('release.customKeyPassword', 'password') - when: - RepositoryConfig config = RepositoryConfigFactory.create(project) + RepositoryConfig config = Fixtures.repositoryConfig(project) then: - config.customKey == 'key' - } - + config.customKey.get() == 'key' + }*/ + def "should set username and password when provided via 'release.customUsername' and 'release.customPassword'"() { given: - Project project = ProjectBuilder.builder().build() - project.extensions.extraProperties.set('release.customUsername', 'username') - project.extensions.extraProperties.set('release.customPassword', 'password') + Project project = Fixtures.project( + ['release.customUsername': 'username', + 'release.customPassword': 'password'] + ) when: - RepositoryConfig config = RepositoryConfigFactory.create(project) + RepositoryConfig config = Fixtures.repositoryConfig(project) then: - config.customUsername == 'username' - config.customPassword == 'password' + config.customUsername.get() == 'username' + config.customPassword.get() == 'password' } } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy index 8144b96f..a512c33e 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverSubfolderTest.groovy @@ -1,8 +1,9 @@ package pl.allegro.tech.build.axion.release.domain +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.RepositoryBasedTest import pl.allegro.tech.build.axion.release.domain.properties.* -import pl.allegro.tech.build.axion.release.infrastructure.di.Context +import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext import spock.lang.Shared import static pl.allegro.tech.build.axion.release.TagPrefixConf.* @@ -19,8 +20,7 @@ class VersionResolverSubfolderTest extends RepositoryBasedTest { NextVersionProperties nextVersionRules = nextVersionProperties().build() @Shared - MonorepoProperties defaultMonorepoProperties = MonorepoPropertiesBuilder.monorepoProperties() - .build() + MonorepoConfig defaultMonorepoProperties = Fixtures.monorepoConfig() VersionProperties defaultMonorepoVersionRules = VersionPropertiesBuilder.versionProperties() .supportMonorepos(defaultMonorepoProperties) @@ -204,7 +204,7 @@ class VersionResolverSubfolderTest extends RepositoryBasedTest { } private void configureContextWithVersionRules(VersionProperties versionRules) { - context = new Context( + context = new VersionResolutionContext( PropertiesBuilder.properties().withVersionRules(versionRules).build(), context.repository(), scmProperties(temporaryFolder).build(), diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy index ce781a0f..b197e950 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionResolverTest.groovy @@ -1,13 +1,11 @@ package pl.allegro.tech.build.axion.release.domain import pl.allegro.tech.build.axion.release.RepositoryBasedTest -import pl.allegro.tech.build.axion.release.TagPrefixConf import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties import pl.allegro.tech.build.axion.release.domain.properties.TagProperties import pl.allegro.tech.build.axion.release.domain.properties.VersionProperties import static pl.allegro.tech.build.axion.release.TagPrefixConf.* -import static pl.allegro.tech.build.axion.release.TagPrefixConf.prefix import static pl.allegro.tech.build.axion.release.domain.properties.NextVersionPropertiesBuilder.nextVersionProperties import static pl.allegro.tech.build.axion.release.domain.properties.TagPropertiesBuilder.tagProperties import static pl.allegro.tech.build.axion.release.domain.properties.VersionPropertiesBuilder.versionProperties @@ -419,7 +417,7 @@ class VersionResolverTest extends RepositoryBasedTest { where: versionProps | tagPrefix | v | isSnapshot - versionProperties().build() | prefix() | '1.1.0' | false - versionProperties().build() | 'B'+prefix() | '1.2.0' | false + versionProperties().build() | defaultPrefix() | '1.1.0' | false + versionProperties().build() | 'B'+defaultPrefix() | '1.2.0' | false } } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionServiceTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionServiceTest.groovy index d83ad17f..e79e8142 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionServiceTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionServiceTest.groovy @@ -3,6 +3,7 @@ package pl.allegro.tech.build.axion.release.domain import com.github.zafarkhaja.semver.Version import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties import pl.allegro.tech.build.axion.release.domain.properties.TagProperties import pl.allegro.tech.build.axion.release.domain.properties.VersionProperties @@ -26,8 +27,8 @@ class VersionServiceTest extends Specification { NextVersionProperties nextVersionProperties = nextVersionProperties().build() def setup() { - Project project = ProjectBuilder.builder().build() - versionConfig = project.extensions.create('versionConfig', VersionConfig, project) + Project project = Fixtures.project() + versionConfig = Fixtures.versionConfig(project) service = new VersionService(resolver) } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/MonorepoPropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/MonorepoPropertiesBuilder.groovy deleted file mode 100644 index eb45ac37..00000000 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/MonorepoPropertiesBuilder.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain.properties - -class MonorepoPropertiesBuilder { - - private List dirsToExclude = [] - - private MonorepoPropertiesBuilder() { - } - - static MonorepoPropertiesBuilder monorepoProperties() { - return new MonorepoPropertiesBuilder() - } - - MonorepoProperties build() { - return new MonorepoProperties(dirsToExclude) - } - - MonorepoPropertiesBuilder excludeDirs(List dirsToExclude) { - this.dirsToExclude = dirsToExclude - return this - } -} diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/PropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/PropertiesBuilder.groovy index 2f6e7c75..2e2ac3f6 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/PropertiesBuilder.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/PropertiesBuilder.groovy @@ -1,5 +1,8 @@ package pl.allegro.tech.build.axion.release.domain.properties +import pl.allegro.tech.build.axion.release.Fixtures +import pl.allegro.tech.build.axion.release.domain.ChecksConfig + class PropertiesBuilder { private TagProperties tagProperties = TagPropertiesBuilder.tagProperties().build() @@ -8,8 +11,6 @@ class PropertiesBuilder { private VersionProperties versionProperties = VersionPropertiesBuilder.versionProperties().build() - private ChecksProperties checksProperties = new ChecksProperties(true, true, false) - private HooksProperties hooksProperties = new HooksProperties([], []) private PropertiesBuilder() { @@ -20,13 +21,15 @@ class PropertiesBuilder { } Properties build() { + ChecksConfig checksConfig = Fixtures.checksConfig(Fixtures.project()) + checksConfig.snapshotDependencies.set(false) return new Properties( - false, - versionProperties, - tagProperties, - checksProperties, - nextVersionProperties, - hooksProperties + false, + versionProperties, + tagProperties, + checksConfig, + nextVersionProperties, + hooksProperties ) } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/TagPropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/TagPropertiesBuilder.groovy index 75c0bc58..fa4fe82f 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/TagPropertiesBuilder.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/TagPropertiesBuilder.groovy @@ -5,7 +5,7 @@ import pl.allegro.tech.build.axion.release.domain.TagNameSerializer class TagPropertiesBuilder { - private String prefix = TagPrefixConf.prefix() + private String prefix = TagPrefixConf.defaultPrefix() private TagPropertiesBuilder() { } @@ -17,7 +17,7 @@ class TagPropertiesBuilder { TagProperties build() { return new TagProperties( prefix, - TagPrefixConf.separator(), + TagPrefixConf.defaultSeparator(), TagNameSerializer.DEFAULT.serializer, TagNameSerializer.DEFAULT.deserializer, { r, p -> '0.1.0' } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/VersionPropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/VersionPropertiesBuilder.groovy index afe3586b..aa32fee9 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/VersionPropertiesBuilder.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/VersionPropertiesBuilder.groovy @@ -1,5 +1,7 @@ package pl.allegro.tech.build.axion.release.domain.properties +import pl.allegro.tech.build.axion.release.Fixtures +import pl.allegro.tech.build.axion.release.domain.MonorepoConfig import pl.allegro.tech.build.axion.release.domain.PredefinedSnapshotCreator import pl.allegro.tech.build.axion.release.domain.PredefinedVersionCreator import pl.allegro.tech.build.axion.release.domain.PredefinedVersionIncrementer @@ -14,7 +16,7 @@ class VersionPropertiesBuilder { private boolean useHighestVersion = false - private MonorepoProperties monorepoProperties = new MonorepoProperties() + private MonorepoConfig monorepoConfig = Fixtures.monorepoConfig() private VersionProperties.Creator versionCreator = PredefinedVersionCreator.SIMPLE.versionCreator @@ -39,7 +41,7 @@ class VersionPropertiesBuilder { PredefinedVersionIncrementer.versionIncrementerFor('incrementPatch'), sanitizeVersion, useHighestVersion, - monorepoProperties + monorepoConfig ) } @@ -63,8 +65,8 @@ class VersionPropertiesBuilder { return this } - VersionPropertiesBuilder supportMonorepos(MonorepoProperties monorepoProperties) { - this.monorepoProperties = monorepoProperties + VersionPropertiesBuilder supportMonorepos(MonorepoConfig monorepoConfig) { + this.monorepoConfig = monorepoConfig return this } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ChecksPropertiesFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ChecksPropertiesFactoryTest.groovy index b80f71cc..e19866dc 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ChecksPropertiesFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ChecksPropertiesFactoryTest.groovy @@ -1,77 +1,63 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder + +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.ChecksConfig -import pl.allegro.tech.build.axion.release.domain.properties.ChecksProperties import spock.lang.Specification class ChecksPropertiesFactoryTest extends Specification { - private ChecksConfig config = new ChecksConfig() - - private Project project = ProjectBuilder.builder().build() - def "should return default value from config when no project properties are present"() { given: - config.aheadOfRemote = true - config.uncommittedChanges = true - config.snapshotDependencies = true - - ChecksProperties rules = ChecksPropertiesFactory.create(project, config) + ChecksConfig config = Fixtures.checksConfig(Fixtures.project()) + config.aheadOfRemote.set(true) + config.uncommittedChanges.set(true) + config.snapshotDependencies.set(true) expect: - rules.checkUncommittedChanges - rules.checkAheadOfRemote - rules.checkSnapshotDependencies + config.checkUncommittedChanges().get() + config.checkAheadOfRemote().get() + config.checkSnapshotDependencies().get() } def "should always return false if checks are globally disabled using release.disableChecks"() { given: - project.extensions.extraProperties.set('release.disableChecks', true) - config.aheadOfRemote = true - config.uncommittedChanges = true - config.snapshotDependencies = true - - ChecksProperties rules = ChecksPropertiesFactory.create(project, config) + ChecksConfig config = Fixtures.checksConfig(Fixtures.project(['release.disableChecks' : ""])) + config.aheadOfRemote.set(true) + config.uncommittedChanges.set(true) + config.snapshotDependencies.set(true) expect: - !rules.checkUncommittedChanges - !rules.checkAheadOfRemote - !rules.checkSnapshotDependencies + !config.checkUncommittedChanges().get() + !config.checkAheadOfRemote().get() + !config.checkSnapshotDependencies().get() } def "should skip uncommitted changes check if it was disabled using project property"() { given: - project.extensions.extraProperties.set('release.disableUncommittedCheck', true) - config.uncommittedChanges = true - - ChecksProperties rules = ChecksPropertiesFactory.create(project, config) + ChecksConfig config = Fixtures.checksConfig(Fixtures.project(['release.disableUncommittedCheck' : ""])) + config.uncommittedChanges.set(true) expect: - !rules.checkUncommittedChanges + !config.checkUncommittedChanges().get() } def "should skip ahead of remote check if it was disabled using project property"() { given: - project.extensions.extraProperties.set('release.disableRemoteCheck', true) - config.aheadOfRemote = true - - ChecksProperties rules = ChecksPropertiesFactory.create(project, config) + ChecksConfig config = Fixtures.checksConfig(Fixtures.project(['release.disableRemoteCheck' : ""])) + config.aheadOfRemote.set(true) expect: - !rules.checkAheadOfRemote + !config.checkAheadOfRemote().get() } def "should skip snapshots check if it was disabled using project property"() { given: - project.extensions.extraProperties.set('release.disableSnapshotsCheck', true) - config.snapshotDependencies = true - - ChecksProperties rules = ChecksPropertiesFactory.create(project, config) + ChecksConfig config = Fixtures.checksConfig(Fixtures.project(['release.disableSnapshotsCheck' : ""])) + config.snapshotDependencies.set(true) expect: - !rules.checkSnapshotDependencies + !config.checkSnapshotDependencies().get() } } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactoryTest.groovy index 452fbc9e..b8c84152 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/LocalOnlyResolverFactoryTest.groovy @@ -1,34 +1,31 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder + +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.LocalOnlyResolver import pl.allegro.tech.build.axion.release.domain.VersionConfig import spock.lang.Specification class LocalOnlyResolverFactoryTest extends Specification { - private final Project project = ProjectBuilder.builder().build() - - private final VersionConfig config = new VersionConfig(project) - - def "should resolve to localOnly when project release.localOnly property present"() { given: - project.extensions.extraProperties.set('release.localOnly', '') - LocalOnlyResolver resolver = LocalOnlyResolverFactory.create(project, config) + VersionConfig config = Fixtures.versionConfig(Fixtures.project(['release.localOnly' : ''])) + LocalOnlyResolver resolver = LocalOnlyResolverFactory.create(config) expect: + config.localOnly().get() resolver.localOnly(false) } def "should resolve to localOnly when config has localOnly flag set"() { given: - config.localOnly = true - LocalOnlyResolver resolver = LocalOnlyResolverFactory.create(project, config) + VersionConfig config = Fixtures.versionConfig() + config.localOnly.set(true) + LocalOnlyResolver resolver = LocalOnlyResolverFactory.create(config) expect: + config.localOnly().get() resolver.localOnly(false) } - } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactoryTest.groovy index 01441946..5b37f998 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactoryTest.groovy @@ -1,33 +1,26 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project + +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.MonorepoConfig -import pl.allegro.tech.build.axion.release.domain.properties.MonorepoProperties import spock.lang.Specification -import static org.gradle.testfixtures.ProjectBuilder.builder - class MonorepoPropertiesFactoryTest extends Specification { - private Project project - private MonorepoConfig monorepoConfig def setup() { - project = builder().build() - monorepoConfig = new MonorepoConfig() + monorepoConfig = Fixtures.monorepoConfig() } def "should copy properties from MonorepoConfig object"() { - given: - monorepoConfig.projectDirs = ["foo", "bar"] - when: - MonorepoProperties rules = MonorepoPropertiesFactory.create(project, monorepoConfig, 'master') + monorepoConfig.projectDirs = ["foo", "bar"] then: - rules.dirsToExclude.size() == 2 - rules.dirsToExclude.contains("foo") - rules.dirsToExclude.contains("bar") + def dirsToExclude = monorepoConfig.projectDirs.get() + dirsToExclude.size() == 2 + dirsToExclude.contains("foo") + dirsToExclude.contains("bar") } } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/NextVersionPropertiesFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/NextVersionPropertiesFactoryTest.groovy index e319c264..81e8c42c 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/NextVersionPropertiesFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/NextVersionPropertiesFactoryTest.groovy @@ -1,34 +1,28 @@ package pl.allegro.tech.build.axion.release.infrastructure.config import org.gradle.api.Project +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.NextVersionConfig import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition import spock.lang.Specification import static org.gradle.testfixtures.ProjectBuilder.builder +import static pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties.* class NextVersionPropertiesFactoryTest extends Specification { - private Project project - - private NextVersionConfig config = new NextVersionConfig() - - def setup() { - project = builder().build() - } - def "should copy non-project properties from NextVersionConfig object"() { given: - project.extensions.extraProperties.set('release.version', '1.0.0') + NextVersionConfig config = Fixtures.nextVersionConfig(Fixtures.project(['release.version': '1.0.0'])) - config.serializer = { config, version -> 'serialize'} - config.deserializer = { config, position, tagName -> 'deserialize'} - config.suffix = 'something' - config.separator = '=' + config.serializer.set( (Serializer) { NextVersionProperties config_, String version -> 'serialize'}) + config.deserializer.set( (Deserializer) { NextVersionProperties config_, ScmPosition position, String tagName -> 'deserialize'}) + config.suffix.set( 'something') + config.separator.set('=') when: - NextVersionProperties properties = NextVersionPropertiesFactory.create(project, config) + NextVersionProperties properties = config.nextVersionProperties() then: properties.serializer.apply(properties, "any") == 'serialize' @@ -39,10 +33,10 @@ class NextVersionPropertiesFactoryTest extends Specification { def "should read nextVersion from 'release.version' property"() { given: - project.extensions.extraProperties.set('release.version', '1.0.0') + NextVersionConfig config = Fixtures.nextVersionConfig(Fixtures.project(['release.version': '1.0.0'])) when: - NextVersionProperties properties = NextVersionPropertiesFactory.create(project, config) + NextVersionProperties properties = config.nextVersionProperties() then: properties.nextVersion @@ -51,10 +45,10 @@ class NextVersionPropertiesFactoryTest extends Specification { def "should read nextVersion from deprecated 'release.nextVersion' property"() { given: - project.extensions.extraProperties.set('release.nextVersion', '1.0.0') + NextVersionConfig config = Fixtures.nextVersionConfig(Fixtures.project(['release.nextVersion': '1.0.0'])) when: - NextVersionProperties properties = NextVersionPropertiesFactory.create(project, config) + NextVersionProperties properties = config.nextVersionProperties() then: properties.nextVersion diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactoryTest.groovy index de957192..70e44975 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmIdentityFactoryTest.groovy @@ -2,15 +2,17 @@ package pl.allegro.tech.build.axion.release.infrastructure.config import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.RepositoryConfig import pl.allegro.tech.build.axion.release.domain.scm.ScmIdentity import spock.lang.Specification class ScmIdentityFactoryTest extends Specification { + private final Project project = Fixtures.project() def "should return default identity when no key set"() { given: - RepositoryConfig config = new RepositoryConfig() + RepositoryConfig config = Fixtures.repositoryConfig(project) when: ScmIdentity identity = ScmIdentityFactory.create(config, false) @@ -22,7 +24,7 @@ class ScmIdentityFactoryTest extends Specification { def "should return no-ssh-agent identity when support for ssh agents disabled"() { given: - RepositoryConfig config = new RepositoryConfig() + RepositoryConfig config = Fixtures.repositoryConfig(project) when: ScmIdentity identity = ScmIdentityFactory.create(config, true) @@ -34,7 +36,9 @@ class ScmIdentityFactoryTest extends Specification { def "should return custom identity when key set"() { given: - RepositoryConfig config = new RepositoryConfig(customKey: 'key', customKeyPassword: 'password') + RepositoryConfig config = Fixtures.repositoryConfig(project) + config.customKey.set("key") + config.customKeyPassword.set("password") when: ScmIdentity identity = ScmIdentityFactory.create(config, false) @@ -47,13 +51,13 @@ class ScmIdentityFactoryTest extends Specification { def "should read key contents from file when file passed as key"() { given: - Project project = ProjectBuilder.builder().build() - File keyFile = project.file('./keyFile') keyFile.createNewFile() keyFile << 'keyFile' - RepositoryConfig config = new RepositoryConfig(customKey: keyFile, customKeyPassword: 'password') + RepositoryConfig config = Fixtures.repositoryConfig(project) + config.customKeyFile.set(keyFile) + config.customKeyPassword.set("password") when: ScmIdentity identity = ScmIdentityFactory.create(config, false) diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactoryTest.groovy index 41d2396d..3a56c66f 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/ScmPropertiesFactoryTest.groovy @@ -1,24 +1,22 @@ package pl.allegro.tech.build.axion.release.infrastructure.config -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder + +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties import spock.lang.Specification class ScmPropertiesFactoryTest extends Specification { - private Project project = ProjectBuilder.builder().build() - - private VersionConfig config = new VersionConfig(project) + private VersionConfig config = Fixtures.versionConfig() def "should return remote name and tagsOnly option from configuration when no flags on project"() { given: - config.repository.remote = 'someRemote' - config.repository.pushTagsOnly = true + config.repository.remote.set( 'someRemote') + config.repository.pushTagsOnly.set(true) when: - ScmProperties properties = ScmPropertiesFactory.create(project, config) + ScmProperties properties = ScmPropertiesFactory.create(config) then: properties.remote == 'someRemote' @@ -27,14 +25,14 @@ class ScmPropertiesFactoryTest extends Specification { def "should return true for tagsOnly when enabled via project flag"() { given: - config.repository.pushTagsOnly = false - project.extensions.extraProperties.set('release.pushTagsOnly', true) + def project = Fixtures.project(['release.pushTagsOnly':'']) + VersionConfig config = Fixtures.versionConfig(project) + config.repository.pushTagsOnly.set(false) when: - ScmProperties properties = ScmPropertiesFactory.create(project, config) + ScmProperties properties = ScmPropertiesFactory.create(config) then: properties.pushTagsOnly } - } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactoryTest.groovy index 5cd7347e..c7935acf 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/TagPropertiesFactoryTest.groovy @@ -1,6 +1,7 @@ package pl.allegro.tech.build.axion.release.infrastructure.config import org.gradle.api.Project +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.properties.TagProperties import spock.lang.Specification @@ -14,16 +15,16 @@ class TagPropertiesFactoryTest extends Specification { private VersionConfig config def setup() { - project = builder().build() - config = new VersionConfig(project) + project = Fixtures.project() + config = Fixtures.versionConfig(project) } def "should pick default prefix if none branch prefixes match"() { given: - config.tag.prefix = 'default-prefix' - config.tag.branchPrefix = [ + config.tag.prefix.set( 'default-prefix') + config.tag.branchPrefix.set( [ 'some.*': 'some-prefix' - ] + ]) when: TagProperties tagProperties = TagPropertiesFactory.create(config.tag, 'master') diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactoryTest.groovy index b61d5394..e7d8a5b4 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/VersionPropertiesFactoryTest.groovy @@ -2,12 +2,12 @@ package pl.allegro.tech.build.axion.release.infrastructure.config import com.github.zafarkhaja.semver.Version import org.gradle.api.Project +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.VersionIncrementerContext import pl.allegro.tech.build.axion.release.domain.properties.VersionProperties import spock.lang.Specification -import static org.gradle.testfixtures.ProjectBuilder.builder import static pl.allegro.tech.build.axion.release.domain.scm.ScmPositionBuilder.scmPosition class VersionPropertiesFactoryTest extends Specification { @@ -17,26 +17,26 @@ class VersionPropertiesFactoryTest extends Specification { private VersionConfig versionConfig def setup() { - project = builder().build() - versionConfig = new VersionConfig(project) + project = Fixtures.project() + versionConfig = Fixtures.versionConfig(project) } def "should copy non-project properties from VersionConfig object"() { given: - versionConfig.versionIncrementer = {VersionIncrementerContext c -> new Version.Builder('1.2.3').build() } - versionConfig.sanitizeVersion = false + versionConfig.versionIncrementer({ VersionIncrementerContext c -> new Version.Builder('1.2.3').build() }) + versionConfig.sanitizeVersion.set(false) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: rules.versionIncrementer.apply(null) == new Version.Builder('1.2.3').build() - rules.sanitizeVersion == versionConfig.sanitizeVersion + rules.sanitizeVersion == versionConfig.sanitizeVersion.get() } def "should return forceVersion false when project has no 'release.version' property"() { when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: !rules.forceVersion() @@ -44,10 +44,10 @@ class VersionPropertiesFactoryTest extends Specification { def "should return forceVersion false when project has 'release.version' property with empty value"() { given: - project.extensions.extraProperties.set('release.version', '') + VersionConfig versionConfig = Fixtures.versionConfig(Fixtures.project(['release.version': ''])) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: !rules.forceVersion() @@ -55,10 +55,10 @@ class VersionPropertiesFactoryTest extends Specification { def "should return forceVersion true when project has 'release.version' property with non-empty value"() { given: - project.extensions.extraProperties.set('release.version', 'version') + VersionConfig versionConfig = Fixtures.versionConfig(Fixtures.project(['release.version': 'version'])) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: rules.forceVersion() @@ -67,10 +67,10 @@ class VersionPropertiesFactoryTest extends Specification { def "should return trimmed forcedVersion when project has 'release.Version' property with leading or trailing spaces"() { given: - project.extensions.extraProperties.set('release.version', ' version ') + VersionConfig versionConfig = Fixtures.versionConfig(Fixtures.project(['release.version': 'version '])) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: rules.forceVersion() @@ -79,10 +79,10 @@ class VersionPropertiesFactoryTest extends Specification { def "should return forceVersion true when project has deprecated 'release.forceVersion' property with non-empty value"() { given: - project.extensions.extraProperties.set('release.forceVersion', 'version') + VersionConfig versionConfig = Fixtures.versionConfig(Fixtures.project(['release.forceVersion': 'version'])) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: rules.forceVersion() @@ -91,10 +91,10 @@ class VersionPropertiesFactoryTest extends Specification { def "should return ignore uncommitted changes flag from version config when no project flag present"() { given: - versionConfig.ignoreUncommittedChanges = false + versionConfig.ignoreUncommittedChanges.set(false) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: !rules.ignoreUncommittedChanges @@ -102,11 +102,11 @@ class VersionPropertiesFactoryTest extends Specification { def "should return ignore uncommitted changes as true when project flag present"() { given: - versionConfig.ignoreUncommittedChanges = false - project.extensions.extraProperties.set('release.ignoreUncommittedChanges', true) + VersionConfig versionConfig = Fixtures.versionConfig(Fixtures.project(['release.ignoreUncommittedChanges': ""])) + versionConfig.ignoreUncommittedChanges.set(false) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: rules.ignoreUncommittedChanges @@ -114,13 +114,13 @@ class VersionPropertiesFactoryTest extends Specification { def "should pick default version creator if none branch creators match"() { given: - versionConfig.versionCreator = { v, p -> 'default' } - versionConfig.branchVersionCreator = [ + versionConfig.versionCreator.set((VersionProperties.Creator) { v, p -> 'default' }) + versionConfig.branchVersionCreator.putAll([ 'some.*': { v, p -> 'someBranch' } - ] + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: rules.versionCreator.apply(null, null) == 'default' @@ -128,13 +128,13 @@ class VersionPropertiesFactoryTest extends Specification { def "should pick version creator suitable for current branch if defined in per branch creators"() { given: - versionConfig.versionCreator = { v, p -> 'default' } - versionConfig.branchVersionCreator = [ + versionConfig.versionCreator.set((VersionProperties.Creator) { v, p -> 'default' }) + versionConfig.branchVersionCreator.putAll([ 'some.*': { v, p -> 'someBranch' } - ] + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'someBranch') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'someBranch') then: rules.versionCreator.apply(null, null) == 'someBranch' @@ -142,29 +142,29 @@ class VersionPropertiesFactoryTest extends Specification { def "should use predefined version creator when supplied with String in per branch creators"() { given: - versionConfig.versionCreator = { v, p -> 'default' } - versionConfig.branchVersionCreator = [ + versionConfig.versionCreator((VersionProperties.Creator) { v, p -> 'default' }) + versionConfig.branchVersionCreator.putAll([ 'some.*': 'versionWithBranch' - ] + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'someBranch') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'someBranch') then: rules.versionCreator.apply('1.0.0', scmPosition('someBranch')) == '1.0.0-someBranch' } - def "should use version creator passed as command line option if present"() { given: - versionConfig.versionCreator = { v, p -> 'default' } - versionConfig.branchVersionCreator = [ + VersionConfig versionConfig = Fixtures.versionConfig(Fixtures.project(['release.versionCreator': 'simple'])) + + versionConfig.versionCreator.set((VersionProperties.Creator) { v, p -> 'default' }) + versionConfig.branchVersionCreator.putAll([ 'some.*': 'versionWithBranch' - ] - project.extensions.extraProperties.set('release.versionCreator', 'simple') + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'someBranch') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'someBranch') then: rules.versionCreator.apply('1.0.0', scmPosition('someBranch')) == '1.0.0' @@ -172,13 +172,13 @@ class VersionPropertiesFactoryTest extends Specification { def "should pick default version incrementer if none branch incrementers match"() { given: - versionConfig.versionIncrementer = {VersionIncrementerContext c -> c.currentVersion } - versionConfig.branchVersionIncrementer = [ + versionConfig.versionIncrementer({ VersionIncrementerContext c -> c.currentVersion }) + versionConfig.branchVersionIncrementer.putAll([ 'some.*': { c -> c.currentVersion.incrementMajorVersion() } - ] + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'master') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'master') then: rules.versionIncrementer.apply( @@ -188,13 +188,13 @@ class VersionPropertiesFactoryTest extends Specification { def "should pick version incrementer suitable for current branch if defined in per branch incrementer"() { given: - versionConfig.versionIncrementer = { c -> c.currentVersion } - versionConfig.branchVersionIncrementer = [ - 'some.*': { c -> c.currentVersion.incrementMajorVersion() } - ] + versionConfig.versionIncrementer({ c -> c.currentVersion }) + versionConfig.branchVersionIncrementer.putAll([ + 'some.*': { VersionIncrementerContext c -> c.currentVersion.incrementMajorVersion() } + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'someBranch') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'someBranch') then: rules.versionIncrementer.apply( @@ -204,13 +204,13 @@ class VersionPropertiesFactoryTest extends Specification { def "should use predefined incrementer creator when supplied with String in per branch incrementer"() { given: - versionConfig.versionCreator = { c -> c.currentVersion } - versionConfig.branchVersionIncrementer = [ + versionConfig.versionCreator({ c -> c.currentVersion }) + versionConfig.branchVersionIncrementer.putAll([ 'some.*': 'incrementMajor' - ] + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'someBranch') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'someBranch') then: rules.versionIncrementer.apply( @@ -220,13 +220,13 @@ class VersionPropertiesFactoryTest extends Specification { def "should use predefined incrementer creator with config options when supplied with String in per branch incrementer"() { given: - versionConfig.versionCreator = { c -> c.currentVersion } - versionConfig.branchVersionIncrementer = [ + versionConfig.versionCreator({ c -> c.currentVersion }) + versionConfig.branchVersionIncrementer.putAll([ 'some.*': ['incrementMinorIfNotOnRelease', [releaseBranchPattern: 'someOther.*']] - ] + ]) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'someBranch') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'someBranch') then: rules.versionIncrementer.apply( @@ -236,11 +236,12 @@ class VersionPropertiesFactoryTest extends Specification { def "should use incrementer passed as command line option if present"() { given: - versionConfig.versionCreator = { c -> c.currentVersion } - project.extensions.extraProperties.set('release.versionIncrementer', 'incrementMajor') + VersionConfig versionConfig = Fixtures.versionConfig(Fixtures.project(['release.versionIncrementer': 'incrementMajor'])) + + versionConfig.versionCreator({ c -> c.currentVersion }) when: - VersionProperties rules = VersionPropertiesFactory.create(project, versionConfig, 'someBranch') + VersionProperties rules = VersionPropertiesFactory.create(versionConfig, 'someBranch') then: rules.versionIncrementer.apply( diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactoryTest.groovy index a52e09ee..74a1e316 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/di/ScmRepositoryFactoryTest.groovy @@ -3,6 +3,7 @@ package pl.allegro.tech.build.axion.release.infrastructure.di import org.ajoberstar.grgit.Grgit import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder +import pl.allegro.tech.build.axion.release.Fixtures import pl.allegro.tech.build.axion.release.domain.RepositoryConfig import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties import pl.allegro.tech.build.axion.release.infrastructure.DummyRepository @@ -17,13 +18,13 @@ class ScmRepositoryFactoryTest extends Specification { Project project - RepositoryConfig config = new RepositoryConfig() + RepositoryConfig config def setup() { - project = ProjectBuilder.builder().build() + project = Fixtures.project() Grgit.init(dir: project.rootDir) - config.directory = project.rootDir + config = Fixtures.repositoryConfig(project) } def "should return git repository by default"() { @@ -36,7 +37,7 @@ class ScmRepositoryFactoryTest extends Specification { def "should return dummy repository when underlying repository is not initialized"() { given: - Project gitlessProject = ProjectBuilder.builder().build() + Project gitlessProject = Fixtures.project() ScmProperties properties = scmProperties(gitlessProject.rootDir).build() expect: diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepositoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepositoryTest.groovy index 7b763e66..57ce0a8c 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepositoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepositoryTest.groovy @@ -16,7 +16,7 @@ import java.util.regex.Pattern import static java.util.regex.Pattern.compile import static pl.allegro.tech.build.axion.release.TagPrefixConf.fullPrefix -import static pl.allegro.tech.build.axion.release.TagPrefixConf.prefix +import static pl.allegro.tech.build.axion.release.TagPrefixConf.defaultPrefix import static pl.allegro.tech.build.axion.release.domain.scm.ScmPropertiesBuilder.scmProperties class GitRepositoryTest extends Specification { @@ -71,7 +71,7 @@ class GitRepositoryTest extends Specification { when: lightweightTagRepository.tag(fullPrefix() + '2') - TagsOnCommit tags = lightweightTagRepository.latestTags(compile('^' + prefix() + '.*')) + TagsOnCommit tags = lightweightTagRepository.latestTags(compile('^' + defaultPrefix() + '.*')) then: tags.tags == [fullPrefix() + '1', fullPrefix() + '2'] @@ -132,7 +132,7 @@ class GitRepositoryTest extends Specification { repository.commit(['*'], "commit after release") when: - TagsOnCommit tags = repository.latestTags(Pattern.compile('^' + prefix() + '.*')) + TagsOnCommit tags = repository.latestTags(Pattern.compile('^' + defaultPrefix() + '.*')) then: tags.tags == [fullPrefix() + '1'] @@ -143,7 +143,7 @@ class GitRepositoryTest extends Specification { GitRepository commitlessRepository = GitProjectBuilder.gitProject(File.createTempDir('axion-release', 'tmp')).build()[GitRepository] when: - TagsOnCommit tags = commitlessRepository.latestTags(Pattern.compile('^' + prefix() + '.*')) + TagsOnCommit tags = commitlessRepository.latestTags(Pattern.compile('^' + defaultPrefix() + '.*')) then: tags.tags == [] @@ -154,7 +154,7 @@ class GitRepositoryTest extends Specification { repository.tag(fullPrefix() + '1') when: - TagsOnCommit tags = repository.latestTags(Pattern.compile('' + prefix() + '.*')) + TagsOnCommit tags = repository.latestTags(Pattern.compile('' + defaultPrefix() + '.*')) then: tags.tags == [fullPrefix() + '1'] @@ -171,7 +171,7 @@ class GitRepositoryTest extends Specification { repository.commit(['*'], "bugfix after " + fullPrefix() + "1") when: - TagsOnCommit tags = repository.latestTags(Pattern.compile("^" + prefix() + ".*")) + TagsOnCommit tags = repository.latestTags(Pattern.compile("^" + defaultPrefix() + ".*")) then: tags.tags == [fullPrefix() + '1'] @@ -192,7 +192,7 @@ class GitRepositoryTest extends Specification { repository.commit(['*'], "commit after " + fullPrefix() + "3") when: - List allTaggedCommits = repository.taggedCommits(Pattern.compile('^' + prefix() + '.*')) + List allTaggedCommits = repository.taggedCommits(Pattern.compile('^' + defaultPrefix() + '.*')) then: allTaggedCommits.collect { c -> c.tags[0] } == [fullPrefix() +'3',fullPrefix() + '4', fullPrefix() + '2', fullPrefix() +'1'] @@ -205,7 +205,7 @@ class GitRepositoryTest extends Specification { repository.tag('otherTag') when: - TagsOnCommit tags = repository.latestTags(Pattern.compile('^' + prefix() + '.*')) + TagsOnCommit tags = repository.latestTags(Pattern.compile('^' + defaultPrefix() + '.*')) then: tags.tags == [fullPrefix() + '1'] @@ -232,7 +232,7 @@ class GitRepositoryTest extends Specification { repository.tag(fullPrefix() + '2') when: - TagsOnCommit tags = repository.latestTags(Pattern.compile('^' + prefix() + '.*')) + TagsOnCommit tags = repository.latestTags(Pattern.compile('^' + defaultPrefix() + '.*')) then: tags.tags == [fullPrefix() + '1', fullPrefix() + '2'] diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/DryRepositoryTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/NoOpRepositoryTest.groovy similarity index 89% rename from src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/DryRepositoryTest.groovy rename to src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/NoOpRepositoryTest.groovy index c633fbe6..969a0756 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/DryRepositoryTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/NoOpRepositoryTest.groovy @@ -4,14 +4,14 @@ import pl.allegro.tech.build.axion.release.domain.scm.ScmIdentity import pl.allegro.tech.build.axion.release.domain.scm.ScmPushOptions import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository import pl.allegro.tech.build.axion.release.domain.scm.TagsOnCommit -import pl.allegro.tech.build.axion.release.infrastructure.DryRepository +import pl.allegro.tech.build.axion.release.infrastructure.NoOpRepository import spock.lang.Specification -class DryRepositoryTest extends Specification { +class NoOpRepositoryTest extends Specification { ScmRepository scm = Mock(ScmRepository) - DryRepository dryRepository = new DryRepository(scm) + NoOpRepository dryRepository = new NoOpRepository(scm) def "should not create actual tags in scm"() { when: