mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge e7e09f6ca36481d5361ff21cf9af3a56be8f1f92 into 06df71c51446e96939c6a615b7c34ce9123806ba
This commit is contained in:
commit
03eac0d31d
@ -12,12 +12,14 @@ import com.android.build.gradle.tasks.ProcessAndroidResources
|
||||
import com.android.builder.model.BuildType
|
||||
import com.flutter.gradle.plugins.PluginHandler
|
||||
import com.flutter.gradle.tasks.DeepLinkJsonFromManifestTask
|
||||
import com.flutter.gradle.tasks.PrintTask
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.UnknownTaskException
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.kotlin.dsl.register
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.Properties
|
||||
@ -708,12 +710,10 @@ object FlutterPluginUtils {
|
||||
@JvmStatic
|
||||
@JvmName("addTaskForJavaVersion")
|
||||
internal fun addTaskForJavaVersion(project: Project) {
|
||||
project.tasks.register("javaVersion") {
|
||||
project.tasks.register<PrintTask>("javaVersion") {
|
||||
description = "Print the current java version used by gradle. see: " +
|
||||
"https://docs.gradle.org/current/javadoc/org/gradle/api/JavaVersion.html"
|
||||
doLast {
|
||||
println(VersionFetcher.getJavaVersion())
|
||||
}
|
||||
message.set(VersionFetcher.getJavaVersion().toString())
|
||||
}
|
||||
}
|
||||
|
||||
@ -727,11 +727,9 @@ object FlutterPluginUtils {
|
||||
@JvmStatic
|
||||
@JvmName("addTaskForKGPVersion")
|
||||
internal fun addTaskForKGPVersion(project: Project) {
|
||||
project.tasks.register("kgpVersion") {
|
||||
project.tasks.register<PrintTask>("kgpVersion") {
|
||||
description = "Print the current kgp version used by the project."
|
||||
doLast {
|
||||
println("KGP Version: " + VersionFetcher.getKGPVersion(project).toString())
|
||||
}
|
||||
message.set(project.provider { "KGP Version: " + VersionFetcher.getKGPVersion(project).toString() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -748,16 +746,19 @@ object FlutterPluginUtils {
|
||||
@JvmStatic
|
||||
@JvmName("addTaskForPrintBuildVariants")
|
||||
internal fun addTaskForPrintBuildVariants(project: Project) {
|
||||
// Groovy was dynamically getting a different subtype here than our Kotlin getAndroidExtension method.
|
||||
// TODO(gmackall): We should take another pass at the different types we are using in our conversion of
|
||||
// the groovy `flutter.android` lines.
|
||||
val androidExtension = project.extensions.getByType(AbstractAppExtension::class.java)
|
||||
project.tasks.register("printBuildVariants") {
|
||||
project.tasks.register<PrintTask>("printBuildVariants") {
|
||||
description = "Prints out all build variants for this Android project"
|
||||
doLast {
|
||||
project.provider {
|
||||
// Groovy was dynamically getting a different subtype here than our Kotlin getAndroidExtension method.
|
||||
// TODO(gmackall): We should take another pass at the different types we are using in our conversion of
|
||||
// the groovy `flutter.android` lines.
|
||||
val androidExtension = project.extensions.getByType(AbstractAppExtension::class.java)
|
||||
|
||||
val messageBuilder = StringBuilder()
|
||||
androidExtension.applicationVariants.forEach { variant ->
|
||||
println("BuildVariant: ${variant.name}")
|
||||
messageBuilder.append("BuildVariant: ${variant.name}\n")
|
||||
}
|
||||
message.set(messageBuilder.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.flutter.gradle.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class PrintTask : DefaultTask() {
|
||||
@get:Input
|
||||
abstract val message: Property<String>
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
println(message.get())
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ import com.android.build.gradle.internal.core.InternalBaseVariant
|
||||
import com.android.build.gradle.tasks.MergeSourceSetFolders
|
||||
import com.android.build.gradle.tasks.ProcessAndroidResources
|
||||
import com.flutter.gradle.tasks.FlutterTask
|
||||
import com.flutter.gradle.tasks.PrintTask
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkObject
|
||||
@ -28,6 +29,7 @@ import org.junit.jupiter.api.io.TempDir
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.writeText
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContains
|
||||
|
||||
class FlutterPluginTest {
|
||||
@Test
|
||||
@ -88,8 +90,15 @@ class FlutterPluginTest {
|
||||
flutterPlugin.apply(project)
|
||||
|
||||
verify { project.tasks.register("generateLockfiles", any()) }
|
||||
verify { project.tasks.register("javaVersion", any()) }
|
||||
verify { project.tasks.register("printBuildVariants", any()) }
|
||||
|
||||
val registeredPrintTasks = mutableListOf<String>()
|
||||
verify {
|
||||
project.tasks.register(capture(registeredPrintTasks), PrintTask::class.java, any())
|
||||
}
|
||||
|
||||
assertContains(registeredPrintTasks, "javaVersion")
|
||||
assertContains(registeredPrintTasks, "kgpVersion")
|
||||
assertContains(registeredPrintTasks, "printBuildVariants")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -10,6 +10,7 @@ import com.android.build.gradle.internal.dsl.CmakeOptions
|
||||
import com.android.build.gradle.internal.dsl.DefaultConfig
|
||||
import com.android.builder.model.BuildType
|
||||
import com.flutter.gradle.plugins.PluginHandler
|
||||
import com.flutter.gradle.tasks.PrintTask
|
||||
import io.mockk.called
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
@ -24,6 +25,8 @@ import org.gradle.api.UnknownTaskException
|
||||
import org.gradle.api.file.Directory
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.api.tasks.TaskContainer
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.extraProperties
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
@ -34,6 +37,7 @@ import kotlin.io.path.createDirectory
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContains
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
class FlutterPluginUtilsTest {
|
||||
companion object {
|
||||
@ -1006,40 +1010,54 @@ class FlutterPluginUtilsTest {
|
||||
}
|
||||
}
|
||||
|
||||
// addTaskForJavaVersion
|
||||
@Test
|
||||
fun `addTaskForJavaVersion adds task for Java version`() {
|
||||
val project = mockk<Project>()
|
||||
every { project.tasks.register(any(), any<Action<Task>>()) } returns mockk()
|
||||
val captureSlot = slot<Action<Task>>()
|
||||
FlutterPluginUtils.addTaskForJavaVersion(project)
|
||||
verify { project.tasks.register("javaVersion", capture(captureSlot)) }
|
||||
val taskContainer = mockk<TaskContainer>()
|
||||
every { project.tasks } returns taskContainer
|
||||
val mockTaskProvider = mockk<TaskProvider<PrintTask>>()
|
||||
val mockPrintTask = mockk<PrintTask>(relaxed = true)
|
||||
val captureSlot = slot<Action<PrintTask>>()
|
||||
|
||||
every {
|
||||
project.tasks.register(eq("javaVersion"), PrintTask::class.java, capture(captureSlot))
|
||||
} returns mockTaskProvider
|
||||
|
||||
FlutterPluginUtils.addTaskForJavaVersion(project)
|
||||
captureSlot.captured.execute(mockPrintTask)
|
||||
|
||||
val mockTask = mockk<Task>()
|
||||
every { mockTask.description = any() } returns Unit
|
||||
every { mockTask.doLast(any<Action<Task>>()) } returns mockk()
|
||||
captureSlot.captured.execute(mockTask)
|
||||
verify {
|
||||
mockTask.description = "Print the current java version used by gradle. see: " +
|
||||
mockPrintTask.description = "Print the current java version used by gradle. see: " +
|
||||
"https://docs.gradle.org/current/javadoc/org/gradle/api/JavaVersion.html"
|
||||
}
|
||||
verify {
|
||||
mockPrintTask.message.set(
|
||||
withArg<String> { assertNotNull(it.toIntOrNull(), message = "$it java version is not an int") }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// addTaskForKGPVersion
|
||||
@Test
|
||||
fun `addTaskForKGPVersion adds task for KGP version`() {
|
||||
val project = mockk<Project>()
|
||||
every { project.tasks.register(any(), any<Action<Task>>()) } returns mockk()
|
||||
val captureSlot = slot<Action<Task>>()
|
||||
FlutterPluginUtils.addTaskForKGPVersion(project)
|
||||
verify { project.tasks.register("kgpVersion", capture(captureSlot)) }
|
||||
val taskContainer = mockk<TaskContainer>()
|
||||
every { project.tasks } returns taskContainer
|
||||
val mockTaskProvider = mockk<TaskProvider<PrintTask>>()
|
||||
val mockPrintTask = mockk<PrintTask>(relaxed = true)
|
||||
val captureSlot = slot<Action<PrintTask>>()
|
||||
|
||||
every {
|
||||
project.tasks.register(eq("kgpVersion"), PrintTask::class.java, capture(captureSlot))
|
||||
} returns mockTaskProvider
|
||||
every { project.provider<PrintTask>(any()) } returns mockTaskProvider
|
||||
every { mockTaskProvider.configure(any()).hint(PrintTask::class) }
|
||||
|
||||
FlutterPluginUtils.addTaskForKGPVersion(project)
|
||||
captureSlot.captured.execute(mockPrintTask)
|
||||
|
||||
val mockTask = mockk<Task>()
|
||||
every { mockTask.description = any() } returns Unit
|
||||
every { mockTask.doLast(any<Action<Task>>()) } returns mockk()
|
||||
captureSlot.captured.execute(mockTask)
|
||||
verify {
|
||||
mockTask.description = "Print the current kgp version used by the project."
|
||||
mockPrintTask.description = "Print the current kgp version used by the project."
|
||||
}
|
||||
}
|
||||
|
||||
@ -1047,21 +1065,23 @@ class FlutterPluginUtilsTest {
|
||||
@Test
|
||||
fun `addTaskForPrintBuildVariants adds task for printing build variants`() {
|
||||
val project = mockk<Project>()
|
||||
every { project.extensions.getByType(AbstractAppExtension::class.java) } returns mockk()
|
||||
every { project.tasks.register(any(), any<Action<Task>>()) } returns mockk()
|
||||
val captureSlot = slot<Action<Task>>()
|
||||
val taskContainer = mockk<TaskContainer>()
|
||||
every { project.tasks } returns taskContainer
|
||||
val mockTaskProvider = mockk<TaskProvider<PrintTask>>()
|
||||
val mockPrintTask = mockk<PrintTask>(relaxed = true)
|
||||
val captureSlot = slot<Action<PrintTask>>()
|
||||
|
||||
every {
|
||||
project.tasks.register(eq("printBuildVariants"), PrintTask::class.java, capture(captureSlot))
|
||||
} returns mockTaskProvider
|
||||
every { project.provider<PrintTask>(any()) } returns mockTaskProvider
|
||||
every { mockTaskProvider.configure(any()).hint(PrintTask::class) }
|
||||
|
||||
FlutterPluginUtils.addTaskForPrintBuildVariants(project)
|
||||
|
||||
verify { project.tasks.register("printBuildVariants", capture(captureSlot)) }
|
||||
val mockTask = mockk<Task>()
|
||||
every { mockTask.description = any() } returns Unit
|
||||
every { mockTask.doLast(any<Action<Task>>()) } returns mockk()
|
||||
|
||||
captureSlot.captured.execute(mockTask)
|
||||
captureSlot.captured.execute(mockPrintTask)
|
||||
|
||||
verify {
|
||||
mockTask.description = "Prints out all build variants for this Android project"
|
||||
mockPrintTask.description = "Prints out all build variants for this Android project"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user