Search in sources :

Example 6 with TestArtifactSearchScopes

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

the class AndroidTestConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(AndroidTestRunConfiguration configuration, ConfigurationContext context) {
    Location location = context.getLocation();
    Module contextModule = AndroidUtils.getAndroidModule(context);
    if (contextModule == null || location == null) {
        return false;
    }
    location = JavaExecutionUtil.stepIntoSingleClass(location);
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    VirtualFile directoryOrFile = element instanceof PsiDirectory ? ((PsiDirectory) element).getVirtualFile() : element.getContainingFile().getVirtualFile();
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(contextModule);
    if (directoryOrFile != null && testScopes != null && !testScopes.isAndroidTestSource(directoryOrFile)) {
        return false;
    }
    PsiPackage psiPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
    String packageName = psiPackage == null ? null : psiPackage.getQualifiedName();
    PsiClass elementClass = getParentOfType(element, PsiClass.class, false);
    String className = elementClass == null ? null : elementClass.getQualifiedName();
    PsiMethod elementMethod = getParentOfType(element, PsiMethod.class, false);
    String methodName = elementMethod == null ? null : elementMethod.getName();
    Module moduleInConfig = configuration.getConfigurationModule().getModule();
    if (!Comparing.equal(contextModule, moduleInConfig)) {
        return false;
    }
    switch(configuration.TESTING_TYPE) {
        case AndroidTestRunConfiguration.TEST_ALL_IN_MODULE:
            return psiPackage != null && packageName.isEmpty();
        case AndroidTestRunConfiguration.TEST_ALL_IN_PACKAGE:
            return packageName != null && packageName.equals(configuration.PACKAGE_NAME);
        case AndroidTestRunConfiguration.TEST_CLASS:
            return elementMethod == null && className != null && className.equals(configuration.CLASS_NAME);
        case AndroidTestRunConfiguration.TEST_METHOD:
            return methodName != null && methodName.equals(configuration.METHOD_NAME) && className != null && className.equals(configuration.CLASS_NAME);
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Example 7 with TestArtifactSearchScopes

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

the class AndroidTestConsoleProperties method initScope.

@NotNull
@Override
protected GlobalSearchScope initScope() {
    GlobalSearchScope scope = super.initScope();
    Module[] modules = ((ModuleRunProfile) getConfiguration()).getModules();
    for (Module each : modules) {
        // UnitTest scope in each module is excluded from the scope used to find JUnitTests
        TestArtifactSearchScopes testArtifactSearchScopes = TestArtifactSearchScopes.get(each);
        if (testArtifactSearchScopes != null) {
            scope = scope.intersectWith(GlobalSearchScope.notScope(testArtifactSearchScopes.getUnitTestSourceScope()));
        }
    }
    return scope;
}
Also used : ModuleRunProfile(com.intellij.execution.configurations.ModuleRunProfile) TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

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