Compare commits

...

1 Commits

Author SHA1 Message Date
Andrey Uskov
b5407e83c7 Fix compilation of ExternalSystem tests in legacy branches 2020-04-28 11:17:21 +03:00
5 changed files with 86 additions and 23 deletions

View File

@@ -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<ModuleOrderEntry> deps = getModuleModuleDeps(moduleName, depName);
@@ -591,7 +595,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest
final Ref<Couple<String>> 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<DataNode<?>> 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 <T> List<T> getModuleDep(@NotNull String moduleName, @NotNull String depName, @NotNull Class<T> clazz) {

View File

@@ -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<Object, Object> EQUALS_PREDICATE = (t, u) -> Objects.equals(t, u);
@@ -425,17 +422,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase {
}
private void build(Object[] buildableElements) {
Promise<ProjectTaskManager.Result> 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) {

View File

@@ -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 193
class ExternalSystemTestCaseBunch {
protected static boolean isDefaultRefreshCallback(Object callback) {
return callback instanceof ImportSpecBuilder.DefaultProjectRefreshCallback;
}
protected static void build(Object[] buildableElements, Project myProject) {
Promise<ProjectTaskManager.Result> 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));
}
}

View File

@@ -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);
}
}
}

View File

@@ -60,15 +60,17 @@ class GradleQuickFixTest : GradleImportingTestCase() {
}
private fun applyInspectionFixes(tool: LocalInspectionTool, file: VirtualFile) {
invokeTestRunnable {
val presentation = runInspection(tool, myProject, listOf(file))
runInEdtAndWait {
invokeTestRunnable {
val presentation = runInspection(tool, myProject, listOf(file))
WriteCommandAction.runWriteCommandAction(myProject) {
val foundProblems = presentation.problemElements.values.mapNotNull { it as? ProblemDescriptorBase }
for (problem in foundProblems) {
val fixes = problem.fixes
if (fixes != null) {
fixes[0].applyFix(myProject, problem)
WriteCommandAction.runWriteCommandAction(myProject) {
val foundProblems = presentation.problemElements.values.mapNotNull { it as? ProblemDescriptorBase }
for (problem in foundProblems) {
val fixes = problem.fixes
if (fixes != null) {
fixes[0].applyFix(myProject, problem)
}
}
}
}