• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java LibraryUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.openapi.roots.libraries.LibraryUtil的典型用法代码示例。如果您正苦于以下问题:Java LibraryUtil类的具体用法?Java LibraryUtil怎么用?Java LibraryUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LibraryUtil类属于com.intellij.openapi.roots.libraries包,在下文中一共展示了LibraryUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: 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 = 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:lshain-android-source,项目名称:tools-idea,代码行数:33,代码来源:GantRunner.java


示例17: displayUrlRelativeToProject

import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
public static String displayUrlRelativeToProject(@Nonnull VirtualFile file,
                                                 @Nonnull String url,
                                                 @Nonnull 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 ModuleExtensionWithSdkOrderEntry) {
          url = url + " - [" + ((ModuleExtensionWithSdkOrderEntry)libraryEntry).getSdkName() + "]";
        }
        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:consulo,项目名称:consulo,代码行数:39,代码来源:ProjectUtilCore.java


示例18: isNavigatableLibraryRoot

import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
private boolean isNavigatableLibraryRoot() {
  VirtualFile jarRoot = getArchiveRoot();
  final Project project = getProject();
  if (jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
    final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
    return orderEntry != null ;
  }
  return false;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:10,代码来源:PsiFileNode.java


示例19: navigate

import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
@Override
public void navigate(boolean requestFocus) {
  final VirtualFile jarRoot = getArchiveRoot();
  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:consulo,项目名称:consulo,代码行数:15,代码来源:PsiFileNode.java


示例20: addAnnotationsDependency

import com.intellij.openapi.roots.libraries.LibraryUtil; //导入依赖的package包/类
public static boolean addAnnotationsDependency(@NotNull final Project project, @NotNull final Set<Module> modulesWithoutAnnotations, @NotNull String annoFQN, final String title)
{
	final Library annotationsLib = LibraryUtil.findLibraryByClass(annoFQN, project);
	if(annotationsLib != null)
	{
		String message = "Module" + (modulesWithoutAnnotations.size() == 1 ? " " : "s ");
		message += StringUtil.join(modulesWithoutAnnotations, Module::getName, ", ");
		message += (modulesWithoutAnnotations.size() == 1 ? " doesn't" : " don't");
		message += " refer to the existing '" + annotationsLib.getName() + "' library with Consulo nullity annotations. Would you like to add the dependenc";
		message += (modulesWithoutAnnotations.size() == 1 ? "y" : "ies") + " now?";
		if(Messages.showOkCancelDialog(project, message, title, Messages.getErrorIcon()) == Messages.OK)
		{
			ApplicationManager.getApplication().runWriteAction(() ->
			{
				for(Module module : modulesWithoutAnnotations)
				{
					ModuleRootModificationUtil.addDependency(module, annotationsLib);
				}
			});
			return true;
		}
		return false;
	}

	/*if(Messages.showOkCancelDialog(project, "It is required that JetBrains annotations" + " be available in all your project sources.\n\nYou will need to add annotations.jar as a library. " +
			"It is possible to configure custom JAR\nin e.g. Constant Conditions & Exceptions inspection or use JetBrains annotations available in installation. " + "\nIntelliJ IDEA nullity " +
			"annotations are freely usable and redistributable under the Apache 2.0 license.\nWould you like to do it now?", title, Messages.getErrorIcon()) == Messages.OK)
	{
		Module firstModule = modulesWithoutAnnotations.iterator().next();
		JavaProjectModelModificationService.getInstance(project).addDependency(modulesWithoutAnnotations, JetBrainsAnnotationsExternalLibraryResolver.getAnnotationsLibraryDescriptor(firstModule)
				, DependencyScope.COMPILE);
		return true;
	} */
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:36,代码来源:InferNullityAnnotationsAction.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IOUtils类代码示例发布时间:2022-05-22
下一篇:
Java ViewContext类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap