tests: check for jar availability in the classpath when package is selected

This commit is contained in:
anna
2012-02-20 10:40:05 +01:00
parent 329c041758
commit ebb5594010
3 changed files with 56 additions and 40 deletions
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.info;
import com.intellij.execution.Location;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
/**
* User: anna
* Date: 2/20/12
*/
public class LocationUtil {
public static boolean isJarAttached(@NotNull Location location, final PsiPackage aPackage, final String fqn) {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(location.getProject());
boolean testngJarFound = false;
final Module locationModule = location.getModule();
if (locationModule != null) {
testngJarFound = facade.findClass(fqn, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(locationModule, true)) != null;
}
else {
for (PsiDirectory directory : aPackage.getDirectories()) {
final Module module = ModuleUtil.findModuleForFile(directory.getVirtualFile(), location.getProject());
if (module != null) {
if (facade.findClass(fqn, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, true)) != null) {
testngJarFound = true;
break;
}
}
}
}
return testngJarFound;
}
}