aboutsummaryrefslogtreecommitdiff
path: root/smali/build.gradle
blob: b5f9cb171217fd19f2d7bbd4c89d3958369b206c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
configurations {
    antlr3
    jflex
    proguard
}

ext.antlrSource = 'src/main/antlr3'
ext.antlrOutput =  file(new File(buildDir, '/generated-sources/antlr3'))

ext.jflexSource = "src/main/jflex"
ext.jflexOutput = file(new File(buildDir, '/generated-sources/jflex'))

ext.testAntlrSource = 'src/test/antlr3'
ext.testAntlrOutput = file(new File(buildDir, '/generated-test-sources/antlr3'))

sourceSets.main.java.srcDir antlrOutput
sourceSets.main.java.srcDir jflexOutput

sourceSets.test.java.srcDir testAntlrOutput

dependencies {
    compile project(':util')
    compile project(':dexlib')
    compile 'org.antlr:antlr-runtime:3.2'
    compile 'commons-cli:commons-cli:1.2'

    testCompile 'junit:junit:4.6'

    antlr3 'org.antlr:antlr:3.2'
    jflex 'de.jflex:jflex:1.4.3'
    proguard 'net.sf.proguard:proguard-base:4.8'
}

task generateAntlrSource {
    inputs.dir file(antlrSource)
    outputs.dir file(antlrOutput)
    doLast {
        mkdir(antlrOutput)

        def grammars = fileTree(antlrSource).include('**/*.g')

        ant.java(classname: 'org.antlr.Tool', classpath: configurations.antlr3.asPath, fork: true) {
            arg(line: '-fo ' + antlrOutput + '/org/jf/smali')
            arg(line: grammars.files.join(" "))
        }
    }
}

task generateTestAntlrSource {
    inputs.dir file(testAntlrSource)
    outputs.dir file(testAntlrOutput)
    doLast {
        mkdir(testAntlrOutput)

        def grammars = fileTree(testAntlrSource).include('**/*.g')

        ant.java(classname: 'org.antlr.Tool', classpath: configurations.antlr3.asPath, fork: true) {
            arg(line: '-fo ' + testAntlrOutput + '/org/jf/smali')
            arg(line: grammars.files.join(" "))
        }
    }
}

task generateJflexSource {
    inputs.dir file(jflexSource)
    outputs.dir file(jflexOutput)
    doLast {
        mkdir(jflexOutput)

        def grammars = fileTree(jflexSource).include('**/*.flex')

        ant.java(classname: 'JFlex.Main', classpath: configurations.jflex.asPath, fork: true) {
            arg(line: '-d ' + jflexOutput + '/org/jf/smali')
            arg(line: grammars.files.join(" "))
        }
    }
}

compileJava.dependsOn generateAntlrSource, generateJflexSource
compileTestJava.dependsOn generateTestAntlrSource

// We have to do this in taskGraph.whenReady, so that we use the correct
// version to resolve the project dependencies
gradle.taskGraph.whenReady {
    // build a jar containing all dependencies
    jar {
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

        manifest {
            attributes("Main-Class": "org.jf.smali.main")
        }
    }

    processResources.inputs.properties('version': version)
	processResources.expand('version': version)

    proguard {
        def outFile = relativePath(buildDir) + '/libs/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension

        inputs.file jar.archivePath
        outputs.file outFile

        args '-injars ' + jar.archivePath + '(!**/TestStringTemplate*.class)'
        args '-outjars ' + outFile
    }
}

task proguard(type: JavaExec, dependsOn: jar) {
    setStandardOutput(java.lang.System.out);
    setErrorOutput(java.lang.System.err);
    classpath = files(configurations.proguard.asPath)
    main = 'proguard.ProGuard'
    args '-libraryjars ' + System.properties['java.home'] + '/lib/rt.jar'
    args '-dontobfuscate'
    args '-dontoptimize'
    args '-keep public class org.jf.smali.main { public static void main(java.lang.String[]); }'
    args '-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }'
    args '-dontwarn com.google.common.base.**'
    args '-dontnote com.google.common.base.**'
}

release.dependsOn(proguard)