Repository: incubator-geode Updated Branches: refs/heads/feature/GEODE-151 [created] aab056851
GEODE-151: Convert to use Gradle Git plugin The build was using the executable git command to populate version information, which created big blocks of Gradle code and could be unstable. All Git executable commands have been changed to use the Gradle Git plugin. If directory is not a valid Git workspace, then it will log a warning and use default values to populate version information. Tested with and without Git workspace Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/aab05685 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/aab05685 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/aab05685 Branch: refs/heads/feature/GEODE-151 Commit: aab056851334504c11000f52d88d2d0fadb14abe Parents: 5a0d43e Author: Mark Bretl <[email protected]> Authored: Mon Nov 16 10:44:50 2015 -0800 Committer: Mark Bretl <[email protected]> Committed: Mon Nov 16 10:44:50 2015 -0800 ---------------------------------------------------------------------- build.gradle | 13 ++++++++- gemfire-core/build.gradle | 64 +++++++++++++----------------------------- 2 files changed, 31 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aab05685/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index e3b1033..a186710 100755 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,15 @@ -apply plugin: 'wrapper' +buildscript { + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + classpath "org.ajoberstar:gradle-git:1.3.2" + } +} +apply plugin: 'wrapper' // Load all properties in dependency-version.properties as project properties, so all projects can read them Properties dependencyVersions = new Properties() @@ -25,6 +35,7 @@ allprojects { group = "org.apache.geode" + apply plugin: 'org.ajoberstar.grgit' apply plugin: 'idea' apply plugin: 'eclipse' http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aab05685/gemfire-core/build.gradle ---------------------------------------------------------------------- diff --git a/gemfire-core/build.gradle b/gemfire-core/build.gradle index 80761ed..ad1fa22 100755 --- a/gemfire-core/build.gradle +++ b/gemfire-core/build.gradle @@ -99,58 +99,32 @@ task createVersionPropertiesFile { inputs.dir compileJava.destinationDir doLast { - new ByteArrayOutputStream().withStream { gitWorkspaceStream -> - def result = exec { - workingDir = "${projectDir}" - standardOutput = gitWorkspaceStream - ignoreExitValue = true - executable = "git" - args = ['rev-parse', '--is-inside-work-tree'] - } - ext.isGitWorkspace = gitWorkspaceStream.toString() - ext.isGitWorkspace = ext.isGitWorkspace.trim() + + ext.isGitWorkspace = true + try { + def grgit = org.ajoberstar.grgit.Grgit.open() + //def grgit = org.ajoberstar.grgit.Grgit.open(dir: 'asdf') + } catch (Exception e) { + logger.warn( '***** Unable to find Git workspace *****' ) + logger.warn( '***** Using default version information *****' ) + isGitWorkspace = false } - if ( isGitWorkspace.equalsIgnoreCase('true') ) { - new ByteArrayOutputStream().withStream { gitBranchStream -> - def result = exec { - workingDir = "${projectDir}" - standardOutput = gitBranchStream - executable = "git" - args = ['rev-parse', '--abbrev-ref', 'HEAD'] - } - ext.gitBranchString = gitBranchStream.toString() - ext.gitBranch = ext.gitBranchString.trim() - } - - new ByteArrayOutputStream().withStream { commitStream -> - def result = exec { - workingDir = "${projectDir}" - standardOutput = commitStream - executable = "git" - args = ['rev-parse', 'HEAD'] - } - ext.commitIdString = commitStream.toString() - ext.commitId = ext.commitIdString.trim() - } - - new ByteArrayOutputStream().withStream { sourceDateStream -> - def result = exec { - workingDir = "${projectDir}" - standardOutput = sourceDateStream - executable = "git" - args = ['show', '-s', '--format=%ci', "${ext.commitId}"] - } - ext.sourceDateString = sourceDateStream.toString() - ext.sourceDate = ext.sourceDateString.trim() - } + if ( ext.isGitWorkspace ) { + ext.branch = grgit.branch.getCurrent().name + ext.commitId = grgit.head().id + ext.sourceDate = grgit.head().getDate().format('yyyy-MM-dd HH:mm:ss Z') + logger.info( '***** Current Branch: ' + ext.branch + ' ******' ) + logger.info( '***** Current ID: ' + ext.commitId + ' ******' ) + logger.info( '***** Current Date: ' + ext.sourceDate + ' ******' ) } else { // Not in SCM workspace, use default values - ext.gitBranch = 'UNKNOWN' + ext.branch = 'UNKNOWN' ext.commitId = 'UNKNOWN' ext.sourceDate = new Date().format('yyyy-MM-dd HH:mm:ss Z') } + grgit.close() ext.osArch = System.getProperty('os.arch') ext.osName = System.getProperty('os.name') @@ -168,7 +142,7 @@ task createVersionPropertiesFile { "Build-Java-Version": ext.jdkVersion, "Source-Date" : ext.sourceDate, "Source-Revision" : ext.commitId, - "Source-Repository" : ext.gitBranch + "Source-Repository" : ext.branch ] as Properties propertiesFile.getParentFile().mkdirs();
