From e3ed1a448a6d3bc6ae86bbdb54cb6e3a248bc9cb Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 4 Feb 2014 09:54:00 -0600 Subject: [PATCH] refactor gradle version system for release, snapshots and non-git snapshots --- brut.apktool/apktool-cli/build.gradle | 4 +- brut.apktool/apktool-lib/build.gradle | 19 ++------ build.gradle | 70 ++++++++++++++++++++------- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/brut.apktool/apktool-cli/build.gradle b/brut.apktool/apktool-cli/build.gradle index 362ee91e..1ee0d114 100644 --- a/brut.apktool/apktool-cli/build.gradle +++ b/brut.apktool/apktool-cli/build.gradle @@ -13,8 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -version = apktoolversion apply plugin: 'fatjar' configurations { @@ -35,7 +33,7 @@ gradle.taskGraph.whenReady { } task proguard(type: JavaExec, dependsOn: fatJar) { - def outFile = jar.destinationDir.getPath() + '/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension + def outFile = jar.destinationDir.getPath() + '/' + "apktool" + '-' + project.apktool_version + '-small' + '.' + jar.extension inputs.file jar.archivePath outputs.file outFile diff --git a/brut.apktool/apktool-lib/build.gradle b/brut.apktool/apktool-lib/build.gradle index c0d120cd..9ae3d0b5 100644 --- a/brut.apktool/apktool-lib/build.gradle +++ b/brut.apktool/apktool-lib/build.gradle @@ -16,26 +16,11 @@ import org.apache.tools.ant.filters.* -// release -if (!('release' in gradle.startParameter.taskNames)) { - ant.loadfile(srcFile: "../../.git/refs/heads/master", property: fullrev, failonerror: false); - if (ant.properties[fullrev] == null) { - gitrev_version = "SNAPSHOT_DEV"; - println "Building SNAPSHOT (no .git folder found)"; - } else { - gitrev_version = ant.properties[fullrev].substring(0,10); - println "Building SNAPSHOT: " + gitrev_version; - } -} else { - gitrev_version = ''; - println "Building RELEASE: " + apktoolversion; -} - processResources { from('src/main/resources/properties') { include '**/*.properties' into 'properties' - filter(ReplaceTokens, tokens: [version: apktoolversion, gitrev: gitrev_version] ) + filter(ReplaceTokens, tokens: [version: project.apktool_version, gitrev: project.hash] ) } from('src/main/resources/') { include '**/*.jar' @@ -43,10 +28,12 @@ processResources { includeEmptyDirs = false } + dependencies { compile ("junit:junit:4.10") { exclude(module: 'hamcrest-core') } + compile project(':brut.j.dir'), project(':brut.j.util'), project(':brut.j.common'), diff --git a/build.gradle b/build.gradle index 4c3c8da6..116bb85e 100644 --- a/build.gradle +++ b/build.gradle @@ -13,14 +13,60 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - apply plugin: 'java' apply plugin: 'maven' -apply plugin: 'license' -ext.apktoolversion = '2.0.0-Beta8' -ext.fullrev = ''; -ext.gitrev_version = ''; +def apktoolversion_major = '2.0.0' +def apktoolversion_minor = 'Beta8'; + +if (!('release' in gradle.startParameter.taskNames)) { + def hash = getCheckedOutGitCommitHash(); + + if (hash == null) { + project.ext.set("hash", "dirty") + project.ext.set("apktool_version", apktoolversion_major + "-dirty") + println "Building SNAPSHOT (no .git folder found)"; + } else { + project.ext.set("hash", hash); + project.ext.set("apktool_version", apktoolversion_major + "-" + hash + "-SNAPSHOT"); + println "Building SNAPSHOT (" + getCheckedOutBranch() + "): " + hash; + } +} else { + project.ext.set("hash", "") + project.ext.set("apktool_version", apktoolversion_major + "-" + apktoolversion_minor); + println "Building RELEASE (" + getCheckedOutBranch() + "): " + apktoolversion_major + "-" + apktoolversion_minor; +} + +// https://gist.github.com/JonasGroeger/7620911 +def getCheckedOutGitCommitHash() { + def gitFolder = "$projectDir/.git/" + def takeFromHash = 6 + + def head + try { + head = new File(gitFolder + "HEAD").text.split(":") + } catch(Exception e) { + return null; + } + + def isCommit = head.length == 1 + if(isCommit) return head[0].trim().take(takeFromHash) + + def refHead = new File(gitFolder + head[1].trim()) + refHead.text.trim().take takeFromHash +} + +def getCheckedOutBranch() { + def gitFolder = "$projectDir/.git/" + + def head + try { + head = new File(gitFolder + "HEAD").text.split("/") + } catch(Exception e) { + return ""; + } + return head[2].trim(); +} repositories { mavenCentral() @@ -37,22 +83,11 @@ build.doFirst { } } - -class Compatibility { - String version - Compatibility(String versionValue) { - def matcher = (versionValue =~ /Java (\d)/) - version = matcher[0][1] - } - String toString() { version } -} - task wrapper(type: Wrapper) { gradleVersion = '1.8' } -// If anyone uses this outside of GoogleCode (Apktool) developers. I will hunt you down and hurt you. -// This is for official releases only. +// used for official releases only. Please don't use task release { } @@ -61,7 +96,6 @@ buildscript { mavenCentral() } dependencies { - classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.5.0' classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1' } }