Browse Source

Make web.application non-experimental (#1880)

pull/1885/head v1.1.0-rc01
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
ea778fbac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      experimental/examples/falling-balls-mpp/build.gradle.kts
  2. 2
      experimental/examples/minesweeper/build.gradle.kts
  3. 11
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  4. 19
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalExtension.kt
  5. 25
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebExtension.kt
  6. 24
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureExperimental.kt
  7. 21
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/WebExtension.kt
  8. 5
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/dsl/WebApplication.kt
  9. 20
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt
  10. 4
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/AbstractUnpackSkikoWasmRuntimeTask.kt

2
experimental/examples/falling-balls-mpp/build.gradle.kts

@ -148,7 +148,7 @@ compose.desktop {
}
}
compose.experimental {
compose {
web.application {}
}

2
experimental/examples/minesweeper/build.gradle.kts

@ -149,7 +149,7 @@ compose.desktop {
}
}
compose.experimental {
compose {
web.application {}
}

11
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<Project> {
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<Project> {
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!")

19
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalExtension.kt

@ -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<ExperimentalWebExtension>) {
action.execute(web)
}
}

25
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebExtension.kt

@ -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<ExperimentalWebApplication>) {
fn.execute(application)
}
}

24
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureExperimental.kt

@ -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)
}
}
}

21
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<WebApplication>) {
fn.execute(application)
}
private var requestedTargets: Set<KotlinJsIrTarget>? = null
private var targetsToConfigure: Set<KotlinJsIrTarget>? = null

5
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebApplication.kt → 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,
) {
}

20
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/internal/configureExperimentalWebApplication.kt → 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<ExperimentalUnpackSkikoWasmRuntimeTask>(taskName) {
val unpackRuntime = project.registerTask<AbstractUnpackSkikoWasmRuntimeTask>(taskName) {
runtimeClasspath = project.configurations.getByName(mainCompilation.runtimeDependencyConfigurationName)
outputDir.set(unpackedRuntimeDir)
}

4
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/tasks/ExperimentalUnpackSkikoWasmRuntimeTask.kt → 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
Loading…
Cancel
Save