Created
October 9, 2015 13:36
-
-
Save bugs84/529f1582eb1189d09a25 to your computer and use it in GitHub Desktop.
Gradle get hg mercurial changeset revision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.aragost.javahg:javahg:0.4' | |
} | |
} | |
task revision << { | |
println "Build revision: $scmRevision" | |
} | |
import com.aragost.javahg.Changeset | |
import com.aragost.javahg.Repository | |
import com.aragost.javahg.commands.ParentsCommand | |
String getHgRevision() { | |
def repo = Repository.open(projectDir) | |
def parentsCommand = new ParentsCommand(repo) | |
List<Changeset> changesets = parentsCommand.execute() | |
if (changesets == null || changesets.size() != 1) { | |
def message = "Exactly one was parent expected. " + changesets | |
throw new Exception(message) | |
} | |
return changesets[0].node | |
} | |
ext { | |
scmRevision = getHgRevision() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment