diff --git a/experimental/examples/falling-balls-mpp/build.gradle.kts b/experimental/examples/falling-balls-mpp/build.gradle.kts index a97803d06c..f9f9d24cfe 100644 --- a/experimental/examples/falling-balls-mpp/build.gradle.kts +++ b/experimental/examples/falling-balls-mpp/build.gradle.kts @@ -148,7 +148,7 @@ compose.desktop { } } -compose.experimental { +compose { web.application {} } diff --git a/experimental/examples/minesweeper/build.gradle.kts b/experimental/examples/minesweeper/build.gradle.kts index ef2a77b7fa..5228b5f114 100644 --- a/experimental/examples/minesweeper/build.gradle.kts +++ b/experimental/examples/minesweeper/build.gradle.kts @@ -149,7 +149,7 @@ compose.desktop { } } -compose.experimental { +compose { web.application {} } diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt index 0cf035b8ab..c3f785cb76 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt @@ -23,12 +23,8 @@ import org.jetbrains.compose.desktop.application.internal.ComposeProperties import org.jetbrains.compose.desktop.application.internal.configureApplicationImpl import org.jetbrains.compose.desktop.application.internal.currentTarget import org.jetbrains.compose.desktop.preview.internal.initializePreview -import org.jetbrains.compose.experimental.dsl.ExperimentalExtension -import org.jetbrains.compose.experimental.internal.configureExperimental -import org.jetbrains.compose.internal.COMPOSE_PLUGIN_ID -import org.jetbrains.compose.internal.KOTLIN_JS_PLUGIN_ID -import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID import org.jetbrains.compose.web.WebExtension +import org.jetbrains.compose.web.internal.configureWebApplication import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -39,14 +35,13 @@ class ComposePlugin : Plugin { val composeExtension = project.extensions.create("compose", ComposeExtension::class.java) val desktopExtension = composeExtension.extensions.create("desktop", DesktopExtension::class.java) val androidExtension = composeExtension.extensions.create("android", AndroidExtension::class.java) - val experimentalExtension = composeExtension.extensions.create("experimental", ExperimentalExtension::class.java) + val webExtension = composeExtension.extensions.create("web", WebExtension::class.java) if (!project.buildFile.endsWith(".gradle.kts")) { setUpGroovyDslExtensions(project) } project.initializePreview() - composeExtension.extensions.create("web", WebExtension::class.java) project.plugins.apply(ComposeCompilerKotlinSupportPlugin::class.java) @@ -57,7 +52,7 @@ class ComposePlugin : Plugin { configureApplicationImpl(project, desktopExtension.application) } - project.configureExperimental(composeExtension, experimentalExtension) + configureWebApplication(project, webExtension) if (androidExtension.useAndroidX) { project.logger.warn("useAndroidX is an experimental feature at the moment!") diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalExtension.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalExtension.kt deleted file mode 100644 index 8c4a809c3e..0000000000 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalExtension.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 org.jetbrains.compose.experimental.dsl - -import org.gradle.api.Action -import org.gradle.api.model.ObjectFactory -import javax.inject.Inject - -abstract class ExperimentalExtension @Inject constructor( - objects: ObjectFactory -) { - val web: ExperimentalWebExtension = objects.newInstance(ExperimentalWebExtension::class.java) - fun web(action: Action) { - action.execute(web) - } -} \ No newline at end of file diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebExtension.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebExtension.kt deleted file mode 100644 index 04425696b8..0000000000 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebExtension.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 org.jetbrains.compose.experimental.dsl - -import org.gradle.api.Action -import org.gradle.api.model.ObjectFactory -import org.gradle.api.plugins.ExtensionAware -import javax.inject.Inject - -abstract class ExperimentalWebExtension @Inject constructor(private val objectFactory: ObjectFactory) : ExtensionAware { - internal var _isApplicationInitialized = false - private set - - val application: ExperimentalWebApplication by lazy { - _isApplicationInitialized = true - objectFactory.newInstance(ExperimentalWebApplication::class.java, "main") - } - - fun application(fn: Action) { - fn.execute(application) - } -} diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureExperimental.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureExperimental.kt deleted file mode 100644 index eda6d845a7..0000000000 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureExperimental.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 org.jetbrains.compose.experimental.internal - -import org.gradle.api.Project -import org.jetbrains.compose.ComposeExtension -import org.jetbrains.compose.experimental.dsl.ExperimentalExtension -import org.jetbrains.compose.experimental.web.internal.configureExperimentalWebApplication -import org.jetbrains.compose.web.WebExtension - -internal fun Project.configureExperimental( - composeExt: ComposeExtension, - experimentalExt: ExperimentalExtension -) { - if (experimentalExt.web._isApplicationInitialized) { - val webExt = composeExt.extensions.getByType(WebExtension::class.java) - for (target in webExt.targetsToConfigure(project)) { - target.configureExperimentalWebApplication(experimentalExt.web.application) - } - } -} diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/WebExtension.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/WebExtension.kt index 571a2792ce..d926909a89 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/WebExtension.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/WebExtension.kt @@ -5,16 +5,33 @@ package org.jetbrains.compose.web +import org.gradle.api.Action import org.gradle.api.Project +import org.gradle.api.model.ObjectFactory import org.gradle.api.plugins.ExtensionAware import org.jetbrains.compose.internal.kotlinJsExtOrNull -import org.jetbrains.compose.internal.mppExt import org.jetbrains.compose.internal.mppExtOrNull -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.compose.web.dsl.WebApplication import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget +import javax.inject.Inject abstract class WebExtension : ExtensionAware { + @get:Inject + internal abstract val objects: ObjectFactory + + internal var _isApplicationInitialized = false + private set + + val application: WebApplication by lazy { + _isApplicationInitialized = true + objects.newInstance(WebApplication::class.java, "main") + } + + fun application(fn: Action) { + fn.execute(application) + } + private var requestedTargets: Set? = null private var targetsToConfigure: Set? = null diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebApplication.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/dsl/WebApplication.kt similarity index 70% rename from gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebApplication.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/dsl/WebApplication.kt index 42b78fb40f..e11e410f07 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebApplication.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/dsl/WebApplication.kt @@ -3,13 +3,12 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. */ -package org.jetbrains.compose.experimental.dsl +package org.jetbrains.compose.web.dsl import javax.inject.Inject -abstract class ExperimentalWebApplication @Inject constructor( +abstract class WebApplication @Inject constructor( @Suppress("unused") val name: String, ) { - } \ No newline at end of file diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/internal/configureExperimentalWebApplication.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt similarity index 55% rename from gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/internal/configureExperimentalWebApplication.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt index 7c23d16fe4..59252a449b 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/internal/configureExperimentalWebApplication.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt @@ -3,19 +3,29 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. */ -package org.jetbrains.compose.experimental.web.internal +package org.jetbrains.compose.web.internal -import org.jetbrains.compose.experimental.dsl.ExperimentalWebApplication +import org.gradle.api.Project import org.jetbrains.compose.internal.registerTask -import org.jetbrains.compose.experimental.web.tasks.ExperimentalUnpackSkikoWasmRuntimeTask +import org.jetbrains.compose.web.WebExtension +import org.jetbrains.compose.web.dsl.WebApplication +import org.jetbrains.compose.web.tasks.AbstractUnpackSkikoWasmRuntimeTask import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget -internal fun KotlinJsIrTarget.configureExperimentalWebApplication(app: ExperimentalWebApplication) { +internal fun configureWebApplication(project: Project, webExtension: WebExtension) { + if (webExtension._isApplicationInitialized) { + for (jsTarget in webExtension.targetsToConfigure(project)) { + jsTarget.configureWebApplication(webExtension.application) + } + } +} + +private fun KotlinJsIrTarget.configureWebApplication(app: WebApplication) { val mainCompilation = compilations.getByName("main") val unpackedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-wasm/$targetName") val taskName = "unpackSkikoWasmRuntime${targetName.capitalize()}" mainCompilation.defaultSourceSet.resources.srcDir(unpackedRuntimeDir) - val unpackRuntime = project.registerTask(taskName) { + val unpackRuntime = project.registerTask(taskName) { runtimeClasspath = project.configurations.getByName(mainCompilation.runtimeDependencyConfigurationName) outputDir.set(unpackedRuntimeDir) } diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/tasks/ExperimentalUnpackSkikoWasmRuntimeTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/AbstractUnpackSkikoWasmRuntimeTask.kt similarity index 93% rename from gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/tasks/ExperimentalUnpackSkikoWasmRuntimeTask.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/AbstractUnpackSkikoWasmRuntimeTask.kt index e467af05e5..bb49624212 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/tasks/ExperimentalUnpackSkikoWasmRuntimeTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/AbstractUnpackSkikoWasmRuntimeTask.kt @@ -3,7 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. */ -package org.jetbrains.compose.experimental.web.tasks +package org.jetbrains.compose.web.tasks import org.gradle.api.DefaultTask import org.gradle.api.artifacts.Configuration @@ -14,7 +14,7 @@ import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import org.jetbrains.compose.internal.debug -abstract class ExperimentalUnpackSkikoWasmRuntimeTask : DefaultTask() { +abstract class AbstractUnpackSkikoWasmRuntimeTask : DefaultTask() { @get:InputFiles lateinit var runtimeClasspath: Configuration