Skip to content

Commit 238a76c

Browse files
committed
add: android plugin code.
1 parent 7b21afa commit 238a76c

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

androidplugin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
`kotlin-dsl`
23
kotlin("jvm") version "1.9.23"
34
id("java-gradle-plugin")
45
id("com.google.protobuf") version "0.9.0"

androidplugin/src/main/java/dev/oianmol/opentestlab/tasks/AndroidTestDeviceFarmTask.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ abstract class AndroidTestDeviceFarmTask : DefaultTask() {
1919

2020
@TaskAction
2121
fun connectDevices() {
22-
dumpDebugLog("We will now build debug and androidtest apks")
23-
24-
project.buildProjects()
25-
26-
dumpDebugLog("We will now Android Test in HYD test lab")
27-
2822
runBlocking {
2923
val channel = managedChannel()
3024
runCatchingCancellable {
@@ -235,15 +229,3 @@ private fun Project.testApks(): Pair<File, File> {
235229
require(apk != null)
236230
return Pair(testApk, apk)
237231
}
238-
239-
private fun Project.buildProjects() {
240-
exec {
241-
it.workingDir(projectDir.parentFile)
242-
it.commandLine("./gradlew", "app:assembleDebug")
243-
}
244-
245-
exec {
246-
it.workingDir(projectDir.parentFile)
247-
it.commandLine("./gradlew", "app:assembleDebugAndroidTest")
248-
}
249-
}

androidplugin/src/main/java/dev/oianmol/opentestlab/tasks/DeviceFarmPlugin.kt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,39 @@ import org.gradle.api.Plugin
55
import org.gradle.api.Project
66

77
class DeviceFarmPlugin : Plugin<Project> {
8+
companion object {
9+
const val GRADLE_METHOD_NAME = "configureOpenDeviceFarm"
10+
}
11+
812
override fun apply(project: Project) {
913
with(project) {
10-
deviceFarm()
14+
project.extensions.create(
15+
GRADLE_METHOD_NAME,
16+
DeviceFarmPluginExtension::class.java,
17+
project
18+
)
19+
20+
project.afterEvaluate {
21+
logger.lifecycle("*************** Open Test Lab Plugin ***************")
22+
deviceFarm()
23+
logger.lifecycle("********************************************************")
24+
}
1125
}
1226
}
1327
}
1428

1529
fun Project.deviceFarm() {
16-
tasks.register(
17-
"assembleDebugAndroidOpenTestLab",
18-
AndroidTestDeviceFarmTask::class.java,
19-
)
30+
project.extensions.findByType(DeviceFarmPluginExtension::class.java)?.apply {
31+
this.applicationId?.let {
32+
tasks.register(
33+
"executeDeviceFarmFor${it.replace(".", "dot")}",
34+
AndroidTestDeviceFarmTask::class.java,
35+
)
2036

21-
tasks.register(
22-
"pullTestReportFiles",
23-
TestLabPullReportTask::class.java,
24-
)
37+
tasks.register(
38+
"pullLatestTestReportFor${it.replace(".", "dot")}",
39+
TestLabPullReportTask::class.java,
40+
)
41+
}
42+
}
2543
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dev.oianmol.opentestlab.tasks
2+
3+
import org.gradle.api.Project
4+
5+
open class DeviceFarmPluginExtension(private val project: Project) {
6+
var applicationId:String? = null
7+
}

androidplugin/src/main/java/dev/oianmol/opentestlab/tasks/getCurrentGitBranchName.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import java.io.ByteArrayOutputStream
66
fun Project.getCurrentGitBranchName(): String {
77
val stdout = ByteArrayOutputStream()
88
exec {
9-
it.commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
10-
it.standardOutput = stdout
9+
this.commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
10+
this.standardOutput = stdout
1111
}
1212
return stdout.toString().trim()
1313
}

0 commit comments

Comments
 (0)