Skip to content

Commit

Permalink
Merge pull request #13 from IntershopCommunicationsAG/feature/add-fea…
Browse files Browse the repository at this point in the history
…turemajor-branch

feature: change build number for special feature/major branch
  • Loading branch information
m-raab committed Nov 22, 2023
2 parents a4a349d + 866c773 commit 8deb990
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
6 changes: 5 additions & 1 deletion README.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= GitFlow Version Plugin
:latestRevision: 1.0.2
:latestRevision: 1.10.0
:toc:
:icons: font

Expand Down Expand Up @@ -93,6 +93,7 @@ gitflowVersion {
defaultVersion = "2.0.0"
mainBranch = "master"
developBranch = "develop"
majorBranch = "major"
hotfixPrefix = "hotfix"
featurePrefix = "feature"
releasePrefix = "release"
Expand Down Expand Up @@ -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 <major_branch_name>-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"]
Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -252,13 +252,13 @@ 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" )

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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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<String>
get() = majorBranchProperty

/**
* This is developBranch property.
*/
var majorBranch : String
get() = majorBranchProperty.get()
set(value) = majorBranchProperty.set(value)

/**
* This is provider for the hotfixPrefix property.
*/
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 8deb990

Please sign in to comment.