diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt index 77ed81f5207b..93b9eb930033 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt @@ -4,11 +4,11 @@ package org.jetbrains.plugins.gradle.testFramework import com.intellij.testFramework.common.runAll import org.gradle.util.GradleVersion import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleProjectTestFixture -import org.jetbrains.plugins.gradle.testFramework.fixtures.application.GradleTestApplication +import org.jetbrains.plugins.gradle.testFramework.fixtures.application.GradleProjectTestApplication import org.jetbrains.plugins.gradle.testFramework.util.onFailureCatching import org.junit.jupiter.api.AfterAll -@GradleTestApplication +@GradleProjectTestApplication abstract class GradleProjectBaseTestCase { private var fixture: GradleProjectTestFixture? = null diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplicationLeakTrackerExtension.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt similarity index 57% rename from plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplicationLeakTrackerExtension.kt rename to plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt index 6a0f9a826585..ac78ba776618 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplicationLeakTrackerExtension.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt @@ -1,22 +1,50 @@ // 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.openapi.application.ApplicationManager import com.intellij.openapi.application.invokeAndWaitIfNeeded import com.intellij.openapi.roots.impl.libraries.LibraryTableTracker import com.intellij.openapi.vfs.impl.VirtualFilePointerTracker import com.intellij.testFramework.SdkLeakTracker +import com.intellij.testFramework.common.cleanApplicationState import com.intellij.testFramework.common.runAll -import org.jetbrains.annotations.TestOnly +import com.intellij.testFramework.junit5.impl.testApplication import org.jetbrains.plugins.gradle.testFramework.fixtures.tracker.ExternalSystemListenerLeakTracker import org.junit.jupiter.api.extension.AfterAllCallback import org.junit.jupiter.api.extension.BeforeAllCallback +import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtensionContext +/** + * Custom application initializer for the [org.jetbrains.plugins.gradle.testFramework.GradleProjectBaseTestCase]. + * This initializer has adjusted leak listeners to the [org.junit.jupiter.api.BeforeAll] and [org.junit.jupiter.api.AfterAll] bounds. + * It is necessary because [org.jetbrains.plugins.gradle.testFramework.GradleProjectBaseTestCase] + * 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 com.intellij.testFramework.junit5.TestApplication + */ +@Target(AnnotationTarget.CLASS) +@ExtendWith( + GradleProjectTestApplicationExtension::class, + GradleProjectTestApplicationLeakTrackerExtension::class, +) +annotation class GradleProjectTestApplication + +private class GradleProjectTestApplicationExtension : BeforeAllCallback, AfterAllCallback { + override fun beforeAll(context: ExtensionContext) { + context.testApplication().getOrThrow() + } + + override fun afterAll(context: ExtensionContext) { + ApplicationManager.getApplication().cleanApplicationState() + } +} + /** * @see com.intellij.testFramework.junit5.impl.TestApplicationLeakTrackerExtension */ -@TestOnly -class GradleTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCallback { +private class GradleProjectTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCallback { companion object { private const val LEAK_TRACKERS_KEY = "Gradle application-level leak trackers" @@ -33,7 +61,6 @@ class GradleTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCal .checkNothingLeaked() } - @TestOnly private class GradleLeakTrackers { val sdkLeakTracker = SdkLeakTracker() @@ -50,4 +77,4 @@ class GradleTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCal ) } } -} +} \ No newline at end of file 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 deleted file mode 100644 index 4c530e56e467..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplication.kt +++ /dev/null @@ -1,17 +0,0 @@ -// 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 org.jetbrains.annotations.TestOnly -import org.junit.jupiter.api.extension.ExtendWith - -/** - * @see com.intellij.testFramework.junit5.TestApplication - */ -@TestOnly -@Target(AnnotationTarget.CLASS) -@ExtendWith( - GradleTestApplicationExtension::class, - GradleTestApplicationLeakTrackerExtension::class, -) -annotation class GradleTestApplication { -} \ No newline at end of file diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplicationExtension.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplicationExtension.kt deleted file mode 100644 index c601a6c27dd5..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleTestApplicationExtension.kt +++ /dev/null @@ -1,24 +0,0 @@ -// 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.openapi.application.ApplicationManager -import com.intellij.testFramework.common.cleanApplicationState -import com.intellij.testFramework.junit5.impl.testApplication -import org.jetbrains.annotations.TestOnly -import org.junit.jupiter.api.extension.AfterAllCallback -import org.junit.jupiter.api.extension.BeforeAllCallback -import org.junit.jupiter.api.extension.ExtensionContext - -/** - * @see com.intellij.testFramework.junit5.impl.TestApplicationExtension - */ -@TestOnly -class GradleTestApplicationExtension : BeforeAllCallback, AfterAllCallback { - override fun beforeAll(context: ExtensionContext) { - context.testApplication().getOrThrow() - } - - override fun afterAll(context: ExtensionContext) { - ApplicationManager.getApplication().cleanApplicationState() - } -} \ No newline at end of file