BuildScriptManipulator: implement new syntax for enable experimental features in MPP
#KT-28295 Fixed
This commit is contained in:
+12
-14
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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
|
||||
@@ -25,6 +14,7 @@ import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CliArgumentStringBuilder.buildArgumentString
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CliArgumentStringBuilder.replaceLanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.idea.configuration.GroovyBuildScriptManipulator.Companion.getBlockOrCreate
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator.Companion.getBuildScriptSettingsPsiFile
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.module
|
||||
@@ -165,6 +155,14 @@ class GroovyBuildScriptManipulator(
|
||||
state: LanguageFeature.State,
|
||||
forTests: Boolean
|
||||
): PsiElement? {
|
||||
if (usesNewMultiplatform()) {
|
||||
val kotlinBlock = scriptFile.getBlockOrCreate("kotlin")
|
||||
val sourceSetsBlock = kotlinBlock.getBlockOrCreate("sourceSets")
|
||||
val allBlock = sourceSetsBlock.getBlockOrCreate("all")
|
||||
allBlock.addLastExpressionInBlockIfNeeded("languageSettings.enableLanguageFeature(\"${feature.name}\")")
|
||||
return allBlock.statements.lastOrNull()
|
||||
}
|
||||
|
||||
val featureArgumentString = feature.buildArgumentString(state)
|
||||
val parameterName = "freeCompilerArgs"
|
||||
return addOrReplaceKotlinTaskParameter(
|
||||
@@ -255,7 +253,7 @@ class GroovyBuildScriptManipulator(
|
||||
|
||||
private fun usesNewMultiplatform(): Boolean {
|
||||
val fileText = runReadAction { scriptFile.text }
|
||||
return fileText.contains("kotlin-multiplatform")
|
||||
return fileText.contains("multiplatform")
|
||||
}
|
||||
|
||||
private fun GrClosableBlock.addParameterAssignment(
|
||||
|
||||
+14
-13
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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
|
||||
@@ -310,11 +299,23 @@ class KotlinBuildScriptManipulator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun usesNewMultiplatform(): Boolean {
|
||||
val fileText = runReadAction { scriptFile.text }
|
||||
return fileText.contains("multiplatform")
|
||||
}
|
||||
|
||||
private fun KtFile.changeLanguageFeatureConfiguration(
|
||||
feature: LanguageFeature,
|
||||
state: LanguageFeature.State,
|
||||
forTests: Boolean
|
||||
): PsiElement? {
|
||||
if (usesNewMultiplatform()) {
|
||||
return findOrCreateScriptInitializer("kotlin")
|
||||
?.findOrCreateBlock("sourceSets")
|
||||
?.findOrCreateBlock("all")
|
||||
?.addExpressionIfMissing("languageSettings.enableLanguageFeature(\"${feature.name}\")")
|
||||
}
|
||||
|
||||
val featureArgumentString = feature.buildArgumentString(state)
|
||||
val parameterName = "freeCompilerArgs"
|
||||
return addOrReplaceKotlinTaskParameter(
|
||||
|
||||
+34
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,22 @@ import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions
|
||||
import org.junit.Test
|
||||
|
||||
class GradleConfiguratorPlatformSpecificTest : GradleImportingTestCase() {
|
||||
@TargetVersions("4.7+")
|
||||
@Test
|
||||
fun testDisableFeatureSupportMultiplatform() {
|
||||
val files = importProjectFromTestData()
|
||||
// now it's impossible to disable feature in multiplatform
|
||||
runInEdtAndWait {
|
||||
myTestFixture.project.executeWriteCommand("") {
|
||||
KotlinWithGradleConfigurator.changeFeatureConfiguration(
|
||||
myTestFixture.module, LanguageFeature.InlineClasses, LanguageFeature.State.DISABLED, false
|
||||
)
|
||||
}
|
||||
|
||||
checkFiles(files)
|
||||
}
|
||||
}
|
||||
|
||||
@TargetVersions("4.7+")
|
||||
@Test
|
||||
fun testEnableFeatureSupportMultiplatform() {
|
||||
@@ -31,7 +47,7 @@ class GradleConfiguratorPlatformSpecificTest : GradleImportingTestCase() {
|
||||
|
||||
@TargetVersions("4.7+")
|
||||
@Test
|
||||
fun testEnableFeatureSupportMultiplatformWithDots() {
|
||||
fun testEnableFeatureSupportMultiplatform2() {
|
||||
val files = importProjectFromTestData()
|
||||
|
||||
runInEdtAndWait {
|
||||
@@ -61,6 +77,22 @@ class GradleConfiguratorPlatformSpecificTest : GradleImportingTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@TargetVersions("4.7+")
|
||||
@Test
|
||||
fun testEnableFeatureSupportMultiplatformKts() {
|
||||
val files = importProjectFromTestData()
|
||||
|
||||
runInEdtAndWait {
|
||||
myTestFixture.project.executeWriteCommand("") {
|
||||
KotlinWithGradleConfigurator.changeFeatureConfiguration(
|
||||
myTestFixture.module, LanguageFeature.InlineClasses, LanguageFeature.State.ENABLED, false
|
||||
)
|
||||
}
|
||||
|
||||
checkFiles(files)
|
||||
}
|
||||
}
|
||||
|
||||
override fun testDataDirName(): String {
|
||||
return "configurator"
|
||||
}
|
||||
|
||||
+1
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2000-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -584,22 +584,6 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@TargetVersions("4.7+")
|
||||
@Test
|
||||
fun testDisableFeatureSupportMultiplatform() {
|
||||
val files = importProjectFromTestData()
|
||||
|
||||
runInEdtAndWait {
|
||||
myTestFixture.project.executeWriteCommand("") {
|
||||
KotlinWithGradleConfigurator.changeFeatureConfiguration(
|
||||
myTestFixture.module, LanguageFeature.InlineClasses, LanguageFeature.State.DISABLED, false
|
||||
)
|
||||
}
|
||||
|
||||
checkFiles(files)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEnableFeatureSupport() {
|
||||
val files = importProjectFromTestData()
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
|
||||
+3
-5
@@ -15,11 +15,6 @@ repositories {
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
configure([jvm]) {
|
||||
tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
|
||||
freeCompilerArgs = ["-XXLanguage:-InlineClasses"]
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
@@ -32,5 +27,8 @@ kotlin {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
}
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -15,11 +15,6 @@ repositories {
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
configure([jvm]) {
|
||||
tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
|
||||
freeCompilerArgs = ["-XXLanguage:+InlineClasses"]
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
@@ -32,5 +27,8 @@ kotlin {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
}
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -7,13 +7,15 @@ buildscript {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0-rc-190"
|
||||
}
|
||||
}
|
||||
apply plugin: "kotlin-multiplatform"
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.3.41'
|
||||
}
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets.fromPreset(presets.jvm, 'jvm')
|
||||
jvm()
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
+6
-8
@@ -7,13 +7,15 @@ buildscript {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0-rc-190"
|
||||
}
|
||||
}
|
||||
apply plugin: "kotlin-multiplatform"
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.3.41'
|
||||
}
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets.fromPreset(presets.jvm, 'jvm')
|
||||
jvm()
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
@@ -25,12 +27,8 @@ kotlin {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
}
|
||||
}
|
||||
targets {
|
||||
configure([jvm]) {
|
||||
tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
|
||||
freeCompilerArgs = ["-XXLanguage:+InlineClasses"]
|
||||
}
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.3.41"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
group = "com.example"
|
||||
version = "0.0.1"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
val commonMain by getting
|
||||
}
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.3.41"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
group = "com.example"
|
||||
version = "0.0.1"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
val commonMain by getting
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+3
-8
@@ -13,14 +13,6 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
configure([jvm]) {
|
||||
tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
|
||||
freeCompilerArgs = ["-XXLanguage:+SamConversionForKotlinFunctions"]
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
@@ -32,5 +24,8 @@ kotlin {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
}
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("SamConversionForKotlinFunctions")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -13,14 +13,6 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
configure([jvm]) {
|
||||
tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
|
||||
freeCompilerArgs = ["-XXLanguage:+SamConversionForKotlinFunctions", "-XXLanguage:+InlineClasses"]
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
@@ -32,5 +24,9 @@ kotlin {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
}
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("SamConversionForKotlinFunctions")
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user