allow junit tests in dumb mode for existing configuration

This commit is contained in:
Anna.Kozlova
2017-07-19 17:33:10 +02:00
parent a75ee5ad8c
commit 9d3e5593eb
2 changed files with 23 additions and 5 deletions
@@ -31,6 +31,7 @@ import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.registry.Registry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -112,8 +113,13 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
ex[0] = e;
}
};
//noinspection StatementWithEmptyBody
while (!runSmartModeReadActionWithWritePriority(runnable, new SensitiveProgressWrapper(indicator)));
if (Registry.is("junit4.search.4.tests.in.classpath", false)) {
runnable.run();
}
else {
//noinspection StatementWithEmptyBody
while (!runSmartModeReadActionWithWritePriority(runnable, new SensitiveProgressWrapper(indicator)));
}
if (ex[0] != null) {
logCantRunException(ex[0]);
}
@@ -169,7 +175,7 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
@Override
public void onSuccess() {
DumbService.getInstance(getProject()).runWhenSmart(() -> {
Runnable runnable = () -> {
try {
onFound();
}
@@ -177,7 +183,13 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
LOG.error(e);
}
finish();
});
};
if (Registry.is("junit4.search.4.tests.in.classpath", false)) {
runnable.run();
}
else {
DumbService.getInstance(getProject()).runWhenSmart(runnable);
}
}
public void finish() {
@@ -26,6 +26,7 @@ import com.intellij.execution.testframework.SourceScope;
import com.intellij.execution.testframework.TestSearchScope;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Ref;
@@ -71,7 +72,9 @@ public class TestPackage extends TestObject {
final SourceScope sourceScope = getSourceScope();
final Module module = getConfiguration().getConfigurationModule().getModule();
if (sourceScope != null && !ReadAction.compute(() -> isJUnit5(module, sourceScope, myProject))) {
DumbService instance = DumbService.getInstance(myProject);
try {
instance.setAlternativeResolveEnabled(true);
final TestClassFilter classFilter = getClassFilter(data);
LOG.assertTrue(classFilter.getBase() != null);
long start = System.currentTimeMillis();
@@ -81,7 +84,7 @@ public class TestPackage extends TestObject {
PsiManager manager = PsiManager.getInstance(myProject);
Arrays.stream(classNames)
.filter(className -> acceptClassName(className)) //check patterns
.map(name -> ClassUtil.findPsiClass(manager, name, null, true, classFilter.getScope()))
.map(name -> ReadAction.compute(() -> ClassUtil.findPsiClass(manager, name, null, true, classFilter.getScope())))
.filter(aClass -> aClass != null)
.forEach(myClasses::add);
LOG.info("Found tests in " + (System.currentTimeMillis() - start));
@@ -91,6 +94,9 @@ public class TestPackage extends TestObject {
}
}
catch (CantRunException ignored) {}
finally {
instance.setAlternativeResolveEnabled(false);
}
}
}