Search in sources :

Example 6 with SourceScope

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 + '\"');
        }
    }
}
Also used : CantRunException(com.intellij.execution.CantRunException) SourceScope(com.intellij.execution.testframework.SourceScope) TestSearchScope(com.intellij.execution.testframework.TestSearchScope) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with SourceScope

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) {
            }
        }
    };
}
Also used : SourceScope(com.intellij.execution.testframework.SourceScope) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet)

Example 8 with SourceScope

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;
}
Also used : Project(com.intellij.openapi.project.Project) SourceScope(com.intellij.execution.testframework.SourceScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 9 with SourceScope

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();
    }
}
Also used : SourceScope(com.intellij.execution.testframework.SourceScope) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with SourceScope

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()]);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceScope(com.intellij.execution.testframework.SourceScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SourceScope (com.intellij.execution.testframework.SourceScope)13 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 CantRunException (com.intellij.execution.CantRunException)2 JavaParameters (com.intellij.execution.configurations.JavaParameters)2 RuntimeConfigurationException (com.intellij.execution.configurations.RuntimeConfigurationException)2 PsiClass (com.intellij.psi.PsiClass)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)1 SearchForTestsTask (com.intellij.execution.testframework.SearchForTestsTask)1 TestSearchScope (com.intellij.execution.testframework.TestSearchScope)1 JUnit5IdeaTestRunner (com.intellij.junit5.JUnit5IdeaTestRunner)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PathsList (com.intellij.util.PathsList)1 TestNGConfiguration (com.theoryinpractice.testng.configuration.TestNGConfiguration)1 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1