@@ -34,12 +34,12 @@ import org.gradle.api.Project
3434
3535internal data class TestifySettings (
3636
37- var baselineSourceDir : String ,
38- var moduleName : String ,
39- var outputFileNameFormat : String? ,
40- var pullWaitTime : Long = 0L ,
41- var testRunner : String ,
42- var useSdCard : Boolean ,
37+ val baselineSourceDir : String ,
38+ val moduleName : String ,
39+ val outputFileNameFormat : String? ,
40+ val pullWaitTime : Long = 0L ,
41+ val testRunner : String ,
42+ val useSdCard : Boolean ,
4343
4444 /* *
4545 * The package ID for the test APK
@@ -49,7 +49,7 @@ internal data class TestifySettings(
4949 *
5050 * e.g. com.testify.example.test
5151 */
52- var testPackageId : String ,
52+ val testPackageId : String ,
5353
5454 /* *
5555 * The package ID for the APK under test
@@ -59,61 +59,65 @@ internal data class TestifySettings(
5959 *
6060 * e.g. com.testify.example
6161 */
62- var targetPackageId : String ,
63- var installTask : String? ,
64- var installAndroidTestTask : String? ,
65- var autoImplementLibrary : Boolean = true
62+ val targetPackageId : String ,
63+ val installTask : String? ,
64+ val installAndroidTestTask : String? ,
65+ val autoImplementLibrary : Boolean = true
6666) {
6767
68- fun override ( extension : TestifyExtension ): TestifySettings {
69- if (extension.baselineSourceDir?.isNotEmpty() == true ) {
70- this .baselineSourceDir = extension.baselineSourceDir !!
71- }
72- if (extension.moduleName?.isNotEmpty() == true ) {
73- this .moduleName = extension.moduleName !!
74- }
75- if ( extension.outputFileNameFormat?.isNotEmpty() == true ) {
76- this .outputFileNameFormat = extension.outputFileNameFormat !!
77- }
78- if (extension.pullWaitTime != null ) {
79- this .pullWaitTime = extension.pullWaitTime !!
80- }
81- if (extension.testRunner?.isNotEmpty() == true ) {
82- this .testRunner = extension.testRunner !!
83- }
84- if (extension.useSdCard != null ) {
85- this .useSdCard = extension.useSdCard !!
86- }
87- if (extension.testPackageId?.isNotEmpty() == true ) {
88- this .testPackageId = extension.testPackageId !!
89- }
90- if (extension.applicationPackageId?.isNotEmpty() == true ) {
91- this .targetPackageId = extension.applicationPackageId !!
92- }
93- if (extension.installTask?.isNotEmpty() == true ) {
94- this .installTask = extension.installTask
95- }
96- if (extension.installAndroidTestTask?.isNotEmpty() == true ) {
97- this .installAndroidTestTask = extension.installAndroidTestTask
98- }
99- if (extension. autoImplementLibrary != null ) {
100- this .autoImplementLibrary = extension.autoImplementLibrary !!
68+ internal companion object {
69+ fun create ( project : Project ): TestifySettings {
70+ val android = project.android
71+ val extension = project.getTestifyExtension()
72+
73+ val assetsSet = android.sourceSets.getByName( """ androidTest """ ).assets
74+ val baselineSourceDir = extension.baselineSourceDir ? : assetsSet.srcDirs.first().path
75+ val testRunner = extension.testRunner ? : android.defaultConfig.testInstrumentationRunner ? : " unknown "
76+ val pullWaitTime = extension.pullWaitTime ? : 0L
77+ val testPackageId = extension.testPackageId ? : project.inferredDefaultTestVariantId
78+ val targetPackageId = extension.applicationPackageId ? : project.inferredTargetPackageId
79+ val version = TestifySettings :: class .java.getPackage().implementationVersion
80+ val autoImplementLibrary = extension.autoImplementLibrary
81+ ? : version?.contains( " local " , ignoreCase = true ) == false
82+ val useSdCard = extension.useSdCard ? : false
83+ val installTask = extension.installTask ? : project.inferredInstallTask
84+ val outputFileNameFormat = extension.outputFileNameFormat
85+ val installAndroidTestTask = extension.installAndroidTestTask ? : project.inferredAndroidTestInstallTask
86+ val moduleName = extension.moduleName ? : project.name
87+
88+ return TestifySettings (
89+ baselineSourceDir = baselineSourceDir,
90+ moduleName = moduleName,
91+ outputFileNameFormat = outputFileNameFormat,
92+ pullWaitTime = pullWaitTime,
93+ testRunner = testRunner,
94+ useSdCard = useSdCard,
95+ testPackageId = testPackageId,
96+ targetPackageId = targetPackageId,
97+ installTask = installTask,
98+ installAndroidTestTask = installAndroidTestTask,
99+ autoImplementLibrary = autoImplementLibrary
100+ )
101101 }
102- return this
103102 }
104103
105104 fun validate () {
106- if (targetPackageId.isEmpty()) {
107- throw GradleExtensionException (
108- """
105+ val (propertyName, examplePackage) = when {
106+ targetPackageId.isEmpty() -> " applicationPackageId" to " com.example.app"
107+ testPackageId.isEmpty() -> " testPackageId" to " com.example.app.test"
108+ else -> null to null
109+ }
110+
111+ propertyName?.let {
112+ val message = """
109113
110- You must define an `applicationPackageId ` in your `testify` gradle extension block:
114+ You must define ` $it ` in your `testify` gradle extension block:
111115
112116 testify {
113- applicationPackageId "com.example.app "
117+ $it " $examplePackage "
114118 }
115119 """
116- )
120+ throw GradleExtensionException (message )
117121 }
118122 }
119123}
@@ -139,39 +143,6 @@ private val Project.inferredTargetPackageId: String
139143 return targetPackageId
140144 }
141145
142- internal class TestifySettingsFactory {
143-
144- companion object {
145-
146- fun create (project : Project ): TestifySettings {
147- val android = project.android
148- val assetsSet = android.sourceSets.getByName(""" androidTest""" ).assets
149- val baselineSourceDir = " ${assetsSet?.srcDirs?.first()?.path} "
150- val testRunner = android.defaultConfig.testInstrumentationRunner ? : " unknown"
151- val testPackageId = project.inferredDefaultTestVariantId
152- val targetPackageId = project.inferredTargetPackageId
153- val installTask = project.inferredInstallTask
154- val installAndroidTestTask = project.inferredAndroidTestInstallTask
155- val version = TestifySettingsFactory ::class .java.getPackage().implementationVersion
156-
157- // Defaults
158- return TestifySettings (
159- baselineSourceDir = baselineSourceDir,
160- moduleName = project.name,
161- outputFileNameFormat = null ,
162- pullWaitTime = 0L ,
163- testRunner = testRunner,
164- useSdCard = false ,
165- testPackageId = testPackageId,
166- targetPackageId = targetPackageId,
167- installTask = installTask,
168- installAndroidTestTask = installAndroidTestTask,
169- autoImplementLibrary = version?.contains(" local" , ignoreCase = true ) == false
170- )
171- }
172- }
173- }
174-
175146open class TestifyExtension {
176147
177148 var baselineSourceDir: String? = null
0 commit comments