1*37f5703cSAndroid Build Coastguard Worker/* 2*37f5703cSAndroid Build Coastguard Worker * Copyright 2012, Google LLC 3*37f5703cSAndroid Build Coastguard Worker * 4*37f5703cSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 5*37f5703cSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are 6*37f5703cSAndroid Build Coastguard Worker * met: 7*37f5703cSAndroid Build Coastguard Worker * 8*37f5703cSAndroid Build Coastguard Worker * * Redistributions of source code must retain the above copyright 9*37f5703cSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 10*37f5703cSAndroid Build Coastguard Worker * * Redistributions in binary form must reproduce the above 11*37f5703cSAndroid Build Coastguard Worker * copyright notice, this list of conditions and the following disclaimer 12*37f5703cSAndroid Build Coastguard Worker * in the documentation and/or other materials provided with the 13*37f5703cSAndroid Build Coastguard Worker * distribution. 14*37f5703cSAndroid Build Coastguard Worker * * Neither the name of Google LLC nor the names of its 15*37f5703cSAndroid Build Coastguard Worker * contributors may be used to endorse or promote products derived from 16*37f5703cSAndroid Build Coastguard Worker * this software without specific prior written permission. 17*37f5703cSAndroid Build Coastguard Worker * 18*37f5703cSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19*37f5703cSAndroid Build Coastguard Worker * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20*37f5703cSAndroid Build Coastguard Worker * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21*37f5703cSAndroid Build Coastguard Worker * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22*37f5703cSAndroid Build Coastguard Worker * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23*37f5703cSAndroid Build Coastguard Worker * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24*37f5703cSAndroid Build Coastguard Worker * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25*37f5703cSAndroid Build Coastguard Worker * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26*37f5703cSAndroid Build Coastguard Worker * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27*37f5703cSAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28*37f5703cSAndroid Build Coastguard Worker * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29*37f5703cSAndroid Build Coastguard Worker */ 30*37f5703cSAndroid Build Coastguard Worker 31*37f5703cSAndroid Build Coastguard Workerext.testAccessorOutputDir = file("${buildDir}/generated-src/accessorTest/java") 32*37f5703cSAndroid Build Coastguard Workerext.testAccessorOutputFile = file("${testAccessorOutputDir}/com/android/tools/smali/dexlib2/AccessorTypes.java") 33*37f5703cSAndroid Build Coastguard Worker 34*37f5703cSAndroid Build Coastguard WorkersourceSets { 35*37f5703cSAndroid Build Coastguard Worker main { 36*37f5703cSAndroid Build Coastguard Worker java { 37*37f5703cSAndroid Build Coastguard Worker srcDirs "${project.rootDir}/third_party/dexlib2/src/main/java" 38*37f5703cSAndroid Build Coastguard Worker } 39*37f5703cSAndroid Build Coastguard Worker } 40*37f5703cSAndroid Build Coastguard Worker accessorTest { 41*37f5703cSAndroid Build Coastguard Worker java { 42*37f5703cSAndroid Build Coastguard Worker srcDir testAccessorOutputDir 43*37f5703cSAndroid Build Coastguard Worker } 44*37f5703cSAndroid Build Coastguard Worker } 45*37f5703cSAndroid Build Coastguard Worker} 46*37f5703cSAndroid Build Coastguard Worker 47*37f5703cSAndroid Build Coastguard Workerconfigurations { 48*37f5703cSAndroid Build Coastguard Worker accessorTestGenerator 49*37f5703cSAndroid Build Coastguard Worker dx 50*37f5703cSAndroid Build Coastguard Worker} 51*37f5703cSAndroid Build Coastguard Worker 52*37f5703cSAndroid Build Coastguard Workerdependencies { 53*37f5703cSAndroid Build Coastguard Worker implementation depends.findbugs 54*37f5703cSAndroid Build Coastguard Worker implementation depends.guava 55*37f5703cSAndroid Build Coastguard Worker 56*37f5703cSAndroid Build Coastguard Worker testImplementation depends.junit 57*37f5703cSAndroid Build Coastguard Worker testImplementation depends.mockito 58*37f5703cSAndroid Build Coastguard Worker 59*37f5703cSAndroid Build Coastguard Worker accessorTestGenerator project('accessorTestGenerator') 60*37f5703cSAndroid Build Coastguard Worker 61*37f5703cSAndroid Build Coastguard Worker dx depends.dx 62*37f5703cSAndroid Build Coastguard Worker} 63*37f5703cSAndroid Build Coastguard Worker 64*37f5703cSAndroid Build Coastguard Worker// You must manually execute this task to regenerate SyntheticAccessorFSM.java, after modifying the ragel file 65*37f5703cSAndroid Build Coastguard Worker// e.g. ./gradlew ragel 66*37f5703cSAndroid Build Coastguard Workertask ragel(type:Exec) { 67*37f5703cSAndroid Build Coastguard Worker workingDir = 'src/main/ragel' 68*37f5703cSAndroid Build Coastguard Worker 69*37f5703cSAndroid Build Coastguard Worker commandLine 'ragel', '-J', '-o', file('src/main/java/com/android/tools/smali/dexlib2/util/SyntheticAccessorFSM.java'), 70*37f5703cSAndroid Build Coastguard Worker 'SyntheticAccessorFSM.rl' 71*37f5703cSAndroid Build Coastguard Worker} 72*37f5703cSAndroid Build Coastguard Worker 73*37f5703cSAndroid Build Coastguard Workertask generateAccessorTestSource(type: JavaExec) { 74*37f5703cSAndroid Build Coastguard Worker file(testAccessorOutputFile.parent).mkdirs() 75*37f5703cSAndroid Build Coastguard Worker outputs.dir file(testAccessorOutputDir) 76*37f5703cSAndroid Build Coastguard Worker 77*37f5703cSAndroid Build Coastguard Worker classpath = configurations.accessorTestGenerator 78*37f5703cSAndroid Build Coastguard Worker main = 'com.android.tools.smali.dexlib2.AccessorTestGenerator' 79*37f5703cSAndroid Build Coastguard Worker args testAccessorOutputFile 80*37f5703cSAndroid Build Coastguard Worker} 81*37f5703cSAndroid Build Coastguard WorkercompileAccessorTestJava.dependsOn(generateAccessorTestSource) 82*37f5703cSAndroid Build Coastguard Worker 83*37f5703cSAndroid Build Coastguard Worker// You must manually execute this task to regenerate src/test/resources/accessorTest.dex 84*37f5703cSAndroid Build Coastguard Workertask generateAccessorTestDex(type: JavaExec, dependsOn: compileAccessorTestJava) { 85*37f5703cSAndroid Build Coastguard Worker def outputDex = file('src/test/resources/accessorTest.dex') 86*37f5703cSAndroid Build Coastguard Worker file(outputDex.parent).mkdirs() 87*37f5703cSAndroid Build Coastguard Worker 88*37f5703cSAndroid Build Coastguard Worker inputs.dir(project.sourceSets.accessorTest.output.classesDirs) 89*37f5703cSAndroid Build Coastguard Worker outputs.file outputDex 90*37f5703cSAndroid Build Coastguard Worker 91*37f5703cSAndroid Build Coastguard Worker main 'com.android.dx.command.Main' 92*37f5703cSAndroid Build Coastguard Worker classpath = configurations.dx 93*37f5703cSAndroid Build Coastguard Worker 94*37f5703cSAndroid Build Coastguard Worker args '--dex' 95*37f5703cSAndroid Build Coastguard Worker args '--no-strict' 96*37f5703cSAndroid Build Coastguard Worker args "--output=${outputDex}" 97*37f5703cSAndroid Build Coastguard Worker args sourceSets.accessorTest.output.classesDirs 98*37f5703cSAndroid Build Coastguard Worker} 99*37f5703cSAndroid Build Coastguard Worker 100*37f5703cSAndroid Build Coastguard Workerpublish { 101*37f5703cSAndroid Build Coastguard Worker publishing { 102*37f5703cSAndroid Build Coastguard Worker publications { 103*37f5703cSAndroid Build Coastguard Worker mavenJava(MavenPublication) { 104*37f5703cSAndroid Build Coastguard Worker pom { 105*37f5703cSAndroid Build Coastguard Worker description = 'dexlib2 is a library for reading/modifying/writing Android dex files' 106*37f5703cSAndroid Build Coastguard Worker scm { 107*37f5703cSAndroid Build Coastguard Worker url = 'https://github.com/google/smali/tree/master/dexlib2' 108*37f5703cSAndroid Build Coastguard Worker } 109*37f5703cSAndroid Build Coastguard Worker } 110*37f5703cSAndroid Build Coastguard Worker } 111*37f5703cSAndroid Build Coastguard Worker } 112*37f5703cSAndroid Build Coastguard Worker } 113*37f5703cSAndroid Build Coastguard Worker} 114