Introduce MPP wizard for web (JVM / JS) applications
This implements first part of KT-25952
This commit is contained in:
+18
@@ -198,6 +198,24 @@ open class GradleKotlinMPPCommonFrameworkSupportProvider :
|
||||
override fun getDescription() = "Shared code for a Kotlin multiplatform project (targeting JVM and JS)"
|
||||
}
|
||||
|
||||
class GradleKotlinMPPFrameworkSupportProvider : GradleKotlinFrameworkSupportProvider(
|
||||
"KOTLIN_MPP", "Kotlin (Multiplatform - Experimental)", KotlinIcons.MPP
|
||||
) {
|
||||
override fun getPluginId() = "kotlin-multiplatform"
|
||||
override fun getPluginExpression() = "id 'kotlin-multiplatform'"
|
||||
|
||||
override fun getDependencies(sdk: Sdk?): List<String> = listOf()
|
||||
override fun getTestDependencies(): List<String> = listOf()
|
||||
|
||||
override fun updateSettingsScript(settingsBuilder: SettingsScriptBuilder, specifyPluginVersionIfNeeded: Boolean) {
|
||||
if (specifyPluginVersionIfNeeded) {
|
||||
settingsBuilder.addResolutionStrategy("kotlin-multiplatform")
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDescription() = "Kotlin multiplatform code"
|
||||
}
|
||||
|
||||
class GradleKotlinMPPJavaFrameworkSupportProvider
|
||||
: GradleKotlinJavaFrameworkSupportProvider("KOTLIN_MPP_JVM", "Kotlin (Multiplatform JVM - Experimental)") {
|
||||
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep
|
||||
import com.intellij.ide.util.projectWizard.WizardContext
|
||||
import com.intellij.openapi.externalSystem.service.project.wizard.ExternalModuleSettingsStep
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||
import org.jetbrains.kotlin.idea.util.rootManager
|
||||
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder
|
||||
import org.jetbrains.plugins.gradle.service.project.wizard.GradleModuleBuilder
|
||||
import org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl
|
||||
import javax.swing.Icon
|
||||
|
||||
abstract class KotlinGradleAbstractMultiplatformModuleBuilder : GradleModuleBuilder() {
|
||||
override fun getNodeIcon(): Icon = KotlinIcons.MPP
|
||||
|
||||
override fun createWizardSteps(wizardContext: WizardContext, modulesProvider: ModulesProvider): Array<ModuleWizardStep> {
|
||||
super.createWizardSteps(wizardContext, modulesProvider) // initializes GradleModuleBuilder.myWizardContext
|
||||
return arrayOf(
|
||||
// Let us have to edit project name only
|
||||
ExternalModuleSettingsStep(wizardContext, this, GradleProjectSettingsControl(externalProjectSettings))
|
||||
)
|
||||
}
|
||||
|
||||
override fun setupModule(module: Module) {
|
||||
try {
|
||||
module.gradleModuleBuilder = this
|
||||
super.setupModule(module)
|
||||
|
||||
val rootDir = module.rootManager.contentRoots.firstOrNull() ?: return
|
||||
val buildGradle = rootDir.findOrCreateChildData(null, "build.gradle")
|
||||
val builder = BuildScriptDataBuilder(buildGradle)
|
||||
GradleKotlinMPPFrameworkSupportProvider().addSupport(builder, module, sdk = null, specifyPluginVersionIfNeeded = true)
|
||||
VfsUtil.saveText(buildGradle, builder.buildConfigurationPart() + builder.buildMainPart() + buildMultiPlatformPart())
|
||||
} finally {
|
||||
flushSettingsGradleCopy(module)
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun buildMultiPlatformPart(): String
|
||||
|
||||
companion object {
|
||||
const val productionSuffix = "Main"
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
class KotlinGradleWebMultiplatformModuleBuilder : KotlinGradleAbstractMultiplatformModuleBuilder() {
|
||||
|
||||
private val commonName: String = "common"
|
||||
private var jvmTargetName: String = "jvm"
|
||||
private var jsTargetName: String = "js"
|
||||
|
||||
private val commonSourceName get() = "$commonName$productionSuffix"
|
||||
private val jvmSourceName get() = "$jvmTargetName$productionSuffix"
|
||||
private val jsSourceName get() = "$jsTargetName$productionSuffix"
|
||||
|
||||
override fun getBuilderId() = "kotlin.gradle.multiplatform.web"
|
||||
|
||||
override fun getPresentableName() = "Kotlin (Multiplatform - Web)"
|
||||
|
||||
override fun getDescription() =
|
||||
"Multiplatform web projects allow reusing the same code between JVM & JS platforms supported by Kotlin. Such projects are built with Gradle."
|
||||
|
||||
override fun buildMultiPlatformPart(): String {
|
||||
return """
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvmWithJava, '$jvmTargetName')
|
||||
fromPreset(presets.js, '$jsTargetName')
|
||||
}
|
||||
sourceSets {
|
||||
$commonSourceName {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
}
|
||||
}
|
||||
$jvmSourceName {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||
}
|
||||
}
|
||||
$jsSourceName {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
@@ -80,5 +80,6 @@
|
||||
<scriptDefinitionContributor implementation="org.jetbrains.kotlin.idea.core.script.GradleScriptDefinitionsContributor" order="first"/>
|
||||
|
||||
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleMultiplatformModuleBuilder"/>
|
||||
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleWebMultiplatformModuleBuilder"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
<scriptDefinitionContributor implementation="org.jetbrains.kotlin.idea.core.script.GradleScriptDefinitionsContributor" order="first"/>
|
||||
|
||||
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleMultiplatformModuleBuilder"/>
|
||||
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleWebMultiplatformModuleBuilder"/>
|
||||
|
||||
<buildSystemTypeDetector implementation="org.jetbrains.kotlin.idea.configuration.GradleDetector"/>
|
||||
</extensions>
|
||||
|
||||
Reference in New Issue
Block a user