buildscript: fix task not found errors when android sdk not available (#1161)

* buildscript: fix task not found errors when android sdk not available

* fix: this shadowed by run

* cleanup: code style

* improve: avoid breaking index map
This commit is contained in:
AdoptOSS 2021-04-05 22:35:38 +08:00 committed by GitHub
parent 45294e1538
commit 21e8852e0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 34 deletions

View File

@ -42,12 +42,14 @@ object CompiledCodeVerify {
sequenceOf("kotlin/main") sequenceOf("kotlin/main")
}.map { sequenceOf(project.buildDir.resolve("classes").resolve(it)) } }.map { sequenceOf(project.buildDir.resolve("classes").resolve(it)) }
private fun getLibraries(project: Project, info: ProjectInfo): Sequence<Sequence<File>> = private fun getLibraries(project: Project, info: ProjectInfo): Sequence<Sequence<File>?> =
if (info.isMpp) { if (info.isMpp) {
sequenceOf("jvmCompileClasspath", "androidCompileClasspath") sequenceOf("jvmCompileClasspath", "androidCompileClasspath")
} else { } else {
sequenceOf("compileClasspath") sequenceOf("compileClasspath")
}.map { project.configurations.getByName(it).files.asSequence() } }.map {
project.configurations.findByName(it)?.files?.asSequence()
}
fun Project.registerVerifyTask(taskName: String, action: VerifyAction) { fun Project.registerVerifyTask(taskName: String, action: VerifyAction) {
@ -55,12 +57,18 @@ object CompiledCodeVerify {
tasks.register(taskName) { tasks.register(taskName) {
group = VERIFICATION_GROUP_NAME group = VERIFICATION_GROUP_NAME
mustRunAfter(*projectInfo.compileTasks) projectInfo.compileTasks.forEach {
tasks.findByPath(it)?.also { compileTask ->
mustRunAfter(compileTask)
}
}
doFirst { doFirst {
getCompiledClassesPath(project, projectInfo).zip(getLibraries(project, projectInfo)) getCompiledClassesPath(project, projectInfo).zip(getLibraries(project, projectInfo))
.forEach { (compiledClasses, libraries) -> .forEach { (compiledClasses, libraries) ->
action(compiledClasses, libraries) if (libraries != null) {
action(compiledClasses, libraries)
}
} }
} }
} }

View File

@ -101,18 +101,20 @@ kotlin {
} }
} }
tasks.register("checkAndroidApiLevel") { if (isAndroidSDKAvailable) {
doFirst { tasks.register("checkAndroidApiLevel") {
analyzes.AndroidApiLevelCheck.check( doFirst {
buildDir.resolve("classes/kotlin/android/main"), analyzes.AndroidApiLevelCheck.check(
project.property("mirai.android.target.api.level")!!.toString().toInt(), buildDir.resolve("classes/kotlin/android/main"),
project project.property("mirai.android.target.api.level")!!.toString().toInt(),
) project
)
}
group = "verification"
this.mustRunAfter("androidMainClasses")
} }
group = "verification" tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
this.mustRunAfter("androidMainClasses")
} }
tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) = fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) =
implementation(dependencyNotation) { implementation(dependencyNotation) {

View File

@ -89,18 +89,20 @@ kotlin {
} }
} }
tasks.register("checkAndroidApiLevel") { if (isAndroidSDKAvailable) {
doFirst { tasks.register("checkAndroidApiLevel") {
analyzes.AndroidApiLevelCheck.check( doFirst {
buildDir.resolve("classes/kotlin/android/main"), analyzes.AndroidApiLevelCheck.check(
project.property("mirai.android.target.api.level")!!.toString().toInt(), buildDir.resolve("classes/kotlin/android/main"),
project project.property("mirai.android.target.api.level")!!.toString().toInt(),
) project
)
}
group = "verification"
this.mustRunAfter("androidMainClasses")
} }
group = "verification" tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
this.mustRunAfter("androidMainClasses")
} }
tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) = fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) =
implementation(dependencyNotation) { implementation(dependencyNotation) {

View File

@ -114,18 +114,20 @@ kotlin {
} }
} }
tasks.register("checkAndroidApiLevel") { if (isAndroidSDKAvailable) {
doFirst { tasks.register("checkAndroidApiLevel") {
analyzes.AndroidApiLevelCheck.check( doFirst {
buildDir.resolve("classes/kotlin/android/main"), analyzes.AndroidApiLevelCheck.check(
project.property("mirai.android.target.api.level")!!.toString().toInt(), buildDir.resolve("classes/kotlin/android/main"),
project project.property("mirai.android.target.api.level")!!.toString().toInt(),
) project
)
}
group = "verification"
this.mustRunAfter("androidMainClasses")
} }
group = "verification" tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
this.mustRunAfter("androidMainClasses")
} }
tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) = fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) =
implementation(dependencyNotation) { implementation(dependencyNotation) {