build.gradle revision 46cefa3d5be5a99484075cf60d1c55ca36ccffd3
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(':dexlib')
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 generateAntlrSource(type: JavaExec) {
81    inputs.dir file(antlrSource)
82    outputs.dir file(antlrOutput)
83
84    mkdir(antlrOutput)
85    def grammars = fileTree(antlrSource).include('**/*.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 generateTestAntlrSource(type: JavaExec) {
94    inputs.dir file(testAntlrSource)
95    outputs.dir file(testAntlrOutput)
96
97    mkdir(testAntlrOutput)
98    def grammars = fileTree(testAntlrSource).include('**/*.g')
99
100    classpath = configurations.antlr3
101    main = 'org.antlr.Tool'
102    args '-fo', relativePath("${testAntlrOutput}/org/jf/smali")
103    args grammars.files.join(' ')
104}
105
106task generateJflexSource(type: JavaExec) {
107    inputs.dir file(jflexSource)
108    outputs.dir file(jflexOutput)
109
110    mkdir(jflexOutput)
111    def grammars = fileTree(jflexSource).include('**/*.flex')
112
113    classpath = configurations.jflex
114    main = 'JFlex.Main'
115    args '-q'
116    args '-d', relativePath("${jflexOutput}/org/jf/smali")
117    args grammars.files.join(' ')
118}
119
120compileJava.dependsOn generateAntlrSource, generateJflexSource
121compileTestJava.dependsOn generateTestAntlrSource
122
123// build a jar containing all dependencies
124jar {
125    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
126
127    manifest {
128        attributes("Main-Class": "org.jf.smali.main")
129    }
130
131    doLast {
132        ant.symlink(link: file("${destinationDir}/smali.jar"), resource: archivePath, overwrite: true)
133    }
134}
135
136processResources.inputs.property('version', version)
137processResources.expand('version': version)
138
139task proguard(type: JavaExec, dependsOn: jar) {
140    def outFile = jar.destinationDir.getPath() + '/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension
141    inputs.file jar.archivePath
142    outputs.file outFile
143
144    classpath = configurations.proguard
145    main = 'proguard.ProGuard'
146    args "-injars ${jar.archivePath}(!**/TestStringTemplate*.class)"
147    args "-outjars ${outFile}"
148    args "-libraryjars ${System.properties['java.home']}/lib/rt.jar"
149    args '-dontobfuscate'
150    args '-dontoptimize'
151    args '-keep public class org.jf.smali.main { public static void main(java.lang.String[]); }'
152    args '-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }'
153    args '-dontwarn com.google.common.base.**'
154    args '-dontnote com.google.common.base.**'
155}
156
157tasks.getByPath(':release').dependsOn(proguard)
158