Mercurial > public > develkit
changeset 178:5a3a875a1f3e
cleanup branch handling
author | smith@nwoca.org |
---|---|
date | Sat, 13 Dec 2014 18:43:34 +0000 |
parents | 629ee17d6f39 |
children | f9087f939b0a |
files | init20.gradle |
diffstat | 1 files changed, 54 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/init20.gradle Sat Dec 13 17:11:06 2014 +0000 +++ b/init20.gradle Sat Dec 13 18:43:34 2014 +0000 @@ -1,4 +1,5 @@ import groovy.sql.Sql +import groovy.transform.ToString final GradleVersion gradleCurrent = GradleVersion.current() final GradleVersion gradleV20 = GradleVersion.version('2.0') @@ -54,35 +55,19 @@ } } - -gradle.ext.branchName = System.getenv('bamboo_planRepository_branch') -gradle.ext.branchStream = "" - -if (!gradle.branchName) { - gradle.ext.branchName = "hg branch".execute().text.trim() - def rawParents = 'hg parents'.execute().text - def parent = rawParents.split('\n').find { it.startsWith("branch") }?.split(":")?.getAt(1)?.trim() - gradle.ext.branchName = parent ?: gradle.branchName -} +gradle.ext.branch = new BranchInfo(System.getenv('bamboo_planRepository_branch')) +gradle.ext.branchName = gradle.branch.name +gradle.ext.branchStream = gradle.branch.stream +gradle.ext.branchHash = gradle.branch.hash +println "${gradle.hgRepositoryUrl} ${gradle.branch}" -if (file('.hgflow').exists()) { - def flows = new Properties() - flows.load(file('.hgflow').newReader()) - flows.stringPropertyNames().each { - if (!it.startsWith("[") && gradle.branchName.startsWith(flows.getProperty(it))) { - gradle.ext.branchStream = it - } - } -} - -gradle.branchName = gradle.branchName.replace('@', '-') -gradle.ext.branchHash = generateMD5(gradle.branchName) loadEnvironments() gradle.environment.put('hgRepositoryUrl', gradle.hgRepositoryUrl) -gradle.environment.put('branchName', gradle.branchName) -gradle.environment.put('branchStream', gradle.branchStream) -gradle.environment.put('branchHash', gradle.branchHash) +gradle.environment.put('branchName', gradle.branch.name) +gradle.environment.put('branchStream', gradle.branch.stream) +gradle.environment.put('branchHash', gradle.branch.hash) + rootProject.ext.indyCapable = { @@ -499,8 +484,47 @@ } -def generateMD5(String s) { - def digest = java.security.MessageDigest.getInstance("MD5") - digest.update(s.bytes); - new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') -} \ No newline at end of file + +@ToString class BranchInfo { + def name + def stream + + BranchInfo(name) { + this.name = name + if (!name) { + this.name = determineName() + } + this.name = this.name.replace('@', '-') + determineStream() + } + + def getHash() { + generateMD5(name) + } + def generateMD5(String s) { + def digest = java.security.MessageDigest.getInstance("MD5") + digest.update(s.bytes); + new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') + } + + def determineName() { + def branch = "hg branch".execute().text.trim() + def rawParents = 'hg parents'.execute().text + def parent = rawParents.split('\n').find { it.startsWith("branch") }?.split(":")?.getAt(1)?.trim() + return parent ?: branch + } + + void determineStream() { + if (new File('.hgflow').exists()) { + def flows = new Properties() + flows.load(new File('.hgflow').newReader()) + flows.stringPropertyNames().each { + if (!it.startsWith("[") && name.startsWith(flows.getProperty(it))) { + stream = it + } + } + } + } + +} +