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);
}
}
}
}
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;
}
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);
}
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()));
}
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;
}
Aggregations