mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] KTIJ-28619, IDEA-338444 setUpWithKotlinPlugin should take place in the base class
SystemPropertyBasedPluginModeProvider is a marker interface to use plugin mode based on the K2 system property GitOrigin-RevId: 13c68457c2187d4f082b3cc5fb8934e0a4c1e1ca
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0773eee148
commit
32d85f7dd1
-2
@@ -1,6 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:JvmName("SystemPropertyUtils")
|
||||
|
||||
package org.jetbrains.kotlin.idea.base.plugin
|
||||
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
+16
-3
@@ -1,6 +1,9 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.test
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.util.ThrowableRunnable
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider
|
||||
import org.jetbrains.kotlin.idea.base.plugin.useK2Plugin
|
||||
@@ -9,9 +12,13 @@ import org.junit.Assert
|
||||
interface ExpectedPluginModeProvider {
|
||||
|
||||
val pluginMode: KotlinPluginMode
|
||||
|
||||
// not a property for compatibility reasons
|
||||
fun getTestRootDisposable(): Disposable
|
||||
}
|
||||
|
||||
fun ExpectedPluginModeProvider.assertKotlinPluginMode() {
|
||||
// do not expose
|
||||
private fun ExpectedPluginModeProvider.assertKotlinPluginMode() {
|
||||
val expectedPluginMode = pluginMode
|
||||
val actualPluginMode = KotlinPluginModeProvider.currentPluginMode
|
||||
|
||||
@@ -26,8 +33,14 @@ fun ExpectedPluginModeProvider.assertKotlinPluginMode() {
|
||||
* Executes a [setUp] function after enabling the K1 or K2 Kotlin plugin in system properties.
|
||||
* The correct Kotlin plugin should be set up after [setUp] finishes.
|
||||
*/
|
||||
fun ExpectedPluginModeProvider.setUpWithKotlinPlugin(setUp: () -> Unit) {
|
||||
fun ExpectedPluginModeProvider.setUpWithKotlinPlugin(setUp: ThrowableRunnable<*>) {
|
||||
val oldUseK2Plugin = useK2Plugin
|
||||
useK2Plugin = pluginMode == KotlinPluginMode.K2
|
||||
setUp()
|
||||
Disposer.register(getTestRootDisposable()) {
|
||||
useK2Plugin = oldUseK2Plugin
|
||||
}
|
||||
|
||||
setUp.run()
|
||||
|
||||
assertKotlinPluginMode()
|
||||
}
|
||||
|
||||
+2
-3
@@ -7,7 +7,7 @@ import com.intellij.testFramework.common.runAll
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.codeInsight.gradle.AbstractGradleBuildFileHighlightingTest
|
||||
import org.jetbrains.kotlin.idea.test.ExpectedPluginModeProvider
|
||||
import org.jetbrains.kotlin.idea.test.assertKotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
|
||||
|
||||
|
||||
private const val SCRIPTING_ENABLED_FLAG = "kotlin.k2.scripting.enabled"
|
||||
@@ -25,8 +25,7 @@ abstract class AbstractK2GradleBuildFileHighlightingTest : AbstractGradleBuildFi
|
||||
|
||||
Registry.get(SCRIPTING_ENABLED_FLAG).setValue(true)
|
||||
|
||||
super.setUp()
|
||||
assertKotlinPluginMode()
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
|
||||
+3
-18
@@ -8,7 +8,6 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import com.intellij.testFramework.VfsTestUtil
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
|
||||
import com.intellij.util.ThrowableRunnable
|
||||
import org.jetbrains.kotlin.gradle.multiplatformTests.testFeatures.*
|
||||
import org.jetbrains.kotlin.gradle.multiplatformTests.testFeatures.checkers.*
|
||||
import org.jetbrains.kotlin.gradle.multiplatformTests.testFeatures.checkers.contentRoots.ContentRootsChecker
|
||||
@@ -22,7 +21,6 @@ import org.jetbrains.kotlin.gradle.multiplatformTests.testFeatures.checkers.runC
|
||||
import org.jetbrains.kotlin.gradle.multiplatformTests.testFeatures.checkers.workspace.GeneralWorkspaceChecks
|
||||
import org.jetbrains.kotlin.gradle.multiplatformTests.testFeatures.checkers.workspace.WorkspaceChecksDsl
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.base.plugin.useK2Plugin
|
||||
import org.jetbrains.kotlin.idea.base.test.AndroidStudioTestUtils
|
||||
import org.jetbrains.kotlin.idea.codeInsight.gradle.KotlinGradleImportingTestCase
|
||||
import org.jetbrains.kotlin.idea.codeInsight.gradle.PluginTargetVersionsRule
|
||||
@@ -130,10 +128,6 @@ abstract class AbstractKotlinMppGradleImportingTest : GradleImportingTestCase(),
|
||||
// Temporary hack allowing to reuse new test runner in selected smoke tests for runs on linux-hosts
|
||||
open val allowOnNonMac: Boolean = false
|
||||
|
||||
// Captures the state of the 'idea.kotlin.plugin.use.k2' system property before the test.
|
||||
// Used for restoring the property's value after the test.
|
||||
private var beforeSetupK2PluginProperty: Boolean? = null
|
||||
|
||||
override val pluginMode: KotlinPluginMode
|
||||
get() = KotlinPluginMode.K1
|
||||
|
||||
@@ -205,8 +199,6 @@ abstract class AbstractKotlinMppGradleImportingTest : GradleImportingTestCase(),
|
||||
assumeTrue("Test is ignored because it requires Mac-host", HostManager.hostIsMac)
|
||||
}
|
||||
|
||||
// It is important to set up property before plugin loading as the property affects plugin.xml parsing
|
||||
beforeSetupK2PluginProperty = useK2Plugin
|
||||
setUpWithKotlinPlugin {
|
||||
// Hack: usually this is set-up by JUnit's Parametrized magic, but
|
||||
// our tests source versions from `kotlinTestPropertiesService`, not from
|
||||
@@ -224,13 +216,6 @@ abstract class AbstractKotlinMppGradleImportingTest : GradleImportingTestCase(),
|
||||
"-XX:MaxMetaspaceSize=1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${System.getProperty("user.dir")}"
|
||||
}
|
||||
|
||||
final override fun tearDown() {
|
||||
runAll(
|
||||
{ super.tearDown() },
|
||||
{ useK2Plugin = beforeSetupK2PluginProperty },
|
||||
)
|
||||
}
|
||||
|
||||
override fun setUpFixtures() {
|
||||
myTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName()).fixture
|
||||
context.mutableCodeInsightTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(myTestFixture)
|
||||
@@ -239,9 +224,9 @@ abstract class AbstractKotlinMppGradleImportingTest : GradleImportingTestCase(),
|
||||
|
||||
override fun tearDownFixtures() {
|
||||
runAll(
|
||||
ThrowableRunnable { context.codeInsightTestFixture.tearDown() },
|
||||
ThrowableRunnable { context.mutableCodeInsightTestFixture = null },
|
||||
ThrowableRunnable { myTestFixture = null },
|
||||
{ context.codeInsightTestFixture.tearDown() },
|
||||
{ context.mutableCodeInsightTestFixture = null },
|
||||
{ myTestFixture = null },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+18
-3
@@ -1,11 +1,14 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.run.gradle
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.idea.run.getConfiguration
|
||||
import org.jetbrains.kotlin.idea.test.ExpectedPluginModeProvider
|
||||
import org.jetbrains.kotlin.idea.test.assertKotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.runAll
|
||||
import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
|
||||
import org.jetbrains.kotlin.idea.testFramework.gradle.KotlinGradleProjectTestCase
|
||||
import org.jetbrains.plugins.gradle.testFramework.annotations.AllGradleVersionsSource
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
@@ -14,9 +17,21 @@ import kotlin.test.assertEquals
|
||||
abstract class KotlinGradleProjectRunConfigurationTestCase : KotlinGradleProjectTestCase(),
|
||||
ExpectedPluginModeProvider {
|
||||
|
||||
private lateinit var testRootDisposable: Disposable
|
||||
|
||||
final override fun getTestRootDisposable(): Disposable = testRootDisposable
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
assertKotlinPluginMode()
|
||||
testRootDisposable = Disposer.newCheckedDisposable()
|
||||
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
runAll(
|
||||
{ Disposer.dispose(testRootDisposable) },
|
||||
{ super.tearDown() },
|
||||
)
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
+3
-3
@@ -14,8 +14,8 @@ import junit.framework.ComparisonFailure
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.ExpectedPluginModeProvider
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.assertKotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.runAll
|
||||
import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractKotlinInlayHintsProviderTest : DeclarativeInlayHintsProviderTestCase(),
|
||||
@@ -25,7 +25,8 @@ abstract class AbstractKotlinInlayHintsProviderTest : DeclarativeInlayHintsProvi
|
||||
get() = KotlinPluginMode.K1
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
|
||||
customToStringProvider = { element ->
|
||||
val virtualFile = element.containingFile.virtualFile
|
||||
val jarFileSystem = virtualFile.fileSystem as? JarFileSystem
|
||||
@@ -35,7 +36,6 @@ abstract class AbstractKotlinInlayHintsProviderTest : DeclarativeInlayHintsProvi
|
||||
} ?: virtualFile.name
|
||||
"[$path:${if (jarFileSystem != null) "*" else element.startOffset.toString()}]"
|
||||
}
|
||||
assertKotlinPluginMode()
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
|
||||
+2
-3
@@ -5,7 +5,7 @@ import com.intellij.testFramework.fixtures.CompletionAutoPopupTestCase
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.ExpectedPluginModeProvider
|
||||
import org.jetbrains.kotlin.idea.test.assertKotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
|
||||
import org.junit.internal.runners.JUnit38ClassRunner
|
||||
import org.junit.runner.RunWith
|
||||
import kotlin.test.assertContains
|
||||
@@ -18,8 +18,7 @@ open class KotlinAutoPopupTest : CompletionAutoPopupTestCase(),
|
||||
get() = KotlinPluginMode.K1
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
assertKotlinPluginMode()
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
}
|
||||
|
||||
fun testAfterLT() {
|
||||
|
||||
+8
-6
@@ -18,7 +18,6 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
import com.intellij.util.ThrowableRunnable
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.base.util.allScope
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
||||
@@ -86,12 +85,16 @@ abstract class AbstractRunConfigurationBaseTest : KotlinCodeInsightTestCase(),
|
||||
override val pluginMode: KotlinPluginMode
|
||||
get() = KotlinPluginMode.K1
|
||||
|
||||
override fun setUp() {
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
runAll(
|
||||
ThrowableRunnable { unconfigureDefaultModule() },
|
||||
ThrowableRunnable { unconfigureOtherModules() },
|
||||
ThrowableRunnable { configuredModules = emptyList() },
|
||||
ThrowableRunnable { super.tearDown() }
|
||||
{ unconfigureDefaultModule() },
|
||||
{ unconfigureOtherModules() },
|
||||
{ configuredModules = emptyList() },
|
||||
{ super.tearDown() },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -131,7 +134,6 @@ abstract class AbstractRunConfigurationBaseTest : KotlinCodeInsightTestCase(),
|
||||
|
||||
platform.addJdk(testRootDisposable)
|
||||
configuredModules = configureModules(projectDir, projectBaseDir, platform)
|
||||
assertKotlinPluginMode()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -155,13 +155,12 @@ abstract class KotlinDescriptorTestCase : DescriptorTestCase(),
|
||||
protected open val compileWithK2: Boolean get() = false
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
|
||||
registerEvaluatorBackend()
|
||||
|
||||
KotlinEvaluator.LOG_COMPILATIONS = true
|
||||
logPropagator = LogPropagator(::systemLogger).apply { attach() }
|
||||
assertKotlinPluginMode()
|
||||
atDebuggerTearDown { restoreEvaluatorBackend() }
|
||||
atDebuggerTearDown { logPropagator = null }
|
||||
atDebuggerTearDown { logPropagator?.detach() }
|
||||
|
||||
+4
-5
@@ -62,11 +62,10 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase(),
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
enableKotlinOfficialCodeStyle(project)
|
||||
|
||||
vfsDisposable = allowProjectRootAccess(this)
|
||||
assertKotlinPluginMode()
|
||||
}
|
||||
|
||||
// [TargetSupportException] can be thrown by the multiplatform test setup when a test artifact doesn't exist for the host platform.
|
||||
@@ -124,9 +123,9 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase(),
|
||||
|
||||
override fun tearDown() {
|
||||
runAll(
|
||||
ThrowableRunnable { disposeVfsRootAccess(vfsDisposable) },
|
||||
ThrowableRunnable { disableKotlinOfficialCodeStyle(project) },
|
||||
ThrowableRunnable { super.tearDown() }
|
||||
{ disposeVfsRootAccess(vfsDisposable) },
|
||||
{ disableKotlinOfficialCodeStyle(project) },
|
||||
{ super.tearDown() },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -4,7 +4,6 @@ package org.jetbrains.kotlin.idea.test
|
||||
|
||||
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
|
||||
import com.intellij.util.ThrowableRunnable
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.base.test.KotlinRoot
|
||||
import java.io.File
|
||||
@@ -16,7 +15,8 @@ abstract class KotlinLightPlatformCodeInsightFixtureTestCase : LightPlatformCode
|
||||
get() = KotlinPluginMode.K1
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
|
||||
enableKotlinOfficialCodeStyle(project)
|
||||
VfsRootAccess.allowRootAccess(myFixture.testRootDisposable, KotlinRoot.DIR.path)
|
||||
|
||||
@@ -24,13 +24,12 @@ abstract class KotlinLightPlatformCodeInsightFixtureTestCase : LightPlatformCode
|
||||
if (pluginMode == KotlinPluginMode.K1) {
|
||||
invalidateLibraryCache(project)
|
||||
}
|
||||
assertKotlinPluginMode()
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
runAll(
|
||||
ThrowableRunnable { disableKotlinOfficialCodeStyle(project) },
|
||||
ThrowableRunnable { super.tearDown() },
|
||||
{ disableKotlinOfficialCodeStyle(project) },
|
||||
{ super.tearDown() },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+13
-18
@@ -15,7 +15,6 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode;
|
||||
import org.jetbrains.kotlin.idea.base.plugin.SystemPropertyUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -26,7 +25,9 @@ import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
public abstract class KotlinLightCodeInsightFixtureTestCaseBase extends LightJavaCodeInsightFixtureTestCase {
|
||||
public abstract class KotlinLightCodeInsightFixtureTestCaseBase extends LightJavaCodeInsightFixtureTestCase
|
||||
implements ExpectedPluginModeProvider {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
@@ -49,26 +50,13 @@ public abstract class KotlinLightCodeInsightFixtureTestCaseBase extends LightJav
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
boolean useK2Plugin = isFirPlugin();
|
||||
SystemPropertyUtils.setUseK2Plugin(useK2Plugin);
|
||||
super.setUp();
|
||||
|
||||
// todo test classes should inherit ExpectedPluginModeProvider directly
|
||||
ExpectedPluginModeProviderKt.assertKotlinPluginMode(new ExpectedPluginModeProvider() {
|
||||
|
||||
@Override
|
||||
public @NotNull KotlinPluginMode getPluginMode() {
|
||||
return KotlinPluginMode.of(useK2Plugin);
|
||||
}
|
||||
});
|
||||
ExpectedPluginModeProviderKt.setUpWithKotlinPlugin(this, super::setUp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
RunAll.runAll(
|
||||
() -> myTempFiles.deleteAll(),
|
||||
() -> super.tearDown()
|
||||
);
|
||||
RunAll.runAll(myTempFiles::deleteAll,
|
||||
super::tearDown);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -102,7 +90,14 @@ public abstract class KotlinLightCodeInsightFixtureTestCaseBase extends LightJav
|
||||
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
|
||||
}
|
||||
|
||||
// todo replace with getPluginMode overrides
|
||||
// todo remove the method
|
||||
protected boolean isFirPlugin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @NotNull KotlinPluginMode getPluginMode() {
|
||||
return KotlinPluginMode.of(isFirPlugin());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user