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() {
|
||||
|
||||
Reference in New Issue
Block a user