Added gitflow version plugin

This commit is contained in:
Christian Basler 2017-01-23 17:26:33 +01:00
parent d1215c6e12
commit e6b35c5f5b
3 changed files with 60 additions and 2 deletions

View File

@ -5,7 +5,7 @@ apply plugin: 'jacoco'
apply plugin: 'gitflow-version'
sourceCompatibility = 1.7
group = 'ch.dissem.jabit'
group = 'ch.dissem.msgpack'
repositories {
mavenCentral()
@ -56,7 +56,7 @@ uploadArchives {
pom.project {
name 'msgpack'
packaging 'jar'
url 'https://github.com/Dissem/msgpack'
url 'https://dissem.ch/msgpack'
scm {
connection 'scm:git:https://github.com/Dissem/msgpack.git'

View File

@ -0,0 +1,57 @@
package ch.dissem.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* Sets the version as follows:
* <ul>
* <li>If the branch is 'master', the version is set to the latest tag (which is expected to be set by Git flow)</li>
* <li>Otherwise, the version is set to the branch name, with '-SNAPSHOT' appended</li>
* </ul>
*/
class GitFlowVersion implements Plugin<Project> {
def getBranch(Project project) {
def stdout = new ByteArrayOutputStream()
project.exec {
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
def getTag(Project project) {
def stdout = new ByteArrayOutputStream()
project.exec {
commandLine 'git', 'describe', '--abbrev=0'
standardOutput = stdout
}
return stdout.toString().trim()
}
def isRelease(Project project) {
return "master" == getBranch(project);
}
def getVersion(Project project) {
if (project.ext.isRelease) {
return getTag(project)
} else {
def branch = getBranch(project)
if ("develop" == branch) {
return "development-SNAPSHOT"
}
return branch.replaceAll("/", "-") + "-SNAPSHOT"
}
}
@Override
void apply(Project project) {
project.ext.isRelease = isRelease(project)
project.version = getVersion(project)
project.task('version') << {
println "Version deduced from git: '${project.version}'"
}
}
}

View File

@ -0,0 +1 @@
implementation-class=ch.dissem.gradle.GitFlowVersion