本文整理汇总了Java中com.intellij.openapi.roots.libraries.LibraryUtil类的典型用法代码示例。如果您正苦于以下问题:Java LibraryUtil类的具体用法?Java LibraryUtil怎么用?Java LibraryUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LibraryUtil类属于com.intellij.openapi.roots.libraries包,在下文中一共展示了LibraryUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: countFiles
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
private void countFiles(Project project) {
final Integer fileCount = project.getUserData(FILE_COUNT);
if (fileCount == null) {
myFileIndex.iterateContent(new ContentIterator() {
public boolean processFile(VirtualFile fileOrDir) {
if (!fileOrDir.isDirectory()) {
counting();
}
return true;
}
});
for (VirtualFile root : LibraryUtil.getLibraryRoots(project)) {
countFilesRecursively(root);
}
project.putUserData(FILE_COUNT, myTotalFileCount);
} else {
myTotalFileCount = fileCount.intValue();
}
}
示例2: navigate
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Override
public void navigate(final boolean requestFocus) {
Module module = ModuleUtil.findModuleForPsiElement(getValue());
if (module != null) {
final VirtualFile file = getVirtualFile();
final Project project = getProject();
ProjectSettingsService service = ProjectSettingsService.getInstance(myProject);
if (ProjectRootsUtil.isModuleContentRoot(file, project)) {
service.openModuleSettings(module);
}
else if (ProjectRootsUtil.isLibraryRoot(file, project)) {
final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, module.getProject());
if (orderEntry != null) {
service.openLibraryOrSdkSettings(orderEntry);
}
}
else {
service.openContentEntriesSettings(module);
}
}
}
示例3: addExternalLibraryDependency
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Override
public Promise<Void> addExternalLibraryDependency(@NotNull final Collection<Module> modules,
@NotNull final ExternalLibraryDescriptor descriptor,
@NotNull final DependencyScope scope) {
List<String> defaultRoots = descriptor.getLibraryClassesRoots();
Module firstModule = ContainerUtil.getFirstItem(modules);
LOG.assertTrue(firstModule != null);
LocateLibraryDialog dialog = new LocateLibraryDialog(firstModule, defaultRoots, descriptor.getPresentableName());
List<String> classesRoots = dialog.showAndGetResult();
if (!classesRoots.isEmpty()) {
String libraryName = classesRoots.size() > 1 ? descriptor.getPresentableName() : null;
final List<String> urls = OrderEntryFix.refreshAndConvertToUrls(classesRoots);
if (modules.size() == 1) {
ModuleRootModificationUtil.addModuleLibrary(firstModule, libraryName, urls, Collections.<String>emptyList(), scope);
}
else {
new WriteAction() {
protected void run(@NotNull Result result) {
Library library =
LibraryUtil.createLibrary(LibraryTablesRegistrar.getInstance().getLibraryTable(myProject), descriptor.getPresentableName());
Library.ModifiableModel model = library.getModifiableModel();
for (String url : urls) {
model.addRoot(url, OrderRootType.CLASSES);
}
model.commit();
for (Module module : modules) {
ModuleRootModificationUtil.addDependency(module, library, scope, false);
}
}
}.execute();
}
}
return Promise.DONE;
}
示例4: build
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
public TreeModel build(final Project project) {
Runnable buildingRunnable = new Runnable() {
public void run() {
countFiles(project);
myFileIndex.iterateContent(new ContentIterator() {
PackageDependenciesNode lastParent = null;
VirtualFile dir = null;
public boolean processFile(VirtualFile fileOrDir) {
if (!fileOrDir.isDirectory()) {
if (lastParent != null && !Comparing.equal(dir, fileOrDir.getParent())) {
lastParent = null;
}
lastParent = buildFileNode(fileOrDir, lastParent);
dir = fileOrDir.getParent();
} else {
lastParent = null;
}
return true;
}
});
for (VirtualFile root : LibraryUtil.getLibraryRoots(project)) {
processFilesRecursively(root);
}
}
};
buildingRunnable.run();
return new TreeModel(myRoot, myTotalFileCount, myMarkedFileCount);
}
示例5: checkLibraries
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Nullable
public RequiredClassesNotFoundInfo checkLibraries(List<VirtualFile> libraryFiles) {
List<LibraryInfo> infos = new ArrayList<LibraryInfo>();
List<String> classes = new ArrayList<String>();
for (LibraryInfo info : myLibraryInfos) {
boolean notFound;
final String md5 = info.getMd5();
if (!StringUtil.isEmptyOrSpaces(md5)) {
notFound = true;
for (VirtualFile libraryFile : libraryFiles) {
final VirtualFile jarFile = JarFileSystem.getInstance().getVirtualFileForJar(libraryFile);
if (md5.equals(md5(jarFile))) {
notFound = false;
break;
}
}
} else {
notFound = false;
for (String className : info.getRequiredClasses()) {
if (!LibraryUtil.isClassAvailableInLibrary(libraryFiles, className)) {
classes.add(className);
notFound = true;
}
}
}
if (notFound) {
infos.add(info);
}
}
if (infos.isEmpty()) {
return null;
}
return new RequiredClassesNotFoundInfo(ArrayUtil.toStringArray(classes), infos.toArray(new LibraryInfo[infos.size()]));
}
示例6: displayUrlRelativeToProject
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
public static String displayUrlRelativeToProject(@NotNull VirtualFile file,
@NotNull String url,
@NotNull Project project,
boolean includeFilePath,
boolean keepModuleAlwaysOnTheLeft) {
final VirtualFile baseDir = project.getBaseDir();
if (baseDir != null && includeFilePath) {
//noinspection ConstantConditions
final String projectHomeUrl = baseDir.getPresentableUrl();
if (url.startsWith(projectHomeUrl)) {
url = "..." + url.substring(projectHomeUrl.length());
}
}
if (SystemInfo.isMac && file.getFileSystem() instanceof LocalFileProvider) {
final VirtualFile fileForJar = ((LocalFileProvider)file.getFileSystem()).getLocalVirtualFileFor(file);
if (fileForJar != null) {
final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
if (libraryEntry != null) {
if (libraryEntry instanceof JdkOrderEntry) {
url = url + " - [" + ((JdkOrderEntry)libraryEntry).getJdkName() + "]";
}
else {
url = url + " - [" + libraryEntry.getPresentableName() + "]";
}
}
else {
url = url + " - [" + fileForJar.getName() + "]";
}
}
}
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module == null) return url;
return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ?
url + " - [" + module.getName() + "]" :
"[" + module.getName() + "] - " + url;
}
示例7: isNavigatableLibraryRoot
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
private boolean isNavigatableLibraryRoot() {
VirtualFile jarRoot = getJarRoot();
final Project project = getProject();
if (jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
return orderEntry != null && ProjectSettingsService.getInstance(project).canOpenLibraryOrSdkSettings(orderEntry);
}
return false;
}
示例8: navigate
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Override
public void navigate(boolean requestFocus) {
final VirtualFile jarRoot = getJarRoot();
final Project project = getProject();
if (requestFocus && jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
if (orderEntry != null) {
ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry);
return;
}
}
super.navigate(requestFocus);
}
示例9: getDefaultDependencyScope
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Nullable
@Override
public DependencyScope getDefaultDependencyScope(@NotNull Library library) {
VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
if (files.length == 1 && LibraryUtil.isClassAvailableInLibrary(files, "org.testng.annotations.Test")) {
return DependencyScope.TEST;
}
return null;
}
示例10: isTestJarRoot
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
private static boolean isTestJarRoot(VirtualFile file) {
for (String marker : JUNIT_JAR_MARKERS) {
if (LibraryUtil.isClassAvailableInLibrary(Collections.singletonList(file), marker)) {
return true;
}
}
return false;
}
示例11: addGroovyAndAntJars
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
private static void addGroovyAndAntJars(JavaParameters params, Module module, String gantHome) {
final File[] groovyJars = GroovyConfigUtils.getGroovyAllJars(gantHome + "/lib/");
if (groovyJars.length > 0) {
params.getClassPath().add(groovyJars[0].getAbsolutePath());
}
if (module == null) {
return;
}
final String groovyHome = LibrariesUtil.getGroovyHomePath(module);
if (groovyHome != null) {
File[] libJars = GroovyUtils.getFilesInDirectoryByPattern(groovyHome + "/lib/", ".*\\.jar");
if (libJars.length > 0) {
params.getClassPath().addAllFiles(libJars);
}
}
List<VirtualFile> classpath = params.getClassPath().getRootDirs();
String[] characteristicClasses = ContainerUtil.ar(
LibrariesUtil.SOME_GROOVY_CLASS, "org.apache.tools.ant.BuildException", "org.apache.tools.ant.launch.AntMain",
"org.apache.commons.cli.ParseException");
for (String someClass : characteristicClasses) {
if (!LibraryUtil.isClassAvailableInLibrary(classpath, someClass)) {
VirtualFile jar = LibrariesUtil.findJarWithClass(module, someClass);
if (jar != null) {
params.getClassPath().add(jar);
}
}
}
}
示例12: findLibrary
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Nullable
private Library findLibrary(Project project, PsiJavaFile clsFile) {
OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(clsFile.getVirtualFile(), project);
if (!(libraryEntry instanceof LibraryOrderEntry)) {
return null;
}
return ((LibraryOrderEntry) libraryEntry).getLibrary();
}
示例13: detectVersion
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Nullable
private static LibraryVersionProperties detectVersion(List<VirtualFile> classesRoots, String detectionClass) {
if (!LibraryUtil.isClassAvailableInLibrary(classesRoots, detectionClass)) {
return null;
}
final String version = JarVersionDetectionUtil.detectJarVersion(detectionClass, classesRoots);
return new LibraryVersionProperties(version);
}
示例14: removeAsmJarFromClasspath
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
private static void removeAsmJarFromClasspath(PathsList classPath) {
List<String> toRemove = new ArrayList<String>();
for (String filePath : classPath.getPathList()) {
if (filePath.endsWith(".jar")) {
final VirtualFile root =
JarFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(filePath) + JarFileSystem.JAR_SEPARATOR);
if (root != null && LibraryUtil.isClassAvailableInLibrary(new VirtualFile[]{root}, "org.objectweb.asm.ClassReader")) {
toRemove.add(filePath);
}
}
}
for (String path : toRemove) {
classPath.remove(path);
}
}
示例15: getDefaultDependencyScope
import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Nullable
@Override
public DependencyScope getDefaultDependencyScope(@NotNull Library library) {
VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
if (files.length == 1 && (LibraryUtil.isClassAvailableInLibrary(files, "junit.framework.TestCase")
|| LibraryUtil.isClassAvailableInLibrary(library, "org.junit.Test"))) {
return DependencyScope.TEST;
}
return null;
}