aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle63
1 files changed, 61 insertions, 2 deletions
diff --git a/build.gradle b/build.gradle
index a1aa9e9..cb11dcb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,14 +1,22 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
+ }
+}
+
plugins {
id 'java-library'
id 'maven-publish'
id 'eclipse'
id 'net.minecrell.licenser' version '0.3'
- id 'org.ajoberstar.grgit' version '4.1.0'
}
group = 'net.minecraftforge'
-version = (grgit.describe(longDescr: true, tags: true) ?: 'unknown-unknown-unknown').split('-').with { "${it[0]}.${it[1]}" }
+version = gitVersion()
println('Version: ' + version + ' Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
sourceSets {
@@ -160,3 +168,54 @@ publishing {
}
}
+def gitInfo(dir) {
+ String.metaClass.rsplit = { String del, int limit = -1 ->
+ def lst = new ArrayList()
+ def x = 0, idx
+ def tmp = delegate
+ while ((idx = tmp.lastIndexOf(del)) != -1 && (limit == -1 || x++ < limit)) {
+ lst.add(0, tmp.substring(idx + del.length(), tmp.length()))
+ tmp = tmp.substring(0, idx)
+ }
+ lst.add(0, tmp)
+ return lst
+ }
+
+ def git = null
+ try {
+ git = org.eclipse.jgit.api.Git.open(dir)
+ } catch (org.eclipse.jgit.errors.RepositoryNotFoundException e) {
+ return [
+ tag: '0.0',
+ offset: '0',
+ hash: '00000000',
+ branch: 'master',
+ commit: '0000000000000000000000',
+ abbreviatedId: '00000000'
+ ]
+ }
+ def desc = git.describe().setLong(true).setTags(true).call().rsplit('-', 2)
+ def head = git.repository.exactRef('HEAD')
+ def longBranch = head.symbolic ? head?.target?.name : null // matches Repository.getFullBranch() but returning null when on a detached HEAD
+
+ def ret = [:]
+ ret.tag = desc[0]
+ ret.offset = desc[1]
+ ret.hash = desc[2]
+ ret.branch = longBranch != null ? org.eclipse.jgit.lib.Repository.shortenRefName(longBranch) : null
+ ret.commit = org.eclipse.jgit.lib.ObjectId.toString(head.objectId)
+ ret.abbreviatedId = head.objectId.abbreviate(8).name()
+
+ return ret
+}
+
+def gitVersion() {
+ def info = gitInfo(rootProject.file('.'))
+ def branch = info.branch
+ if (branch != null && branch.startsWith('pulls/'))
+ branch = 'pr' + branch.rsplit('/', 1)[1]
+ if (branch in [null, 'master', 'HEAD'])
+ return "${info.tag}.${info.offset}".toString()
+ return "${info.tag}.${info.offset}-${branch}".toString()
+}
+