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    accessorTestGenerator
34}
35
36dependencies {
37    compile project(':util')
38    compile depends.findbugs
39    compile depends.guava
40
41    testCompile depends.junit
42
43    accessorTestGenerator project('accessorTestGenerator')
44}
45
46ext.testAccessorOutputDir = file("${buildDir}/generated-accessor-test-sources")
47ext.testAccessorOutputFile = file("${buildDir}/generated-accessor-test-sources/org/jf/dexlib2/AccessorTypes.java")
48
49sourceSets {
50    // The sources for building the test dex file for the accessor test
51    accessorTestDex {
52        java {
53            srcDir testAccessorOutputDir
54        }
55    }
56
57    // The sources for the accessor test itself
58    accessorTest {
59        java {
60            compileClasspath += main.output
61            runtimeClasspath += main.output
62        }
63    }
64}
65
66configurations {
67    accessorTestDexCompile.extendsFrom compile
68    accessorTestDexRuntime.extendsFrom runtime
69
70    accessorTestCompile.extendsFrom testCompile
71    accessorTestRuntime.extendsFrom testRuntime
72}
73
74idea {
75    module {
76        testSourceDirs += sourceSets.accessorTest.java.srcDirs
77    }
78}
79
80// You must manually execute this task to regenerate SyntheticAccessorFSM.java, after modifying the ragel file
81// e.g. ./gradlew ragel
82task ragel(type:Exec) {
83    workingDir = 'src/main/ragel'
84
85    commandLine 'ragel', '-J', '-o', file('src/main/java/org/jf/dexlib2/util/SyntheticAccessorFSM.java'),
86            'SyntheticAccessorFSM.rl'
87}
88
89task generateAccessorTestSource(type: JavaExec) {
90    outputs.dir file(testAccessorOutputDir)
91
92    mkdir(file(testAccessorOutputFile).parent)
93
94    classpath = configurations.accessorTestGenerator
95    main = 'org.jf.dexlib2.AccessorTestGenerator'
96    args testAccessorOutputFile
97}
98compileAccessorTestDexJava.dependsOn(generateAccessorTestSource)
99
100task generateAccessorTestDex(type: Exec, dependsOn: compileAccessorTestDexJava) {
101    def outputDex = file("${sourceSets.accessorTest.output.resourcesDir}/accessorTest.dex")
102    mkdir(outputDex.parent)
103
104    inputs.dir project.sourceSets.accessorTestDex.output.classesDir
105    outputs.file outputDex
106
107    sourceSets.accessorTest.resources
108
109    workingDir project.sourceSets.accessorTestDex.output.classesDir
110    executable 'dx'
111    args '--dex'
112    args "--output=${outputDex}"
113    args '.'
114}
115
116task accessorTest(type: Test, dependsOn: generateAccessorTestDex) {
117    testClassesDir = project.sourceSets.accessorTest.output.classesDir
118    classpath = project.sourceSets.accessorTest.runtimeClasspath
119}
120
121task sourcesJar(type: Jar) {
122    classifier = 'sources'
123    from sourceSets.main.allJava
124}
125
126artifacts {
127    archives sourcesJar
128}
129
130uploadArchives {
131    repositories.mavenDeployer {
132        pom.project {
133            description 'dexlib2 is a library for reading/modifying/writing Android dex files'
134            scm {
135                url 'https://github.com/JesusFreke/smali/tree/master/dexlib2'
136            }
137        }
138    }
139}