build.gradle revision 318954d56b135ade53ea9f76814fbf4b630b5827
1/* 2 * Copyright 2012, Google Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32configurations { 33 antlr3 34 jflex 35 proguard 36} 37 38ext.antlrSource = 'src/main/antlr3' 39ext.antlrOutput = file("${buildDir}/generated-sources/antlr3") 40 41ext.jflexSource = "src/main/jflex" 42ext.jflexOutput = file("${buildDir}/generated-sources/jflex") 43 44ext.testAntlrSource = 'src/test/antlr3' 45ext.testAntlrOutput = file("${buildDir}/generated-test-sources/antlr3") 46 47sourceSets.main.java.srcDir antlrOutput 48sourceSets.main.java.srcDir jflexOutput 49 50sourceSets.test.java.srcDir testAntlrOutput 51 52idea { 53 module { 54 excludeDirs -= buildDir 55 if (buildDir.exists()) { 56 excludeDirs.addAll(buildDir.listFiles()) 57 } 58 for (sourceDir in (sourceDirs + testSourceDirs)) { 59 excludeDirs.remove(sourceDir); 60 while ((sourceDir = sourceDir.getParentFile()) != null) { 61 excludeDirs.remove(sourceDir); 62 } 63 } 64 } 65} 66 67dependencies { 68 compile project(':util') 69 compile project(':dexlib2') 70 compile depends.antlr_runtime 71 compile depends.commons_cli 72 73 testCompile depends.junit 74 75 antlr3 depends.antlr 76 jflex depends.jflex 77 proguard depends.proguard 78} 79 80task generateParserAntlrSource(type: JavaExec) { 81 inputs.dir file(antlrSource) 82 outputs.dir file(antlrOutput) 83 84 mkdir(antlrOutput) 85 def grammars = fileTree(antlrSource).include('**/smaliParser.g') 86 87 classpath = configurations.antlr3 88 main = 'org.antlr.Tool' 89 args '-fo', relativePath("${antlrOutput}/org/jf/smali") 90 args grammars.files 91} 92 93task generateTreeWalkerAntlrSource(type: JavaExec) { 94 inputs.dir file(antlrSource) 95 outputs.dir file(antlrOutput) 96 97 mkdir(antlrOutput) 98 def grammars = fileTree(antlrSource).include('**/smaliTreeWalker.g') 99 100 classpath = configurations.antlr3 101 main = 'org.antlr.Tool' 102 args '-fo', relativePath("${antlrOutput}/org/jf/smali") 103 args grammars.files 104} 105 106task generateTestAntlrSource(type: JavaExec) { 107 inputs.dir file(testAntlrSource) 108 outputs.dir file(testAntlrOutput) 109 110 mkdir(testAntlrOutput) 111 def grammars = fileTree(testAntlrSource).include('**/*.g') 112 113 classpath = configurations.antlr3 114 main = 'org.antlr.Tool' 115 args '-fo', relativePath("${testAntlrOutput}/org/jf/smali") 116 args grammars.files.join(' ') 117} 118 119task generateJflexSource(type: JavaExec) { 120 inputs.dir file(jflexSource) 121 outputs.dir file(jflexOutput) 122 123 mkdir(jflexOutput) 124 def grammars = fileTree(jflexSource).include('**/*.flex') 125 126 classpath = configurations.jflex 127 main = 'JFlex.Main' 128 args '-q' 129 args '-d', relativePath("${jflexOutput}/org/jf/smali") 130 args grammars.files.join(' ') 131} 132 133compileJava.dependsOn generateParserAntlrSource, generateTreeWalkerAntlrSource, generateJflexSource 134compileTestJava.dependsOn generateTestAntlrSource 135 136// build a jar containing all dependencies 137jar { 138 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 139 140 manifest { 141 attributes("Main-Class": "org.jf.smali.main") 142 } 143 144 doLast { 145 if (!System.getProperty("os.name").toLowerCase().contains("windows")) { 146 ant.symlink(link: file("${destinationDir}/smali.jar"), resource: archivePath, overwrite: true) 147 } 148 } 149} 150 151processResources.inputs.property('version', version) 152processResources.expand('version': version) 153 154task proguard(type: JavaExec, dependsOn: jar) { 155 def outFile = jar.destinationDir.getPath() + '/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension 156 inputs.file jar.archivePath 157 outputs.file outFile 158 159 classpath = configurations.proguard 160 main = 'proguard.ProGuard' 161 args "-injars ${jar.archivePath}(!**/TestStringTemplate*.class)" 162 args "-outjars ${outFile}" 163 args "-libraryjars ${System.properties['java.home']}/lib/rt.jar" 164 args '-dontobfuscate' 165 args '-dontoptimize' 166 args '-keep public class org.jf.smali.main { public static void main(java.lang.String[]); }' 167 args '-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }' 168 args '-dontwarn com.google.common.**' 169 args '-dontnote com.google.common.**' 170} 171 172tasks.getByPath(':release').dependsOn(proguard) 173