From aa6801569a3a1e146af62f9702cfa3b1b617343e Mon Sep 17 00:00:00 2001 From: Andrey Uskov Date: Mon, 27 Apr 2020 22:01:30 +0300 Subject: [PATCH] Fix compilation of ExternalSystem tests in legacy branches --- .../ExternalSystemImportingTestCase.java | 8 +++- .../gradle/ExternalSystemTestCase.java | 15 +------ .../gradle/ExternalSystemTestCaseBunch.java | 39 +++++++++++++++++++ .../ExternalSystemTestCaseBunch.java.192 | 29 ++++++++++++++ 4 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java create mode 100644 idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java.192 diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java index 44cebb75416..44fa07be5ec 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java @@ -256,11 +256,13 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest assertOrderedElementsAreEqual(actual, Arrays.asList(expected)); } + /* Unused but available in ESITC@IDEA protected void assertModuleOutputs(String moduleName, String... outputs) { String[] outputPaths = ContainerUtil.map2Array(CompilerPaths.getOutputPaths(new Module[]{getModule(moduleName)}), String.class, s -> getAbsolutePath(s)); assertUnorderedElementsAreEqual(outputPaths, outputs); } + */ protected void assertModuleOutput(String moduleName, String output, String testOutput) { CompilerModuleExtension e = getCompilerExtension(moduleName); @@ -378,11 +380,13 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest assertOrderedElementsAreEqual(predicate, collectModuleDepsNames(moduleName, clazz), expectedDeps); } + /* Unused but available in ESITC@IDEA protected void assertProductionOnTestDependencies(String moduleName, String... expectedDeps) { assertOrderedElementsAreEqual(collectModuleDepsNames( moduleName, entry -> entry instanceof ModuleOrderEntry && ((ModuleOrderEntry)entry).isProductionOnTestDependency() ), expectedDeps); } + */ protected void assertModuleModuleDepScope(String moduleName, String depName, DependencyScope... scopes) { List deps = getModuleModuleDeps(moduleName, depName); @@ -591,7 +595,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest final Ref> error = Ref.create(); ImportSpec importSpec = createImportSpec(); ExternalProjectRefreshCallback callback = importSpec.getCallback(); - if (callback == null || callback instanceof ImportSpecBuilder.DefaultProjectRefreshCallback) { + if (callback == null || ExternalSystemTestCaseBunch.isDefaultRefreshCallback(callback)) { importSpec = new TestImportSpecBuilder(importSpec) .setCreateEmptyContentRoots(projectSettings.isCreateEmptyContentRootDirectories()) .callback(new ExternalProjectRefreshCallback() { @@ -744,6 +748,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest return ModuleRootManager.getInstance(getModule(module)); } + /* Unused but available in ESITC@IDEA protected void ignoreData(BooleanFunction> booleanFunction, final boolean ignored) { final ExternalProjectInfo externalProjectInfo = ProjectDataManagerImpl.getInstance().getExternalProjectData( myProject, getExternalSystemId(), getCurrentExternalProjectSettings().getExternalProjectPath()); @@ -758,6 +763,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest } ServiceManager.getService(ProjectDataManager.class).importData(projectDataNode, myProject, true); } + */ @NotNull private List getModuleDep(@NotNull String moduleName, @NotNull String depName, @NotNull Class clazz) { diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java index 02bef0cd2fa..2856f23bc79 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java @@ -77,9 +77,6 @@ import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; -/** - * @author Vladislav.Soroka - */ public abstract class ExternalSystemTestCase extends UsefulTestCase { private static final BiPredicate EQUALS_PREDICATE = (t, u) -> Objects.equals(t, u); @@ -425,17 +422,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } private void build(Object[] buildableElements) { - Promise promise; - if (buildableElements instanceof Module[]) { - promise = ProjectTaskManager.getInstance(myProject).build((Module[])buildableElements); - } - else if (buildableElements instanceof Artifact[]) { - promise = ProjectTaskManager.getInstance(myProject).build((Artifact[])buildableElements); - } - else { - throw new AssertionError("Unsupported buildableElements: " + Arrays.toString(buildableElements)); - } - edt(() -> PlatformTestUtil.waitForPromise(promise)); + ExternalSystemTestCaseBunch.build(buildableElements, myProject); } private void compile(@NotNull CompileScope scope) { diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java new file mode 100644 index 00000000000..e03926734a4 --- /dev/null +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java @@ -0,0 +1,39 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.codeInsight.gradle; + +import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.packaging.artifacts.Artifact; +import com.intellij.task.ProjectTaskManager; +import com.intellij.testFramework.EdtTestUtil; +import com.intellij.testFramework.PlatformTestUtil; +import org.jetbrains.concurrency.Promise; +import java.util.Arrays; + +//BUNCH: 192 +class ExternalSystemTestCaseBunch { + + protected static boolean isDefaultRefreshCallback(Object callback) { + return callback instanceof ImportSpecBuilder.DefaultProjectRefreshCallback; + } + + protected static void build(Object[] buildableElements, Project myProject) { + Promise promise; + if (buildableElements instanceof Module[]) { + promise = ProjectTaskManager.getInstance(myProject).build((Module[])buildableElements); + } + else if (buildableElements instanceof Artifact[]) { + promise = ProjectTaskManager.getInstance(myProject).build((Artifact[])buildableElements); + } + else { + throw new AssertionError("Unsupported buildableElements: " + Arrays.toString(buildableElements)); + } + EdtTestUtil.runInEdtAndWait(() -> PlatformTestUtil.waitForPromise(promise)); + } + +} \ No newline at end of file diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java.192 b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java.192 new file mode 100644 index 00000000000..720e12d8428 --- /dev/null +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCaseBunch.java.192 @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.codeInsight.gradle; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.packaging.artifacts.Artifact; +import com.intellij.task.ProjectTaskManager; + +//BUNCH 193 +class ExternalSystemTestCaseBunch { + + protected static boolean isDefaultRefreshCallback(Object callback) { + return false; + } + + protected static void build(Object[] buildableElements, Project myProject) { + if (buildableElements instanceof Module[]) { + ProjectTaskManager.getInstance(myProject).build((Module[])buildableElements); + } + else if (buildableElements instanceof Artifact[]) { + ProjectTaskManager.getInstance(myProject).build((Artifact[])buildableElements); + } + } + +} \ No newline at end of file