GradleBuildScript: throw exception when trying to change level of language features to disable in multiplatform & fix tests
This commit is contained in:
+10
@@ -92,6 +92,16 @@ fun GradleBuildScriptManipulator<*>.useNewSyntax(kotlinPluginName: String, gradl
|
||||
return !hasOldApply
|
||||
}
|
||||
|
||||
fun GradleBuildScriptManipulator<*>.usesNewMultiplatform(): Boolean {
|
||||
val fileText = runReadAction { scriptFile.text }
|
||||
return fileText.contains("multiplatform")
|
||||
}
|
||||
|
||||
fun LanguageFeature.State.assertApplicableInMultiplatform() {
|
||||
if (this == LanguageFeature.State.ENABLED_WITH_ERROR || this == LanguageFeature.State.DISABLED)
|
||||
throw UnsupportedOperationException("Disabling the language feature is unsupported for multiplatform")
|
||||
}
|
||||
|
||||
private val MIN_GRADLE_VERSION_FOR_API_AND_IMPLEMENTATION = GradleVersion.version("3.4")
|
||||
|
||||
fun GradleVersion.scope(directive: String): String {
|
||||
|
||||
+1
-6
@@ -14,7 +14,6 @@ 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
|
||||
@@ -156,6 +155,7 @@ class GroovyBuildScriptManipulator(
|
||||
forTests: Boolean
|
||||
): PsiElement? {
|
||||
if (usesNewMultiplatform()) {
|
||||
state.assertApplicableInMultiplatform()
|
||||
val kotlinBlock = scriptFile.getBlockOrCreate("kotlin")
|
||||
val sourceSetsBlock = kotlinBlock.getBlockOrCreate("sourceSets")
|
||||
val allBlock = sourceSetsBlock.getBlockOrCreate("all")
|
||||
@@ -251,11 +251,6 @@ class GroovyBuildScriptManipulator(
|
||||
)
|
||||
}
|
||||
|
||||
private fun usesNewMultiplatform(): Boolean {
|
||||
val fileText = runReadAction { scriptFile.text }
|
||||
return fileText.contains("multiplatform")
|
||||
}
|
||||
|
||||
private fun GrClosableBlock.addParameterAssignment(
|
||||
parameterName: String,
|
||||
defaultValue: String,
|
||||
|
||||
+1
-5
@@ -299,17 +299,13 @@ 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()) {
|
||||
state.assertApplicableInMultiplatform()
|
||||
return findOrCreateScriptInitializer("kotlin")
|
||||
?.findOrCreateBlock("sourceSets")
|
||||
?.findOrCreateBlock("all")
|
||||
|
||||
-16
@@ -13,22 +13,6 @@ 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
@@ -1,31 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0-rc-190"
|
||||
}
|
||||
}
|
||||
apply plugin: "kotlin-multiplatform"
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0-rc-190"
|
||||
}
|
||||
}
|
||||
apply plugin: "kotlin-multiplatform"
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
}
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.JarFileSystem
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.testFramework.exceptionCases.AbstractExceptionCase
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments.Companion.DEFAULT
|
||||
import org.jetbrains.kotlin.config.CompilerSettings.Companion.DEFAULT_ADDITIONAL_ARGUMENTS
|
||||
@@ -45,13 +44,7 @@ class UpdateConfigurationQuickFixTest : LightPlatformCodeInsightFixtureTestCase(
|
||||
myFixture.configureByText("foo.kt", "inline class My(val n: Int)")
|
||||
|
||||
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, inlineClassesSupport)
|
||||
assertException(object : AbstractExceptionCase<AssertionError>() {
|
||||
override fun getExpectedExceptionClass(): Class<AssertionError> = AssertionError::class.java
|
||||
|
||||
override fun tryClosure() {
|
||||
myFixture.findSingleIntention("Disable inline classes support in the project")
|
||||
}
|
||||
})
|
||||
assertTrue(myFixture.availableIntentions.none { it.text == "Disable inline classes support in the project" })
|
||||
}
|
||||
|
||||
fun testEnableInlineClasses() {
|
||||
|
||||
+1
-8
@@ -14,7 +14,6 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.JarFileSystem
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.testFramework.exceptionCases.AbstractExceptionCase
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments.Companion.DEFAULT
|
||||
import org.jetbrains.kotlin.config.CompilerSettings.Companion.DEFAULT_ADDITIONAL_ARGUMENTS
|
||||
@@ -42,13 +41,7 @@ class UpdateConfigurationQuickFixTest : LightPlatformCodeInsightFixtureTestCase(
|
||||
myFixture.configureByText("foo.kt", "inline class My(val n: Int)")
|
||||
|
||||
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, inlineClassesSupport)
|
||||
assertException(object : AbstractExceptionCase<AssertionError>() {
|
||||
override fun getExpectedExceptionClass(): Class<AssertionError> = AssertionError::class.java
|
||||
|
||||
override fun tryClosure() {
|
||||
myFixture.findSingleIntention("Disable inline classes support in the project")
|
||||
}
|
||||
})
|
||||
assertTrue(myFixture.availableIntentions.none { it.text == "Disable inline classes support in the project" })
|
||||
}
|
||||
|
||||
fun testEnableInlineClasses() {
|
||||
|
||||
Reference in New Issue
Block a user