Skip to content

Commit 4210d64

Browse files
authored
Switch to build tools git processing logic (#1472)
1 parent 97a8690 commit 4210d64

File tree

3 files changed

+5
-49
lines changed

3 files changed

+5
-49
lines changed

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/BaseBuildPlugin.groovy

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,8 @@ class BaseBuildPlugin implements Plugin<Project> {
147147
if (!project.rootProject.ext.has('settingsConfigured')) {
148148
// Force any Elasticsearch test clusters to use packaged java versions if they have them available
149149
project.rootProject.ext.isRuntimeJavaHomeSet = false
150-
151-
File gitHead = gitBranch(project)
152-
project.rootProject.ext.gitHead = gitHead
153-
project.rootProject.ext.revHash = gitHash(gitHead)
154150
project.rootProject.ext.settingsConfigured = true
155151
}
156-
project.ext.gitHead = project.rootProject.ext.gitHead
157-
project.ext.revHash = project.rootProject.ext.revHash
158152
project.ext.javaVersions = BuildParams.javaVersions
159153
project.ext.isRuntimeJavaHomeSet = project.rootProject.ext.isRuntimeJavaHomeSet
160154
}
@@ -197,44 +191,4 @@ class BaseBuildPlugin implements Plugin<Project> {
197191
}
198192
}
199193
}
200-
201-
/**
202-
* @param project that belongs to a git repo
203-
* @return the file containing the hash for the current branch
204-
*/
205-
private static File gitBranch(Project project) {
206-
// parse the git files to find out the revision
207-
File gitHead = project.file("${project.rootDir}/.git/HEAD")
208-
if (gitHead != null && !gitHead.exists()) {
209-
// Try as a sub module
210-
File subModuleGit = project.file("${project.rootDir}/.git")
211-
if (subModuleGit != null && subModuleGit.exists()) {
212-
String content = subModuleGit.text.trim()
213-
if (content.startsWith("gitdir:")) {
214-
gitHead = project.file("${project.rootDir}/" + content.replace('gitdir: ','') + "/HEAD")
215-
}
216-
}
217-
}
218-
219-
if (gitHead != null && gitHead.exists()) {
220-
String content = gitHead.text.trim()
221-
if (content.startsWith("ref:")) {
222-
return project.file("${project.rootDir}/.git/" + content.replace('ref: ',''))
223-
}
224-
return gitHead
225-
}
226-
return null
227-
}
228-
229-
/**
230-
* @param gitHead file containing the the currently checked out ref
231-
* @return the current commit version hash
232-
*/
233-
private static String gitHash(File gitHead) {
234-
String rev = "unknown"
235-
if (gitHead != null && gitHead.exists()) {
236-
rev = gitHead.text.trim()
237-
}
238-
return rev
239-
}
240194
}

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/BuildPlugin.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.elasticsearch.hadoop.gradle
22

33
import org.elasticsearch.gradle.DependenciesInfoTask
4+
import org.elasticsearch.gradle.info.BuildParams
45
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
56
import org.elasticsearch.gradle.precommit.LicenseHeadersTask
67
import org.elasticsearch.gradle.precommit.UpdateShasTask
@@ -231,7 +232,7 @@ class BuildPlugin implements Plugin<Project> {
231232
manifest.attributes['Implementation-URL'] = "https://github.com/elastic/elasticsearch-hadoop"
232233
manifest.attributes['Implementation-Vendor'] = "Elastic"
233234
manifest.attributes['Implementation-Vendor-Id'] = "org.elasticsearch.hadoop"
234-
manifest.attributes['Repository-Revision'] = project.ext.revHash
235+
manifest.attributes['Repository-Revision'] = BuildParams.gitRevision
235236
String build = System.env['ESHDP.BUILD']
236237
if (build != null) {
237238
manifest.attributes['Build'] = build

mr/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.elasticsearch.gradle.info.BuildParams
12

23
apply plugin: 'es.hadoop.build.integration'
34

@@ -36,13 +37,13 @@ sourceSets {
3637
}
3738

3839
task generateGitHash {
39-
inputs.file project.ext.gitHead
40+
inputs.property "revision", BuildParams.gitRevision
4041
outputs.dir generatedResources
4142

4243
doLast {
4344
Properties props = new Properties()
4445
props.put("version", version)
45-
props.put("hash", project.ext.revHash)
46+
props.put("hash", BuildParams.gitRevision)
4647
File output = new File(generatedResources, "esh-build.properties")
4748
new File(generatedResources).mkdirs()
4849
output.createNewFile()

0 commit comments

Comments
 (0)