diff --git a/README.asciidoc b/README.asciidoc index 8dfbcc3..160d918 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -1,5 +1,5 @@ = GitFlow Version Plugin -:latestRevision: 1.0.2 +:latestRevision: 1.10.0 :toc: :icons: font @@ -93,6 +93,7 @@ gitflowVersion { defaultVersion = "2.0.0" mainBranch = "master" developBranch = "develop" + majorBranch = "major" hotfixPrefix = "hotfix" featurePrefix = "feature" releasePrefix = "release" @@ -123,6 +124,9 @@ Example: release/7.11 -> '7.11.0.0-SNAPSHOT' (Version type is 'four') * Support branches (support) The version is calculated from tags. The branch is used for LTS releases after a new major version is created. +* Major branch +The version is always -SNAPSHOT. The branch is a feature branch with major changes, therefore the prefix is always feature. So the complete default path is feature/major. + == Tasks [cols="20%,15%,65%", width="95%", options="header"] diff --git a/build.gradle.kts b/build.gradle.kts index e904494..b4c2bbb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,7 +51,7 @@ plugins { // release configuration group = "com.intershop.gradle.version" description = "Gradle SCM version plugin - SCM based version handling for Gradle" -version = "1.9.0" +version = "1.10.0" val sonatypeUsername: String by project @@ -252,7 +252,7 @@ dependencies { exclude(group = "org.slf4j", module = "slf4j-api") } - testRuntimeOnly("org.apache.httpcomponents:httpclient:4.5.6") + testRuntimeOnly("org.apache.httpcomponents:httpclient:4.5.13") testRuntimeOnly("org.slf4j:slf4j-api:1.7.25") testImplementation("com.github.stefanbirkner:system-rules:1.19.0" ) @@ -260,5 +260,5 @@ dependencies { testImplementation("com.intershop.gradle.test:test-gradle-plugin:4.1.1") testImplementation(gradleTestKit()) - testImplementation("commons-io:commons-io:2.2") + testImplementation("commons-io:commons-io:2.7") } diff --git a/src/main/kotlin/com/intershop/gradle/gitflow/extension/VersionExtension.kt b/src/main/kotlin/com/intershop/gradle/gitflow/extension/VersionExtension.kt index 276aac1..d6ec9ca 100644 --- a/src/main/kotlin/com/intershop/gradle/gitflow/extension/VersionExtension.kt +++ b/src/main/kotlin/com/intershop/gradle/gitflow/extension/VersionExtension.kt @@ -47,6 +47,7 @@ open class VersionExtension @Inject constructor(project: Project, private val defaultVersionProperty = objectFactory.property(String::class.java) private val mainBranchProperty = objectFactory.property(String::class.java) private val developBranchProperty = objectFactory.property(String::class.java) + private val majorBranchProperty = objectFactory.property(String::class.java) private val hotfixPrefixProperty = objectFactory.property(String::class.java) private val featurePrefixProperty = objectFactory.property(String::class.java) private val releasePrefixProperty = objectFactory.property(String::class.java) @@ -67,6 +68,7 @@ open class VersionExtension @Inject constructor(project: Project, defaultVersionProperty.convention("1.0.0") mainBranchProperty.convention("master") developBranchProperty.convention("develop") + majorBranchProperty.convention("major") hotfixPrefixProperty.convention("hotfix") featurePrefixProperty.convention("feature") releasePrefixProperty.convention("release") @@ -122,6 +124,19 @@ open class VersionExtension @Inject constructor(project: Project, get() = developBranchProperty.get() set(value) = developBranchProperty.set(value) + /** + * This is provider for the developBranch property. + */ + val majorBranchProvider: Provider + get() = majorBranchProperty + + /** + * This is developBranch property. + */ + var majorBranch : String + get() = majorBranchProperty.get() + set(value) = majorBranchProperty.set(value) + /** * This is provider for the hotfixPrefix property. */ @@ -241,6 +256,7 @@ open class VersionExtension @Inject constructor(project: Project, versionService.defaultVersion = Version.forString(defaultVersionProperty.get(), vType) versionService.mainBranch = mainBranchProperty.get() versionService.developBranch = developBranchProperty.get() + versionService.majorBranch = majorBranchProperty.get() versionService.featurePrefix = featurePrefixProperty.get() versionService.hotfixPrefix = hotfixPrefixProperty.get() versionService.releasePrefix = releasePrefixProperty.get() diff --git a/src/main/kotlin/com/intershop/gradle/gitflow/utils/GitVersionService.kt b/src/main/kotlin/com/intershop/gradle/gitflow/utils/GitVersionService.kt index de9a40c..80e1321 100644 --- a/src/main/kotlin/com/intershop/gradle/gitflow/utils/GitVersionService.kt +++ b/src/main/kotlin/com/intershop/gradle/gitflow/utils/GitVersionService.kt @@ -17,6 +17,7 @@ package com.intershop.gradle.gitflow.utils import com.intershop.release.version.Version import com.intershop.release.version.VersionType +import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion.getLatestVersion import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.errors.JGitInternalException import org.eclipse.jgit.lib.Constants @@ -95,6 +96,13 @@ class GitVersionService @JvmOverloads constructor( */ var developBranch: String = "develop" + /** + * Name/path of the feature branch with major + * changes for the next major version. + * The branch starts with feature. + */ + var majorBranch: String = "major" + /** * Prefix of a hotfix branch. * Default value is hotfix. @@ -174,9 +182,9 @@ class GitVersionService @JvmOverloads constructor( private val changed: Boolean by lazy { val status = client.status().call() - val rv = status.untracked.size > 0 || status.uncommittedChanges.size > 0 || - status.removed.size > 0 || status.added.size > 0 || - status.changed.size > 0 || status.modified.size > 0 + val rv = status.untracked.isNotEmpty() || status.uncommittedChanges.isNotEmpty() || + status.removed.isNotEmpty() || status.added.isNotEmpty() || + status.changed.isNotEmpty()|| status.modified.isNotEmpty() if(log.isInfoEnabled && rv) { log.info("There are local changes on the repository.") @@ -325,7 +333,7 @@ class GitVersionService @JvmOverloads constructor( val versionWithID: String by lazy { val tag = getVersionTagFrom(Constants.HEAD) - var rv: String + val rv: String if(! localOnly) { @@ -376,7 +384,7 @@ class GitVersionService @JvmOverloads constructor( val version: String by lazy { val tag = getVersionTagFrom(Constants.HEAD) - var rv: String + val rv: String if(! localOnly) { when { @@ -428,7 +436,7 @@ class GitVersionService @JvmOverloads constructor( */ val containerVersion: String by lazy { val tag = getVersionTagFrom(Constants.HEAD) - var rv: String + val rv: String if(! localOnly) { when { @@ -544,6 +552,11 @@ class GitVersionService @JvmOverloads constructor( val bname = branchName.substring("${prefix}${separator}".length) val sname = bname.split("/".toRegex(), 2) + + if(prefix == featurePrefix && bname == majorBranch) { + return majorBranch + } + val fname = if(sname.size > 1) { sname[1].replace("/", "_").shortened() } else { diff --git a/src/test/groovy/com/intershop/gradle/gitflow/GitIntegrationSpecialSpec.groovy b/src/test/groovy/com/intershop/gradle/gitflow/GitIntegrationSpecialSpec.groovy index 6cab194..3db2cd6 100644 --- a/src/test/groovy/com/intershop/gradle/gitflow/GitIntegrationSpecialSpec.groovy +++ b/src/test/groovy/com/intershop/gradle/gitflow/GitIntegrationSpecialSpec.groovy @@ -57,6 +57,18 @@ class GitIntegrationSpecialSpec extends AbstractIntegrationGroovySpec { println(" - develop -> dev-SNAPSHOT") preVersion == null println(' - develop -> pre version is null') + + when: 'on master' + creator.setBranch("feature/major") + gvs = getConfGitVersionService(creator.directory) + version = gvs.version + preVersion = null + + then: 'version is major-SNAPSHOT' + version == "major-SNAPSHOT" + println(" - feature/major -> major-SNAPSHOT") + preVersion == null + println(' - feature/major -> pre version is null') } } diff --git a/src/test/groovy/com/intershop/gradle/gitflow/utils/GitCreatorSpecialVersions.groovy b/src/test/groovy/com/intershop/gradle/gitflow/utils/GitCreatorSpecialVersions.groovy index 0381245..bfba87e 100644 --- a/src/test/groovy/com/intershop/gradle/gitflow/utils/GitCreatorSpecialVersions.groovy +++ b/src/test/groovy/com/intershop/gradle/gitflow/utils/GitCreatorSpecialVersions.groovy @@ -38,6 +38,9 @@ class GitCreatorSpecialVersions { creator.createBranch("feature/JIRA-2", cDevelop) creator.createCommits("jira2", 3) + creator.setBranch("develop") + creator.createBranch("feature/major", cDevelop) + return creator }