From e6b35c5f5ba9ecb0ede638d552b6235b8afe8be6 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Mon, 23 Jan 2017 17:26:33 +0100 Subject: [PATCH] Added gitflow version plugin --- build.gradle | 4 +- .../ch/dissem/gradle/GitFlowVersion.groovy | 57 +++++++++++++++++++ .../gradle-plugins/gitflow-version.properties | 1 + 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 buildSrc/src/main/groovy/ch/dissem/gradle/GitFlowVersion.groovy create mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/gitflow-version.properties diff --git a/build.gradle b/build.gradle index 3dfcde7..903abe3 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/buildSrc/src/main/groovy/ch/dissem/gradle/GitFlowVersion.groovy b/buildSrc/src/main/groovy/ch/dissem/gradle/GitFlowVersion.groovy new file mode 100644 index 0000000..869d57e --- /dev/null +++ b/buildSrc/src/main/groovy/ch/dissem/gradle/GitFlowVersion.groovy @@ -0,0 +1,57 @@ +package ch.dissem.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project + +/** + * Sets the version as follows: + * + */ +class GitFlowVersion implements Plugin { + 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}'" + } + } +} diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/gitflow-version.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/gitflow-version.properties new file mode 100644 index 0000000..1fb4f78 --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/gitflow-version.properties @@ -0,0 +1 @@ +implementation-class=ch.dissem.gradle.GitFlowVersion