| configurations { |
| antlr3 |
| jflex |
| proguard |
| } |
| |
| ext.antlrSource = 'src/main/antlr3' |
| ext.antlrOutput = file(new File(buildDir, '/generated-sources/antlr3')) |
| |
| ext.jflexSource = "src/main/jflex" |
| ext.jflexOutput = file(new File(buildDir, '/generated-sources/jflex')) |
| |
| ext.testAntlrSource = 'src/test/antlr3' |
| ext.testAntlrOutput = file(new File(buildDir, '/generated-test-sources/antlr3')) |
| |
| sourceSets.main.java.srcDir antlrOutput |
| sourceSets.main.java.srcDir jflexOutput |
| |
| sourceSets.test.java.srcDir testAntlrOutput |
| |
| dependencies { |
| compile project(':util') |
| compile project(':dexlib') |
| compile 'org.antlr:antlr-runtime:3.2' |
| compile 'commons-cli:commons-cli:1.2' |
| |
| testCompile 'junit:junit:4.6' |
| |
| antlr3 'org.antlr:antlr:3.2' |
| jflex 'de.jflex:jflex:1.4.3' |
| proguard 'net.sf.proguard:proguard-base:4.8' |
| } |
| |
| task generateAntlrSource { |
| inputs.dir file(antlrSource) |
| outputs.dir file(antlrOutput) |
| doLast { |
| mkdir(antlrOutput) |
| |
| def grammars = fileTree(antlrSource).include('**/*.g') |
| |
| ant.java(classname: 'org.antlr.Tool', classpath: configurations.antlr3.asPath, fork: true) { |
| arg(line: '-fo ' + antlrOutput + '/org/jf/smali') |
| arg(line: grammars.files.join(" ")) |
| } |
| } |
| } |
| |
| task generateTestAntlrSource { |
| inputs.dir file(testAntlrSource) |
| outputs.dir file(testAntlrOutput) |
| doLast { |
| mkdir(testAntlrOutput) |
| |
| def grammars = fileTree(testAntlrSource).include('**/*.g') |
| |
| ant.java(classname: 'org.antlr.Tool', classpath: configurations.antlr3.asPath, fork: true) { |
| arg(line: '-fo ' + testAntlrOutput + '/org/jf/smali') |
| arg(line: grammars.files.join(" ")) |
| } |
| } |
| } |
| |
| task generateJflexSource { |
| inputs.dir file(jflexSource) |
| outputs.dir file(jflexOutput) |
| doLast { |
| mkdir(jflexOutput) |
| |
| def grammars = fileTree(jflexSource).include('**/*.flex') |
| |
| ant.java(classname: 'JFlex.Main', classpath: configurations.jflex.asPath, fork: true) { |
| arg(line: '-d ' + jflexOutput + '/org/jf/smali') |
| arg(line: 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) } } |
| |
| 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 + '-small' + '.' + jar.extension |
| |
| inputs.file jar.archivePath |
| outputs.file outFile |
| |
| args '-injars ' + jar.archivePath + '(!**/TestStringTemplate*.class)' |
| args '-outjars ' + outFile |
| } |
| } |
| |
| task proguard(type: JavaExec, dependsOn: jar) { |
| setStandardOutput(java.lang.System.out); |
| setErrorOutput(java.lang.System.err); |
| classpath = files(configurations.proguard.asPath) |
| main = 'proguard.ProGuard' |
| args '-libraryjars ' + System.properties['java.home'] + '/lib/rt.jar' |
| args '-dontobfuscate' |
| args '-dontoptimize' |
| args '-keep public class org.jf.smali.main { public static void main(java.lang.String[]); }' |
| args '-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }' |
| args '-dontwarn com.google.common.base.**' |
| args '-dontnote com.google.common.base.**' |
| } |
| |
| release.dependsOn(proguard) |