Files
jadx/jadx-test-app/build.gradle
T

71 lines
1.7 KiB
Groovy

ext {
testAppDir = 'test-app'
testAppTmpDir = 'test-app-tmp'
tmpBuildFile = "${testAppTmpDir}/build.gradle"
apkFile = "${testAppTmpDir}/build/outputs/apk/test-app-tmp-debug.apk"
outCodeDir = "${testAppTmpDir}/src/main"
checkTask = 'connectedCheck'
}
dependencies {
compile(project(":jadx-cli"))
}
task deleteTmp(type:Delete) {
delete testAppTmpDir
}
task copyApp(type:Copy, dependsOn: deleteTmp) {
from testAppDir
into testAppTmpDir
}
task buildApp(type:Exec, dependsOn: copyApp) {
workingDir testAppTmpDir
commandLine "./gradlew clean build ${checkTask}".split(' ')
}
task removeSource(type:Delete, dependsOn: buildApp) {
delete outCodeDir
}
task runJadx(type: JavaExec, dependsOn: removeSource) {
classpath = sourceSets.main.output + configurations.compile
main = project(':jadx-cli').mainClassName
args = ['-d', testAppTmpDir, apkFile, '-v', '-e']
}
task decompile(dependsOn: runJadx) {
doLast {
injectDependencies()
}
}
def injectDependencies() {
def fileContent = file(tmpBuildFile).getText('UTF-8')
def updatedContent = fileContent.replaceAll(
'// some dependencies',
"""
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
""")
file(tmpBuildFile).write(updatedContent, 'UTF-8')
}
task runChecks(type:Exec, dependsOn: decompile) {
workingDir testAppTmpDir
commandLine "./gradlew clean build ${checkTask}".split(' ')
}
task testAppCheck(dependsOn: runChecks) {
doFirst {
def buildFile = file(buildFile)
if (!buildFile.exists() || !buildFile.isFile()) {
throw new StopExecutionException("Test app not found")
}
}
}
clean.dependsOn deleteTmp