@@ -5,36 +5,29 @@ import com.squareup.spoon.SpoonRunner
5
5
import java.io.File
6
6
import java.time.Duration
7
7
import org.gradle.api.DefaultTask
8
- import org.gradle.api.GradleException
9
8
import org.gradle.api.Task
10
9
import org.gradle.api.tasks.TaskAction
11
10
12
11
/* * A [Task] that creates and runs the Spoon test runner. */
13
12
open class SpoonTask : DefaultTask () { // tasks can't be final
14
13
15
14
/* * Use our Spoon extension. */
16
- lateinit var extension: SpoonExtension
15
+ var extension: SpoonExtension = SpoonExtension ()
17
16
18
17
/* * Application APK (eg. app-debug.apk). */
19
- lateinit var applicationApk: File
18
+ var applicationApk: File ? = null
20
19
21
20
/* * Instrumentation APK (eg. app-debug-androidTest.apk). */
22
- lateinit var instrumentationApk: File
21
+ var instrumentationApk: File ? = null
23
22
24
23
/* * Results baseOutputDir. */
25
- lateinit var outputDir: File
26
-
27
- /* * TESTING ONLY */
28
- var testing: Boolean = false
29
- var testValue: Boolean = true
30
- var spoonRenderer: SpoonRunner .Builder ? = null
24
+ var outputDir: File ? = null
31
25
32
26
@Suppress(" unused" )
33
27
@TaskAction
34
28
fun spoonTask () {
35
- if (extension.className.isEmpty() && extension.methodName.isNotEmpty()) {
36
- throw IllegalStateException (" '${extension.methodName} ' must have a fully qualified class " +
37
- " name." )
29
+ check(! (extension.className.isEmpty() and extension.methodName.isNotEmpty())) {
30
+ " '${extension.methodName} ' must have a fully qualified class name."
38
31
}
39
32
40
33
val builder = SpoonRunner .Builder ()
@@ -55,8 +48,10 @@ open class SpoonTask : DefaultTask() { // tasks can't be final
55
48
.setClearAppDataBeforeEachTest(extension.clearAppDataBeforeEachTest)
56
49
57
50
// APKs
58
- if ( ! testing) {
51
+ instrumentationApk?. let {
59
52
builder.setTestApk(instrumentationApk)
53
+ }
54
+ applicationApk?.let {
60
55
builder.addOtherApk(applicationApk)
61
56
}
62
57
@@ -81,8 +76,8 @@ open class SpoonTask : DefaultTask() { // tasks can't be final
81
76
if (extension.instrumentationArgs.isNotEmpty()) {
82
77
val instrumentationArgs = hashMapOf<String , String >()
83
78
extension.instrumentationArgs.forEach { instrumentation ->
84
- if (! (instrumentation.contains(' :' ) or instrumentation.contains(' =' ))) {
85
- throw UnsupportedOperationException ( " Please use '=' or ':' to separate arguments." )
79
+ check (! (instrumentation.contains(' :' ) or instrumentation.contains(' =' ))) {
80
+ " Please use '=' or ':' to separate arguments."
86
81
}
87
82
88
83
val keyVal = if (instrumentation.contains(' :' )) {
@@ -110,12 +105,10 @@ open class SpoonTask : DefaultTask() { // tasks can't be final
110
105
builder.addDevice(it)
111
106
}
112
107
113
- spoonRenderer = builder
108
+ builder.build(). run ()
114
109
115
- val success = if (testing) testValue else builder.build().run ()
116
- if (! success && ! extension.ignoreFailures) {
117
- throw GradleException (" Tests failed! " +
118
- " See ${ConsoleRenderer .asClickableFileUrl(File (outputDir, " index.html" ))} " )
110
+ check(! extension.ignoreFailures) {
111
+ " Tests failed! See ${ConsoleRenderer .asClickableFileUrl(File (outputDir, " index.html" ))} "
119
112
}
120
113
}
121
114
0 commit comments