This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.gradle
109 lines (85 loc) · 2.89 KB
/
build.gradle
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
plugins {
id 'java'
id 'application'
}
mainClassName = 'sh.calaba.screenshot.ScreenshotTaker'
sourceSets {
intTest {
java.srcDir file('src/intTest/java')
compileClasspath += sourceSets.main.output + configurations.testRuntime
runtimeClasspath += output + compileClasspath
}
}
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
testCompile 'junit:junit:4.12'
}
repositories {
jcenter()
}
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Main-Class': 'sh.calaba.screenshot.ScreenshotTaker'
}
baseName = 'screenshotTaker'
}
task integrationTest(type: JavaExec) {
def imageFromAppFileName = 'screenshotTakerTest.png'
def imageFromAdbFileName = 'adbScreenshotTest.png'
doFirst {
def androidHome = System.getenv('ANDROID_HOME')
if (androidHome == null) {
throw new GradleException('ANDROID_HOME environment variable must be set to proper Android SDK location before executiong this test')
}
def adb = new File(androidHome, 'platform-tools/adb')
def jar = new File(rootDir, 'screenshotTaker.jar')
String deviceSerial = null;
def getSerailResult = exec {
standardOutput = new ByteArrayOutputStream();
ignoreExitValue = true
commandLine adb, 'get-serialno'
ext.output = {
return standardOutput.toString()
}
}
if (getSerailResult.getExitValue() == 0) {
deviceSerial = ext.output().trim()
} else {
deviceSerial = System.getenv('ADB_SERIAL')
if (deviceSerial == null) {
System.out.println(ext.output())
exec {
commandLine adb, 'devices'
}
def message = 'Please set ADB_SERIAL environment variable to identify the device: $ ADB_SERIAL=<serial number> gradlew integrationTest'
System.out.println(message)
throw new GradleException()
}
}
javaexec {
main = "-jar"
args = [jar, deviceSerial, new File(rootDir, imageFromAppFileName)]
}
def pathOnDevice = "/sdcard/$imageFromAdbFileName"
exec {
commandLine adb, '-s', deviceSerial, 'shell', 'screencap', pathOnDevice
}
exec {
commandLine adb, '-s', deviceSerial, 'pull', pathOnDevice, new File(rootDir, imageFromAdbFileName)
}
}
description = 'Runs integration tests.'
group = 'verification'
main = 'src.ScreenshotTakerTest'
classpath = sourceSets.intTest.runtimeClasspath
args = [imageFromAppFileName, imageFromAdbFileName]
dependsOn build
}
tasks.withType(Jar) {
destinationDir = rootDir
}