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
32apply plugin: 'antlr'
33apply plugin: 'org.xbib.gradle.plugin.jflex'
34
35buildscript {
36    repositories {
37        mavenCentral()
38    }
39    dependencies {
40        classpath depends.jflex_plugin
41        classpath depends.proguard_gradle
42    }
43}
44
45configurations {
46    // Remove the full antlr library that's added by the antlr plugin. We manually
47    // add the smaller antlr_runtime library instead
48    compile.exclude group: 'org.antlr', module: 'antlr'
49}
50
51sourceSets {
52    main {
53        resources {
54            // This adds the generated .tokens files to the jar
55            srcDir 'build/generated-src/antlr/main'
56        }
57    }
58}
59
60idea {
61    module {
62        excludeDirs -= buildDir
63        if (buildDir.exists()) {
64            excludeDirs.addAll(buildDir.listFiles())
65        }
66        for (sourceDir in (sourceDirs + testSourceDirs)) {
67            excludeDirs.remove(sourceDir);
68            while ((sourceDir = sourceDir.getParentFile()) != null) {
69                excludeDirs.remove(sourceDir);
70            }
71        }
72    }
73}
74
75dependencies {
76    compile project(':util')
77    compile project(':dexlib2')
78    compile depends.antlr_runtime
79    compile depends.jcommander
80    compile depends.stringtemplate
81
82    testCompile depends.junit
83
84    antlr depends.antlr
85}
86
87processResources.inputs.property('version', version)
88processResources.expand('version': version)
89
90// Build a separate jar that contains all dependencies
91task fatJar(type: Jar, dependsOn: jar) {
92    from sourceSets.main.output
93    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
94
95    classifier = 'fat'
96
97    manifest {
98        attributes('Main-Class': 'org.jf.smali.Main')
99    }
100
101    doLast {
102        if (!System.getProperty('os.name').toLowerCase().contains('windows')) {
103            ant.symlink(link: file("${destinationDir}/smali.jar"), resource: archivePath, overwrite: true)
104        }
105    }
106}
107tasks.getByPath('build').dependsOn(fatJar)
108
109generateTestGrammarSource {
110    outputDirectory = new File(outputDirectory, 'org/jf/smali')
111}
112
113generateGrammarSource {
114    outputDirectory = new File(outputDirectory, 'org/jf/smali')
115}
116
117jflex {
118    generateDir = new File(generateDir, 'org/jf/smali')
119}
120
121uploadArchives {
122    repositories.mavenDeployer {
123        pom.project {
124            description 'smali is an assembler for dalvik bytecode'
125            scm {
126                url 'https://github.com/JesusFreke/smali/tree/master/smali'
127            }
128        }
129    }
130}
131
132task proguard(type: proguard.gradle.ProGuardTask, dependsOn: fatJar) {
133    def outFile = fatJar.destinationDir.getPath() + '/' + fatJar.baseName + '-' +
134            fatJar.version + '-small' + '.' + fatJar.extension
135
136    injars fatJar.archivePath
137    outjars outFile
138
139    libraryjars "${System.properties['java.home']}/lib/rt.jar"
140
141    dontobfuscate
142    dontoptimize
143
144    keep 'public class org.jf.smali.Main { public static void main(java.lang.String[]); }'
145    keep 'class com.beust.jcommander.** { *; }'
146    keepclassmembers 'enum * { public static **[] values(); public static ** valueOf(java.lang.String); }'
147
148    dontwarn 'com.google.common.**'
149    dontnote 'com.google.common.**'
150}
151
152tasks.getByPath(':release').dependsOn(proguard)
153