Search in sources :

Example 1 with TestArtifactSearchScopes

use of com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes in project android by JetBrains.

the class ModuleNodeIconDecorator method decorate.

@Override
public void decorate(ProjectViewNode node, PresentationData data) {
    if (!(node instanceof PsiDirectoryNode)) {
        return;
    }
    final PsiDirectoryNode psiDirectoryNode = (PsiDirectoryNode) node;
    PsiDirectory psiDirectory = psiDirectoryNode.getValue();
    assert psiDirectory != null;
    Project project = psiDirectory.getProject();
    if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
        return;
    }
    VirtualFile folder = psiDirectory.getVirtualFile();
    Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(folder);
    if (module != null) {
        if (isModuleDir(module, folder)) {
            data.setIcon(getModuleIcon(module));
        } else if (isSourceRoot(folder, project)) {
            TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
            if (testScopes != null && testScopes.isAndroidTestSource(folder)) {
                data.setIcon(AndroidIcons.AndroidTestRoot);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) Module(com.intellij.openapi.module.Module)

Example 2 with TestArtifactSearchScopes

use of com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes in project android by JetBrains.

the class AndroidTestsPattern method getClassFilter.

@Override
protected TestClassFilter getClassFilter(JUnitConfiguration.Data data) throws CantRunException {
    TestClassFilter classFilter = super.getClassFilter(data);
    JUnitConfiguration configuration = getConfiguration();
    Module[] modules = configuration instanceof AndroidJUnitConfiguration ? ((AndroidJUnitConfiguration) configuration).getModulesToCompile() : configuration.getModules();
    for (Module module : modules) {
        TestArtifactSearchScopes testArtifactSearchScopes = TestArtifactSearchScopes.get(module);
        if (testArtifactSearchScopes != null) {
            classFilter = classFilter.intersectionWith(testArtifactSearchScopes.getAndroidTestExcludeScope());
        }
    }
    return classFilter;
}
Also used : TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) Module(com.intellij.openapi.module.Module) TestClassFilter(com.intellij.execution.junit.TestClassFilter)

Example 3 with TestArtifactSearchScopes

use of com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes in project android by JetBrains.

the class AndroidTestConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(AndroidTestRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Module module = AndroidUtils.getAndroidModule(context);
    if (module == null) {
        return false;
    }
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    location = JavaExecutionUtil.stepIntoSingleClass(location);
    if (location == null) {
        return false;
    }
    final PsiElement element = location.getPsiElement();
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return false;
    }
    // TODO: Resolve direct AndroidGradleModel dep (b/22596984)
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel != null) {
        // Only suggest the android test run configuration if it makes sense for the selected test artifact.
        if (androidModel.getAndroidTestArtifactInSelectedVariant() == null) {
            return false;
        }
        TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
        if (testScopes == null) {
            return false;
        }
        VirtualFile virtualFile = null;
        if (element instanceof PsiDirectory) {
            virtualFile = ((PsiDirectory) element).getVirtualFile();
        } else {
            PsiFile psiFile = element.getContainingFile();
            if (psiFile != null) {
                virtualFile = psiFile.getVirtualFile();
            }
        }
        if (virtualFile == null) {
            return false;
        }
        if (!testScopes.isAndroidTestSource(virtualFile)) {
            return false;
        }
    }
    setupInstrumentationTestRunner(configuration, facet);
    if (setupAllInPackageConfiguration(configuration, element, context, sourceElement)) {
        return true;
    }
    if (setupMethodConfiguration(configuration, element, context, sourceElement)) {
        return true;
    }
    return setupClassConfiguration(configuration, element, context, sourceElement);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Location(com.intellij.execution.Location)

Example 4 with TestArtifactSearchScopes

use of com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes in project android by JetBrains.

the class AndroidTestAndJUnitConfigurationConflictsTest method checkClassesInAllInPackage.

private void checkClassesInAllInPackage(TestSearchScope type) throws CantRunException {
    Module module = ModuleManager.getInstance(myFixture.getProject()).findModuleByName("app");
    assertNotNull(module);
    AndroidJUnitConfiguration configuration = createConfiguration(getProject(), "google.simpleapplication", module);
    configuration.getPersistentData().setScope(type);
    AndroidTestPackage testPackage = new AndroidTestPackage(configuration, ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build());
    Set<PsiClass> myClasses = new HashSet<>();
    ConfigurationUtil.findAllTestClasses(testPackage.getClassFilter(configuration.getPersistentData()), null, myClasses);
    assertSize(1, myClasses);
    TestArtifactSearchScopes scopes = TestArtifactSearchScopes.get(module);
    assertNotNull(scopes);
    assertTrue(scopes.isUnitTestSource(myClasses.iterator().next().getContainingFile().getVirtualFile()));
}
Also used : TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) PsiClass(com.intellij.psi.PsiClass) AndroidTestPackage(com.android.tools.idea.testartifacts.junit.AndroidTestPackage) AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration) Module(com.intellij.openapi.module.Module) HashSet(java.util.HashSet)

Example 5 with TestArtifactSearchScopes

use of com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes in project android by JetBrains.

the class AndroidTestPackage method getClassFilter.

@Override
@VisibleForTesting
public TestClassFilter getClassFilter(JUnitConfiguration.Data data) throws CantRunException {
    TestClassFilter classFilter = super.getClassFilter(data);
    JUnitConfiguration configuration = getConfiguration();
    Module[] modules = configuration instanceof AndroidJUnitConfiguration ? ((AndroidJUnitConfiguration) configuration).getModulesToCompile() : configuration.getModules();
    for (Module module : modules) {
        TestArtifactSearchScopes testArtifactSearchScopes = TestArtifactSearchScopes.get(module);
        if (testArtifactSearchScopes != null) {
            classFilter = classFilter.intersectionWith(testArtifactSearchScopes.getAndroidTestExcludeScope());
        }
    }
    return classFilter;
}
Also used : TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) Module(com.intellij.openapi.module.Module) TestClassFilter(com.intellij.execution.junit.TestClassFilter) VisibleForTesting(com.android.annotations.VisibleForTesting)

Aggregations

TestArtifactSearchScopes (com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes)7 Module (com.intellij.openapi.module.Module)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Location (com.intellij.execution.Location)2 JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)2 TestClassFilter (com.intellij.execution.junit.TestClassFilter)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 AndroidJUnitConfiguration (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration)1 AndroidTestPackage (com.android.tools.idea.testartifacts.junit.AndroidTestPackage)1 ModuleRunProfile (com.intellij.execution.configurations.ModuleRunProfile)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 Project (com.intellij.openapi.project.Project)1 PsiClass (com.intellij.psi.PsiClass)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 HashSet (java.util.HashSet)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 NotNull (org.jetbrains.annotations.NotNull)1