use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class TestNGTestPackage method fillTestObjects.
@Override
public void fillTestObjects(Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {
final String packageName = myConfig.getPersistantData().getPackageName();
PsiPackage psiPackage = ApplicationManager.getApplication().runReadAction(new Computable<PsiPackage>() {
@Nullable
public PsiPackage compute() {
return JavaPsiFacade.getInstance(myConfig.getProject()).findPackage(packageName);
}
});
if (psiPackage == null) {
throw CantRunException.packageNotFound(packageName);
} else {
TestSearchScope scope = myConfig.getPersistantData().getScope();
//TODO we should narrow this down by module really, if that's what's specified
SourceScope sourceScope = scope.getSourceScope(myConfig);
TestClassFilter projectFilter = new TestClassFilter(sourceScope != null ? sourceScope.getGlobalSearchScope() : GlobalSearchScope.projectScope(myConfig.getProject()), myConfig.getProject(), true, true);
TestClassFilter filter = projectFilter.intersectionWith(PackageScope.packageScope(psiPackage, true));
calculateDependencies(null, classes, getSearchScope(), TestNGUtil.getAllTestClasses(filter, false));
if (classes.size() == 0) {
throw new CantRunException("No tests found in the package \"" + packageName + '\"');
}
}
}
use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class TestPackage method createSearchingForTestsTask.
@Override
public SearchForTestsTask createSearchingForTestsTask() {
final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
return new SearchForTestsTask(getConfiguration().getProject(), myServerSocket) {
private final THashSet<PsiClass> myClasses = new THashSet<>();
@Override
protected void search() {
myClasses.clear();
final SourceScope sourceScope = getSourceScope();
final Module module = getConfiguration().getConfigurationModule().getModule();
if (sourceScope != null && !ReadAction.compute(() -> isJUnit5(module, sourceScope, myProject))) {
try {
final TestClassFilter classFilter = getClassFilter(data);
LOG.assertTrue(classFilter.getBase() != null);
ConfigurationUtil.findAllTestClasses(classFilter, module, myClasses);
} catch (CantRunException ignored) {
}
}
}
@Override
protected void onFound() {
try {
addClassesListToJavaParameters(myClasses, psiClass -> psiClass != null ? JavaExecutionUtil.getRuntimeQualifiedName(psiClass) : null, getPackageName(data), createTempFiles(), getJavaParameters());
} catch (ExecutionException ignored) {
}
}
};
}
use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class JUnitTestDiscoveryRunnableState method retrievePsiElement.
@Override
protected PsiElement retrievePsiElement(Object pattern) {
if (pattern instanceof String) {
final String className = StringUtil.getPackageName((String) pattern, ',');
if (!pattern.equals(className)) {
final Project project = getConfiguration().getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final SourceScope sourceScope = getSourceScope();
final GlobalSearchScope globalSearchScope = sourceScope != null ? sourceScope.getGlobalSearchScope() : GlobalSearchScope.projectScope(project);
return facade.findClass(className, globalSearchScope);
}
}
return null;
}
use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class JUnitConsoleProperties method initScope.
@NotNull
@Override
protected GlobalSearchScope initScope() {
final JUnitConfiguration.Data persistentData = getConfiguration().getPersistentData();
final String testObject = persistentData.TEST_OBJECT;
//ignore invisible setting
if (JUnitConfiguration.TEST_CATEGORY.equals(testObject) || JUnitConfiguration.TEST_PATTERN.equals(testObject) || JUnitConfiguration.TEST_PACKAGE.equals(testObject)) {
final SourceScope sourceScope = persistentData.getScope().getSourceScope(getConfiguration());
return sourceScope != null ? sourceScope.getGlobalSearchScope() : GlobalSearchScope.allScope(getProject());
} else {
return super.initScope();
}
}
use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class TestDirectory method getSourceScope.
@Nullable
@Override
public SourceScope getSourceScope() {
final String dirName = getConfiguration().getPersistentData().getDirName();
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(dirName));
final GlobalSearchScope globalSearchScope = file == null ? GlobalSearchScope.EMPTY_SCOPE : GlobalSearchScopesCore.directoryScope(getConfiguration().getProject(), file, true);
return new SourceScope() {
@Override
public GlobalSearchScope getGlobalSearchScope() {
return globalSearchScope;
}
@Override
public Project getProject() {
return getConfiguration().getProject();
}
@Override
public GlobalSearchScope getLibrariesScope() {
final Module module = getConfiguration().getConfigurationModule().getModule();
return module != null ? GlobalSearchScope.moduleWithLibrariesScope(module) : GlobalSearchScope.allScope(getConfiguration().getProject());
}
@Override
public Module[] getModulesToCompile() {
final Collection<Module> validModules = getConfiguration().getValidModules();
return validModules.toArray(new Module[validModules.size()]);
}
};
}
Aggregations