build.gradle revision de3a5f95ae35478159786155474a95c744b2cbc4
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(new File(buildDir, '/generated-sources/antlr3')) 40 41ext.jflexSource = "src/main/jflex" 42ext.jflexOutput = file(new File(buildDir, '/generated-sources/jflex')) 43 44ext.testAntlrSource = 'src/test/antlr3' 45ext.testAntlrOutput = file(new File(buildDir, '/generated-test-sources/antlr3')) 46 47sourceSets.main.java.srcDir antlrOutput 48sourceSets.main.java.srcDir jflexOutput 49 50sourceSets.test.java.srcDir testAntlrOutput 51 52dependencies { 53 compile project(':util') 54 compile project(':dexlib') 55 compile 'org.antlr:antlr-runtime:3.2' 56 compile 'commons-cli:commons-cli:1.2' 57 58 testCompile 'junit:junit:4.6' 59 60 antlr3 'org.antlr:antlr:3.2' 61 jflex 'de.jflex:jflex:1.4.3' 62 proguard 'net.sf.proguard:proguard-base:4.8' 63} 64 65task generateAntlrSource(type: JavaExec) { 66 inputs.dir file(antlrSource) 67 outputs.dir file(antlrOutput) 68 69 mkdir(antlrOutput) 70 def grammars = fileTree(antlrSource).include('**/*.g') 71 72 classpath = configurations.antlr3 73 main = 'org.antlr.Tool' 74 args '-fo', relativePath(new File(antlrOutput, 'org/jf/smali')) 75 args grammars.files 76} 77 78task generateTestAntlrSource(type: JavaExec) { 79 inputs.dir file(testAntlrSource) 80 outputs.dir file(testAntlrOutput) 81 82 mkdir(testAntlrOutput) 83 def grammars = fileTree(testAntlrSource).include('**/*.g') 84 85 classpath = configurations.antlr3 86 main = 'org.antlr.Tool' 87 args '-fo', relativePath(new File(testAntlrOutput, 'org/jf/smali')) 88 args grammars.files.join(' ') 89} 90 91task generateJflexSource(type: JavaExec) { 92 inputs.dir file(jflexSource) 93 outputs.dir file(jflexOutput) 94 95 mkdir(jflexOutput) 96 def grammars = fileTree(jflexSource).include('**/*.flex') 97 98 classpath = configurations.jflex 99 main = 'JFlex.Main' 100 args '-q' 101 args '-d', relativePath(new File(jflexOutput, 'org/jf/smali')) 102 args grammars.files.join(' ') 103} 104 105 106compileJava.dependsOn generateAntlrSource, generateJflexSource 107compileTestJava.dependsOn generateTestAntlrSource 108 109// We have to do this in taskGraph.whenReady, so that we use the correct 110// version to resolve the project dependencies 111gradle.taskGraph.whenReady { 112 // build a jar containing all dependencies 113 jar { 114 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 115 116 manifest { 117 attributes("Main-Class": "org.jf.smali.main") 118 } 119 } 120 121 processResources.inputs.properties('version': version) 122 processResources.expand('version': version) 123 124 proguard { 125 def outFile = relativePath(buildDir) + '/libs/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension 126 127 inputs.file jar.archivePath 128 outputs.file outFile 129 130 args '-injars ' + jar.archivePath + '(!**/TestStringTemplate*.class)' 131 args '-outjars ' + outFile 132 } 133} 134 135task proguard(type: JavaExec, dependsOn: jar) { 136 classpath = configurations.proguard 137 main = 'proguard.ProGuard' 138 args '-libraryjars ' + System.properties['java.home'] + '/lib/rt.jar' 139 args '-dontobfuscate' 140 args '-dontoptimize' 141 args '-keep public class org.jf.smali.main { public static void main(java.lang.String[]); }' 142 args '-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }' 143 args '-dontwarn com.google.common.base.**' 144 args '-dontnote com.google.common.base.**' 145} 146 147release.dependsOn(proguard)