From 3a96d5d432ed10f94ddf2a9a9d5af9c5593e9b0d Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Mon, 29 Oct 2012 21:42:29 -0700 Subject: [PATCH] Change how release vs. non-release is detected This allows the smali/baksmali builds to be simplified a bit --- baksmali/build.gradle | 38 +++++++++------------- build.gradle | 73 +++++++++++++++++++++---------------------- smali/build.gradle | 39 +++++++++-------------- 3 files changed, 66 insertions(+), 84 deletions(-) diff --git a/baksmali/build.gradle b/baksmali/build.gradle index 2ee41805..78f85bc0 100644 --- a/baksmali/build.gradle +++ b/baksmali/build.gradle @@ -42,35 +42,27 @@ dependencies { proguard 'net.sf.proguard:proguard-base:4.8' } -// We have to do this in taskGraph.whenReady, so that we use the correct -// version to resolve the project dependencies -gradle.taskGraph.whenReady { - // build a jar containing all dependencies - jar { - from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } +processResources.inputs.property('version', version) +processResources.expand('version': version) - manifest { - attributes("Main-Class": "org.jf.baksmali.main") - } +// build a jar containing all dependencies +jar { + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + + manifest { + attributes("Main-Class": "org.jf.baksmali.main") } - - proguard { - def outFile = relativePath(buildDir) + '/libs/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension - - inputs.file jar.archivePath - outputs.file outFile - - args '-injars ' + jar.archivePath - args '-outjars ' + outFile - } - - processResources.inputs.properties('version': { -> version}) - processResources.expand('version': { -> version}) } task proguard(type: JavaExec, dependsOn: jar) { + def outFile = jar.destinationDir.getPath() + '/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension + inputs.file jar.archivePath + outputs.file outFile + classpath = configurations.proguard main = 'proguard.ProGuard' + args '-injars ' + jar.archivePath + args '-outjars ' + outFile args '-libraryjars ' + System.properties['java.home'] + '/lib/rt.jar' args '-dontobfuscate' args '-dontoptimize' @@ -80,4 +72,4 @@ task proguard(type: JavaExec, dependsOn: jar) { args '-dontnote com.google.common.base.**' } -release.dependsOn(proguard) \ No newline at end of file +tasks.getByPath(':release').dependsOn(proguard) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 30134f0e..dfc76a5b 100644 --- a/build.gradle +++ b/build.gradle @@ -31,56 +31,55 @@ apply plugin: 'idea' +version = '1.4.1' + +def jarVersion = version + +if (!('release' in gradle.startParameter.taskNames)) { + def versionSuffix + try { + def git = org.eclipse.jgit.api.Git.open(file('.')) + def head = git.getRepository().getRef("HEAD") + versionSuffix = head.getObjectId().abbreviate(8).name() + + if (!git.status().call().clean) { + versionSuffix += '-dirty' + } + } catch (Exception) { + // In case we can't get the commit for some reason, + // just use -dev + versionSuffix = 'dev' + } + + def baseVersion = version + version = baseVersion + '-' + versionSuffix + + // use something like module-1.2.3-dev.jar for the jar name, rather than the full + // module-1.2.3-001afe02-dirty.jar + jarVersion = baseVersion + '-dev' +} + subprojects { apply plugin: 'java' apply plugin: 'idea' - ext.baseVersion = '1.4.1' - ext.jarVersion = baseVersion + version = parent.version - // For non-release builds, we want to append the commit and - // dirty status to the version - gradle.taskGraph.whenReady { - if (!it.hasTask(release)) { - def versionSuffix - try { - def git = org.eclipse.jgit.api.Git.open(file('.')) - def head = git.getRepository().getRef("HEAD") - versionSuffix = head.getObjectId().abbreviate(8).name() - - if (!git.status().call().clean) { - versionSuffix += '-dirty' - } - } catch (Exception) { - // In case we can't get the commit for some reason, - // just use -dev - versionSuffix = 'dev' - } - - version = baseVersion + '-' + versionSuffix - - // use -dev for the jar name, rather than the - // full commit+dirty string - jarVersion = baseVersion + '-dev' - } else { - version = baseVersion - } - - jar { - version = jarVersion - } + jar { + version = jarVersion } repositories { mavenCentral() } - // Note: please don't use this. This is strictly for the official releases - // that are posted on the googlecode download page. - task release { - } + } +// Note: please don't use this. This is strictly for the official releases +// that are posted on the googlecode download page. +task release { +} buildscript { repositories { diff --git a/smali/build.gradle b/smali/build.gradle index 1be1c514..a60056fb 100644 --- a/smali/build.gradle +++ b/smali/build.gradle @@ -117,39 +117,30 @@ task generateJflexSource(type: JavaExec) { args grammars.files.join(' ') } - compileJava.dependsOn generateAntlrSource, generateJflexSource compileTestJava.dependsOn generateTestAntlrSource -// We have to do this in taskGraph.whenReady, so that we use the correct -// version to resolve the project dependencies -gradle.taskGraph.whenReady { - // build a jar containing all dependencies - jar { - from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } +// build a jar containing all dependencies +jar { + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } - manifest { - attributes("Main-Class": "org.jf.smali.main") - } - } - - processResources.inputs.properties('version': version) - processResources.expand('version': version) - - proguard { - def outFile = relativePath("${buildDir}/libs/${jar.baseName}-${jar.version}-smali.${jar.extension}") - - inputs.file jar.archivePath - outputs.file outFile - - args "-injars ${jar.archivePath}(!**/TestStringTemplate*.class)" - args "-outjars ${outFile}" + manifest { + attributes("Main-Class": "org.jf.smali.main") } } +processResources.inputs.property('version', version) +processResources.expand('version': version) + task proguard(type: JavaExec, dependsOn: jar) { + def outFile = jar.destinationDir.getPath() + '/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension + inputs.file jar.archivePath + outputs.file outFile + classpath = configurations.proguard main = 'proguard.ProGuard' + args "-injars ${jar.archivePath}(!**/TestStringTemplate*.class)" + args "-outjars ${outFile}" args "-libraryjars ${System.properties['java.home']}/lib/rt.jar" args '-dontobfuscate' args '-dontoptimize' @@ -159,4 +150,4 @@ task proguard(type: JavaExec, dependsOn: jar) { args '-dontnote com.google.common.base.**' } -release.dependsOn(proguard) \ No newline at end of file +tasks.getByPath(':release').dependsOn(proguard) \ No newline at end of file