Browse Source
This is a preparation to move these tests to kotlin project. Some neccessary parts were copy-pasted from our Compose Multiplatform gradle plugin. So `id("org.jetbrains.compose")` is not used anymorepull/4426/head
Oleksandr Karpovich
10 months ago
committed by
GitHub
26 changed files with 143 additions and 53 deletions
@ -0,0 +1,70 @@
|
||||
/* |
||||
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers. |
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. |
||||
*/ |
||||
|
||||
package internal |
||||
|
||||
import internal.ComposeCompilerArtifactProvider.DefaultCompiler.pluginArtifact |
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact |
||||
|
||||
// Partially copy-pasted from https://github.com/JetBrains/compose-multiplatform/tree/master/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose |
||||
internal class ComposeCompilerArtifactProvider( |
||||
private val customPluginString: () -> String |
||||
) { |
||||
val compilerArtifact: SubpluginArtifact by lazy { |
||||
val customPlugin = customPluginString() |
||||
val customCoordinates = customPlugin.split(":") |
||||
when (customCoordinates.size) { |
||||
1 -> { |
||||
val customVersion = customCoordinates[0] |
||||
check(customVersion.isNotBlank()) { "'compose.kotlinCompilerPlugin' cannot be blank!" } |
||||
pluginArtifact(version = customVersion) |
||||
} |
||||
3 -> pluginArtifact( |
||||
version = customCoordinates[2], |
||||
groupId = customCoordinates[0], |
||||
artifactId = customCoordinates[1], |
||||
) |
||||
else -> error(""" |
||||
Illegal format of 'compose.kotlinCompilerPlugin' property. |
||||
Expected format: either '<VERSION>' or '<GROUP_ID>:<ARTIFACT_ID>:<VERSION>' |
||||
Actual value: '$customPlugin' |
||||
""".trimIndent()) |
||||
} |
||||
} |
||||
|
||||
val compilerHostedArtifact: SubpluginArtifact |
||||
get() = compilerArtifact.run { |
||||
val newArtifactId = |
||||
if (groupId == DefaultCompiler.GROUP_ID && artifactId == DefaultCompiler.ARTIFACT_ID) { |
||||
DefaultCompiler.HOSTED_ARTIFACT_ID |
||||
} else artifactId |
||||
|
||||
copy(artifactId = newArtifactId) |
||||
} |
||||
|
||||
internal object DefaultCompiler { |
||||
const val GROUP_ID = "org.jetbrains.compose.compiler" |
||||
const val ARTIFACT_ID = "compiler" |
||||
const val HOSTED_ARTIFACT_ID = "compiler-hosted" |
||||
|
||||
fun pluginArtifact( |
||||
version: String, |
||||
groupId: String = GROUP_ID, |
||||
artifactId: String = ARTIFACT_ID, |
||||
): SubpluginArtifact = |
||||
SubpluginArtifact(groupId = groupId, artifactId = artifactId, version = version) |
||||
} |
||||
} |
||||
|
||||
internal fun SubpluginArtifact.copy( |
||||
groupId: String? = null, |
||||
artifactId: String? = null, |
||||
version: String? = null |
||||
): SubpluginArtifact = |
||||
SubpluginArtifact( |
||||
groupId = groupId ?: this.groupId, |
||||
artifactId = artifactId ?: this.artifactId, |
||||
version = version ?: this.version |
||||
) |
@ -0,0 +1,50 @@
|
||||
/* |
||||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers. |
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. |
||||
*/ |
||||
|
||||
package internal |
||||
|
||||
import org.gradle.api.Project |
||||
import org.gradle.api.provider.Provider |
||||
import org.jetbrains.kotlin.gradle.plugin.* |
||||
|
||||
// Partially copy-pasted from https://github.com/JetBrains/compose-multiplatform/tree/master/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose |
||||
class InternalComposeSupportPlugin : KotlinCompilerPluginSupportPlugin { |
||||
private lateinit var composeCompilerArtifactProvider: ComposeCompilerArtifactProvider |
||||
|
||||
override fun apply(target: Project) { |
||||
super.apply(target) |
||||
|
||||
val composeCompilerVersion = target.properties["compose.kotlinCompilerPluginVersion"] as? String |
||||
?: error("'compose.kotlinCompilerPluginVersion' is not defined") |
||||
composeCompilerArtifactProvider = ComposeCompilerArtifactProvider { composeCompilerVersion } |
||||
} |
||||
|
||||
override fun getCompilerPluginId(): String = "androidx.compose.compiler.plugins.kotlin" |
||||
|
||||
override fun getPluginArtifact(): SubpluginArtifact = |
||||
composeCompilerArtifactProvider.compilerArtifact |
||||
|
||||
override fun getPluginArtifactForNative(): SubpluginArtifact = |
||||
composeCompilerArtifactProvider.compilerHostedArtifact |
||||
|
||||
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true |
||||
|
||||
override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> { |
||||
val target = kotlinCompilation.target |
||||
return target.project.provider { emptyList() } |
||||
} |
||||
|
||||
private fun options(vararg options: Pair<String, String>): List<SubpluginOption> = |
||||
options.map { SubpluginOption(it.first, it.second) } |
||||
} |
||||
|
||||
val Project.composeVersion: String |
||||
get() = properties["compose.version"] as? String |
||||
?: error("'compose.version' is not defined") |
||||
|
||||
val Project.composeRuntimeDependency: String |
||||
get() = properties["compose.runtime.artifactId"] as? String |
||||
?: properties["compose.runtime.groupId"]?.let { it.toString() + ":runtime:$composeVersion" } |
||||
?: "org.jetbrains.compose.runtime:runtime:${composeVersion}" |
Loading…
Reference in new issue