diff --git a/plugins/gradle/java/testSources/testFramework/GradleReloadProjectBaseTestCase.kt b/plugins/gradle/java/testSources/testFramework/GradleReloadProjectBaseTestCase.kt index ba52e6901bd7..bd3216209ab2 100644 --- a/plugins/gradle/java/testSources/testFramework/GradleReloadProjectBaseTestCase.kt +++ b/plugins/gradle/java/testSources/testFramework/GradleReloadProjectBaseTestCase.kt @@ -7,19 +7,19 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.closeProjectAsync import com.intellij.testFramework.common.runAll import com.intellij.testFramework.fixtures.IdeaTestFixture -import com.intellij.testFramework.junit5.TestApplication import com.intellij.testFramework.utils.vfs.createDirectory import kotlinx.coroutines.runBlocking import org.gradle.util.GradleVersion import org.jetbrains.plugins.gradle.testFramework.fixture.GradleExecutionTestFixture import org.jetbrains.plugins.gradle.testFramework.fixture.GradleExecutionTestFixtureImpl import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleTestFixture +import org.jetbrains.plugins.gradle.testFramework.fixtures.application.GradleTestApplication import org.jetbrains.plugins.gradle.testFramework.fixtures.impl.GradleTestFixtureImpl import org.jetbrains.plugins.gradle.testFramework.util.createSettingsFile import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.TestInfo -@TestApplication +@GradleTestApplication abstract class GradleReloadProjectBaseTestCase { private lateinit var testInfo: TestInfo diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleBaseTestCase.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleBaseTestCase.kt index 90044e8ee8f7..86146b2c57b5 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleBaseTestCase.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleBaseTestCase.kt @@ -8,15 +8,15 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.common.runAll -import com.intellij.testFramework.junit5.TestApplication import org.gradle.util.GradleVersion import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleTestFixture import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleTestFixtureFactory +import org.jetbrains.plugins.gradle.testFramework.fixtures.application.GradleTestApplication import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.TestInfo -@TestApplication +@GradleTestApplication abstract class GradleBaseTestCase { private lateinit var testDisposable: Disposable diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt index ac78ba776618..7b42eae34fea 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt @@ -22,6 +22,7 @@ import org.junit.jupiter.api.extension.ExtensionContext * orchestrate Gradle project with different configuration. These project instances are shared between tests. * They can be closed and opened at any time between the tests. * + * @see GradleTestApplication * @see com.intellij.testFramework.junit5.TestApplication */ @Target(AnnotationTarget.CLASS) diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplication.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplication.kt new file mode 100644 index 000000000000..b27bdb67550f --- /dev/null +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplication.kt @@ -0,0 +1,42 @@ +// 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.plugins.gradle.testFramework.fixtures.application + +import com.intellij.testFramework.junit5.TestApplication +import org.jetbrains.plugins.gradle.testFramework.fixtures.tracker.ExternalSystemListenerLeakTracker +import org.junit.jupiter.api.extension.* + +/** + * @see com.intellij.testFramework.junit5.TestApplication + */ +@TestApplication +@ExtendWith( + GradleTestApplicationLeakTrackerExtension::class +) +annotation class GradleTestApplication + +private class GradleTestApplicationLeakTrackerExtension : BeforeEachCallback, AfterEachCallback { + + companion object { + private const val LEAK_TRACKERS_KEY = "Gradle application-level leak trackers" + } + + override fun beforeEach(context: ExtensionContext) { + context.getStore(ExtensionContext.Namespace.GLOBAL) + .put(LEAK_TRACKERS_KEY, GradleLeakTrackers()) + } + + override fun afterEach(context: ExtensionContext) { + context.getStore(ExtensionContext.Namespace.GLOBAL) + .get(LEAK_TRACKERS_KEY, GradleLeakTrackers::class.java) + .checkNothingLeaked() + } + + private class GradleLeakTrackers { + + val externalSystemListenerLeakTracker = ExternalSystemListenerLeakTracker() + + fun checkNothingLeaked() { + externalSystemListenerLeakTracker.tearDown() + } + } +} \ No newline at end of file diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureImpl.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureImpl.kt index 5e644a0b8408..aa5e3c0156d3 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureImpl.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureImpl.kt @@ -23,7 +23,6 @@ import org.gradle.util.GradleVersion import org.jetbrains.plugins.gradle.service.project.open.linkAndSyncGradleProject import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleTestFixture import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleTestFixtureFactory -import org.jetbrains.plugins.gradle.testFramework.fixtures.tracker.ExternalSystemListenerLeakTracker import org.jetbrains.plugins.gradle.testFramework.fixtures.tracker.OperationLeakTracker import org.jetbrains.plugins.gradle.util.GradleConstants import org.jetbrains.plugins.gradle.util.getGradleProjectReloadOperation @@ -35,7 +34,6 @@ class GradleTestFixtureImpl( override val gradleVersion: GradleVersion, ) : GradleTestFixture { - private lateinit var listenerLeakTracker: ExternalSystemListenerLeakTracker private lateinit var reloadLeakTracker: OperationLeakTracker private lateinit var testDisposable: Disposable @@ -48,9 +46,6 @@ class GradleTestFixtureImpl( override lateinit var gradleJvm: String override fun setUp() { - listenerLeakTracker = ExternalSystemListenerLeakTracker() - listenerLeakTracker.setUp() - reloadLeakTracker = OperationLeakTracker { getGradleProjectReloadOperation(it) } reloadLeakTracker.setUp() @@ -76,8 +71,7 @@ class GradleTestFixtureImpl( { fileFixture.tearDown() }, { sdkFixture.tearDown() }, { Disposer.dispose(testDisposable) }, - { reloadLeakTracker.tearDown() }, - { listenerLeakTracker.tearDown() } + { reloadLeakTracker.tearDown() } ) }