diff options
author | LexManos <LexManos@gmail.com> | 2021-05-26 10:43:30 -0700 |
---|---|---|
committer | LexManos <LexManos@gmail.com> | 2021-05-26 10:43:46 -0700 |
commit | 12aeb6f4c7c09e749204707475a7f71b16c14133 (patch) | |
tree | 4b0dcfaeb5c368d7e8e5aa23ceca212592cd8ad7 | |
parent | 4b39e3af8d3c0fe9f0ae03391715ff586bccf56d (diff) | |
download | Artifactural-12aeb6f4c7c09e749204707475a7f71b16c14133.tar.gz Artifactural-12aeb6f4c7c09e749204707475a7f71b16c14133.tar.bz2 Artifactural-12aeb6f4c7c09e749204707475a7f71b16c14133.zip |
Move to jgit as grgit is no longer being published and start 3.0 cycle.
-rw-r--r-- | build.gradle | 63 |
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() +} + |