当前位置: 首页>>代码示例>>Java>>正文


Java LibraryUtil类代码示例

本文整理汇总了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();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:TreeModelBuilder.java

示例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);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:PsiDirectoryNode.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:IdeaProjectModelModifier.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:TreeModelBuilder.java

示例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()]));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:RequiredLibrariesInfo.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:ProjectUtilCore.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PsiFileNode.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:PsiFileNode.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:TestNGDependencyScopeSuggester.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:JUnitDependencyScopeSuggester.java

示例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);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:GantRunner.java

示例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();
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:9,代码来源:BlazeSourceJarNavigationPolicy.java

示例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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:9,代码来源:DownloadableLibraryTypeBase.java

示例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);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:EnhancerCompilerInstance.java

示例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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:JUnitDependencyScopeSuggester.java


注:本文中的com.intellij.openapi.roots.libraries.LibraryUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。