Skip to content

Commit f7efad2

Browse files
JaciBrunningJLLeitschuh
authored andcommitted
Use grgit (#757)
1 parent ada49ce commit f7efad2

File tree

2 files changed

+24
-39
lines changed

2 files changed

+24
-39
lines changed

build.gradle

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ plugins {
3333
id 'com.google.osdetector' version '1.4.0'
3434
id 'com.github.johnrengelman.shadow' version '1.2.3'
3535
id "com.dorongold.task-tree" version "1.2.2"
36+
id 'org.ajoberstar.grgit' version '1.6.0' apply false
3637
}
3738
apply plugin: 'nebula-aggregate-javadocs'
39+
apply from: 'git.gradle'
3840

3941
buildScan {
4042
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
@@ -48,15 +50,6 @@ allprojects {
4850
}
4951
}
5052

51-
def getGitCommit = { ->
52-
def stdout = new ByteArrayOutputStream()
53-
exec {
54-
commandLine 'git', 'rev-parse', '--short', 'HEAD'
55-
standardOutput = stdout
56-
}
57-
return stdout.toString().trim()
58-
}
59-
6053
idea.project {
6154
ipr.withXml { provider ->
6255
def node = provider.asNode()
@@ -78,40 +71,12 @@ idea.project {
7871
*/
7972
def getVersionName = { ->
8073
if (project.hasProperty("vers")) return vers
81-
try {
82-
def stdout = new ByteArrayOutputStream()
83-
exec {
84-
commandLine 'git', 'describe', '--tags'
85-
standardOutput = stdout
86-
}
87-
return stdout.toString().trim().substring(1)
88-
} catch (org.gradle.process.internal.ExecException e) {
89-
if (!new File(rootDir, '.git/HEAD').exists()) {
90-
println("WARN: Could not fetch Git Tag for build version. No Git HEAD available. Substituting version 0.0.0")
91-
return "0.0.0"
92-
}
93-
println("WARN: Could not fetch Git Tag for build version. Please install Git and add it to your PATH. For now, the Git commit hash has been substituted.")
94-
return getGitCommit()
95-
}
74+
return getGitDescribe()
9675
}
9776

9877
def getVersionSimple = { ->
9978
if (project.hasProperty("vers")) return vers
100-
try {
101-
def stdout = new ByteArrayOutputStream()
102-
exec {
103-
commandLine 'git', 'describe', '--tags', '--abbrev=0'
104-
standardOutput = stdout
105-
}
106-
return stdout.toString().trim().substring(1)
107-
} catch (org.gradle.process.internal.ExecException e) {
108-
if (!new File(rootDir, '.git/HEAD').exists()) {
109-
println("WARN: Could not fetch Git Tag for build version. No Git HEAD available. Substituting version 0.0.0")
110-
return "0.0.0"
111-
}
112-
println("WARN: Could not fetch Git Tag for build version. Please install Git and add it to your PATH. For now, the Git commit hash has been substituted.")
113-
return getGitCommit()
114-
}
79+
return getGitDescribeAbbrev()
11580
}
11681

11782
configure(subprojects - project(':ui:linuxLauncher')) {

git.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def git_provided = false
2+
if (rootProject.file(".git").exists()) {
3+
git_provided = true
4+
project.apply plugin: 'org.ajoberstar.grgit'
5+
}
6+
7+
ext.getGitCommit = { ->
8+
if (git_provided) return grgit.head().abbreviatedId
9+
return "<no commit>"
10+
}
11+
12+
ext.getGitDescribe = { ->
13+
if (git_provided) return grgit.describe()
14+
return "v0.0.0"
15+
}
16+
17+
ext.getGitDescribeAbbrev = { ->
18+
if (git_provided) return grgit.tag.list().last().getName()
19+
return "v0.0.0"
20+
}

0 commit comments

Comments
 (0)