mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit: search for tests in classpath: fix all in directory
directory implicitly imply that single module should be used + it should be a module where the directory is located
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.execution;
|
||||
|
||||
import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
||||
@@ -27,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.PathsList;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -43,7 +43,10 @@ public class TestClassCollector {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(TestClassCollector.class);
|
||||
|
||||
public static String[] collectClassFQNames(String packageName, JavaTestConfigurationBase configuration, Function<ClassLoader, Predicate<Class<?>>> predicateProducer) {
|
||||
public static String[] collectClassFQNames(String packageName,
|
||||
@Nullable Path rootPath,
|
||||
JavaTestConfigurationBase configuration,
|
||||
Function<ClassLoader, Predicate<Class<?>>> predicateProducer) {
|
||||
Module module = configuration.getConfigurationModule().getModule();
|
||||
List<URL> urls = new ArrayList<>();
|
||||
|
||||
@@ -58,17 +61,6 @@ public class TestClassCollector {
|
||||
}
|
||||
}
|
||||
|
||||
Path rootPath = null;
|
||||
if (configuration.getTestSearchScope() == TestSearchScope.SINGLE_MODULE) {
|
||||
CompilerModuleExtension moduleExtension = CompilerModuleExtension.getInstance(module);
|
||||
if (moduleExtension != null) {
|
||||
VirtualFile tests = moduleExtension.getCompilerOutputPathForTests();
|
||||
if (tests != null) {
|
||||
rootPath = Paths.get(VfsUtilCore.virtualToIoFile(tests).toURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> classes = new HashSet<>();
|
||||
UrlClassLoader classLoader = UrlClassLoader.build().allowLock().useCache().urls(urls).get();
|
||||
try {
|
||||
@@ -123,4 +115,18 @@ public class TestClassCollector {
|
||||
|
||||
return ArrayUtil.toStringArray(classes);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Path getRootPath(Module module, final boolean chooseSingleModule) {
|
||||
if (chooseSingleModule) {
|
||||
CompilerModuleExtension moduleExtension = CompilerModuleExtension.getInstance(module);
|
||||
if (moduleExtension != null) {
|
||||
VirtualFile tests = moduleExtension.getCompilerOutputPathForTests();
|
||||
if (tests != null) {
|
||||
return Paths.get(VfsUtilCore.virtualToIoFile(tests).toURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.execution.junit;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.execution.TestClassCollector;
|
||||
import com.intellij.execution.configurations.RuntimeConfigurationError;
|
||||
import com.intellij.execution.configurations.RuntimeConfigurationException;
|
||||
import com.intellij.execution.configurations.RuntimeConfigurationWarning;
|
||||
@@ -25,6 +26,7 @@ import com.intellij.execution.testframework.SourceScope;
|
||||
import com.intellij.execution.util.JavaParametersUtil;
|
||||
import com.intellij.execution.util.ProgramParametersUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -36,6 +38,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScopesCore;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
||||
class TestDirectory extends TestPackage {
|
||||
@@ -76,6 +79,15 @@ class TestDirectory extends TestPackage {
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Path getRootPath() {
|
||||
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(getConfiguration().getPersistentData().getDirName()));
|
||||
if (file == null) return null;
|
||||
Module dirModule = ModuleUtilCore.findModuleForFile(file, getConfiguration().getProject());
|
||||
return TestClassCollector.getRootPath(dirModule, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean configureByModule(Module module) {
|
||||
return module != null;
|
||||
|
||||
@@ -45,6 +45,7 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -81,7 +82,7 @@ public class TestPackage extends TestObject {
|
||||
long start = System.currentTimeMillis();
|
||||
if (Registry.is("junit4.search.4.tests.in.classpath", false)) {
|
||||
String packageName = getPackageName(data);
|
||||
String[] classNames = TestClassCollector.collectClassFQNames(packageName, getConfiguration(), TestPackage::createPredicate);
|
||||
String[] classNames = TestClassCollector.collectClassFQNames(packageName, getRootPath(), getConfiguration(), TestPackage::createPredicate);
|
||||
PsiManager manager = PsiManager.getInstance(myProject);
|
||||
Arrays.stream(classNames)
|
||||
.filter(className -> acceptClassName(className)) //check patterns
|
||||
@@ -113,6 +114,13 @@ public class TestPackage extends TestObject {
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Path getRootPath() {
|
||||
Module module = getConfiguration().getConfigurationModule().getModule();
|
||||
boolean chooseSingleModule = getConfiguration().getTestSearchScope() == TestSearchScope.SINGLE_MODULE;
|
||||
return TestClassCollector.getRootPath(module, chooseSingleModule);
|
||||
}
|
||||
|
||||
protected boolean acceptClassName(String className) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user