• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2012, Google LLC
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google LLC nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31apply plugin: 'antlr'
32apply plugin: 'org.xbib.gradle.plugin.jflex'
33
34buildscript {
35    repositories {
36        mavenCentral()
37    }
38    dependencies {
39        classpath depends.jflex_plugin
40        classpath depends.proguard_gradle
41    }
42}
43
44configurations {
45    // Remove the full antlr library that's added by the antlr plugin. We manually
46    // add the smaller antlr_runtime library instead
47    implementation.exclude group: 'org.antlr', module: 'antlr'
48}
49
50sourceSets {
51    main {
52        java {
53            srcDirs "${project.rootDir}/third_party/smali/src/main/java"
54        }
55        resources {
56            // This adds the generated .tokens files to the jar
57            srcDir 'build/generated-src/antlr/main'
58        }
59    }
60    test {
61        java {
62            srcDirs "${project.rootDir}/third_party/smali/src/test/java"
63        }
64    }
65}
66
67idea {
68    module {
69        excludeDirs -= buildDir
70        if (buildDir.exists()) {
71            excludeDirs.addAll(buildDir.listFiles())
72        }
73        for (sourceDir in (sourceDirs + testSourceDirs)) {
74            excludeDirs.remove(sourceDir);
75            while ((sourceDir = sourceDir.getParentFile()) != null) {
76                excludeDirs.remove(sourceDir);
77            }
78        }
79    }
80}
81
82dependencies {
83    implementation project(':util')
84    api project(':dexlib2')
85    implementation depends.antlr_runtime
86    implementation depends.jcommander
87    implementation depends.stringtemplate
88    implementation depends.guava
89
90    testImplementation depends.junit
91
92    antlr depends.antlr
93}
94
95processResources.inputs.property('version', version)
96processResources.expand('version': version)
97
98// Build a separate jar that contains all dependencies
99task fatJar(type: Jar, dependsOn: jar) {
100    from sourceSets.main.output
101    from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
102
103    classifier = 'fat'
104
105    manifest {
106        attributes('Main-Class': 'com.android.tools.smali.smali.Main')
107    }
108
109    doLast {
110        if (!System.getProperty('os.name').toLowerCase().contains('windows')) {
111            ant.symlink(link: file("${destinationDirectory.get()}/smali.jar"), resource: archivePath, overwrite: true)
112        }
113    }
114}
115tasks.getByPath('build').dependsOn(fatJar)
116
117generateTestGrammarSource {
118    outputDirectory = new File(outputDirectory, 'com/android/tools/smali/smali')
119}
120
121generateGrammarSource {
122    outputDirectory = new File(outputDirectory, 'com/android/tools/smali/smali')
123}
124
125jflex {
126    generateDir = new File(generateDir, 'com/android/tools/smali/smali')
127}
128
129publish {
130    publishing {
131        publications {
132            mavenJava(MavenPublication) {
133                pom {
134                    description = 'smali is an assembler for dalvik bytecode'
135                    scm {
136                        url = 'https://github.com/google/smali/tree/master/smali'
137                    }
138                }
139            }
140        }
141    }
142}
143
144task proguard(type: proguard.gradle.ProGuardTask, dependsOn: fatJar) {
145    def outFile = fatJar.destinationDirectory.file(
146            "${fatJar.archiveBaseName.get()}-${fatJar.archiveVersion.get()}-small.${fatJar.archiveExtension.get()}")
147
148    injars fatJar
149    outjars outFile
150
151    if (JavaVersion.current().isJava9Compatible()) {
152        libraryjars(System.getProperty("java.home") + "/jmods")
153    } else {
154        libraryjars(System.getProperty("java.home") + "/lib/rt.jar")
155    }
156
157    dontobfuscate
158    dontoptimize
159
160    keep 'public class com.android.tools.smali.smali.Main { public static void main(java.lang.String[]); }'
161    keep 'class com.beust.jcommander.** { *; }'
162    keepclassmembers 'enum * { public static **[] values(); public static ** valueOf(java.lang.String); }'
163
164    dontwarn 'com.google.common.**'
165    dontnote 'com.google.common.**'
166}
167
168sourcesJar {
169    duplicatesStrategy = DuplicatesStrategy.INCLUDE
170}
171
172tasks.getByPath(':release').dependsOn(proguard)
173