Skip to content

Commit

Permalink
[Gradle, JS] Activate legacy plugin and new plugin via gradle property
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgonmic committed Jan 20, 2020
1 parent 4e5b66a commit e0b4b61
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ abstract class KotlinBasePluginWrapper(

kotlinGradleBuildServices.detectKotlinPluginLoadedInMultipleProjects(project, kotlinPluginVersion)

defineExtension(project)

project.createKotlinExtension(projectExtensionClass).apply {
fun kotlinSourceSetContainer(factory: NamedDomainObjectFactory<KotlinSourceSet>) =
project.container(KotlinSourceSet::class.java, factory)
Expand Down Expand Up @@ -98,6 +100,9 @@ abstract class KotlinBasePluginWrapper(
project: Project,
kotlinGradleBuildServices: KotlinGradleBuildServices
): Plugin<Project>

protected open fun defineExtension(project: Project) {
}
}

open class KotlinPluginWrapper @Inject constructor(
Expand Down Expand Up @@ -147,11 +152,28 @@ open class Kotlin2JsPluginWrapper @Inject constructor(
open class KotlinJsPluginWrapper @Inject constructor(
fileResolver: FileResolver
) : KotlinBasePluginWrapper(fileResolver) {
override fun getPlugin(project: Project, kotlinGradleBuildServices: KotlinGradleBuildServices): Plugin<Project> =
KotlinJsPlugin(kotlinPluginVersion)
override fun getPlugin(project: Project, kotlinGradleBuildServices: KotlinGradleBuildServices): Plugin<Project> {
val propertiesProvider = PropertiesProvider(project)

override val projectExtensionClass: KClass<out KotlinJsProjectExtension>
get() = KotlinJsProjectExtension::class
return when (propertiesProvider.jsMode) {
JsMode.IR -> KotlinJsIrPlugin(kotlinPluginVersion)
JsMode.LEGACY -> KotlinJsPlugin(kotlinPluginVersion)
JsMode.MIXED -> KotlinJsPlugin(kotlinPluginVersion)
}
}

override lateinit var projectExtensionClass: KClass<out KotlinProjectExtension>

override fun defineExtension(project: Project) {
val propertiesProvider = PropertiesProvider(project)

when (propertiesProvider.jsMode) {
JsMode.IR -> projectExtensionClass = KotlinJsIrProjectExtension::class
JsMode.LEGACY -> projectExtensionClass = KotlinJsProjectExtension::class
JsMode.MIXED -> {
} //TODO MIXED MODE
}
}

override fun createTestRegistry(project: Project) = KotlinTestsRegistry(project, "test")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ internal class PropertiesProvider private constructor(private val project: Proje
val jsDiscoverTypes: Boolean?
get() = booleanProperty("kotlin.js.experimental.discoverTypes")

/**
* Use Kotlin/JS backend mode
*/
val jsMode: JsMode
get() = property("kotlin.js.mode")?.let { JsMode.byCompilerArgument(it) } ?: JsMode.IR

private fun propertyWithDeprecatedVariant(propName: String, deprecatedPropName: String): String? {
val deprecatedProperty = property(deprecatedPropName)
if (deprecatedProperty != null) {
Expand Down Expand Up @@ -198,3 +204,14 @@ internal class PropertiesProvider private constructor(private val project: Proje
}
}
}

internal enum class JsMode {
LEGACY,
IR,
MIXED;

companion object {
fun byCompilerArgument(argument: String): JsMode? =
JsMode.values().firstOrNull { it.name.equals(argument, ignoreCase = true) }
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
implementation-class=org.jetbrains.kotlin.gradle.plugin.KotlinJsIrPluginWrapper
implementation-class=org.jetbrains.kotlin.gradle.plugin.KotlinJsPluginWrapper

0 comments on commit e0b4b61

Please sign in to comment.