diff options
author | LexManos <LexManos@gmail.com> | 2021-05-26 10:46:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-26 10:46:04 -0700 |
commit | c3948938178810000353830671e474abb9d32a2c (patch) | |
tree | 22e8db707b69b433463446b0709f93a6df65c27f /build.gradle | |
parent | a4fe3e095ffdffb6022327def06744948d061571 (diff) | |
parent | 12aeb6f4c7c09e749204707475a7f71b16c14133 (diff) | |
download | Artifactural-c3948938178810000353830671e474abb9d32a2c.tar.gz Artifactural-c3948938178810000353830671e474abb9d32a2c.tar.bz2 Artifactural-c3948938178810000353830671e474abb9d32a2c.zip |
Merge branch 'master' into theUnsafe
Diffstat (limited to 'build.gradle')
-rw-r--r-- | build.gradle | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/build.gradle b/build.gradle index ec0d95f..8155cf7 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 'org.cadixdev.licenser' version '0.6.0' - 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 { @@ -121,3 +129,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() +} + |