Java Code Examples for com.intellij.openapi.roots.libraries.LibraryTable#getLibraries()

The following examples show how to use com.intellij.openapi.roots.libraries.LibraryTable#getLibraries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaxelibClasspathUtils.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
/**
 * Loads a classpath from the given library table.  Workhorse for other APIs
 * in this class.
 *
 * @param libraryTable to load
 * @return the classpath
 */
@NotNull
private static HaxeClasspath loadClasspathFrom(LibraryTable libraryTable) {
  HaxeClasspath classpath = new HaxeClasspath();
  Library[] libraries = libraryTable.getLibraries();
  OrderRootType interestingRootTypes[] = {OrderRootType.SOURCES, OrderRootType.CLASSES};
  for (Library library : libraries) {
    for (OrderRootType rootType : interestingRootTypes) {
      for (String url : library.getUrls(rootType)) {
        if (!classpath.containsUrl(url)) {
          classpath.add(new HaxeClasspathEntry(library.getName(), url));
        }
      }
    }
  }
  return classpath;
}
 
Example 2
Source File: HaxelibUtil.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
/**
 * Get the list of libraries specified on the project.  Managed haxelib
 * (of the form "haxelib|<lib_name>") libraries are included unless
 * filterManagedLibs is true.
 *
 *
 * @param project to get the classpath for.
 * @return a (possibly empty) list of the classpaths for all of the libraries
 *         that are specified on the project (in the library pane).
 */
@NotNull
public static HaxeLibraryList getProjectLibraries(@NotNull Project project, boolean filterManagedLibs, boolean filterUnmanagedLibs) {
  LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
  if (null == libraryTable || (filterManagedLibs && filterUnmanagedLibs)) {
    return new HaxeLibraryList(HaxelibSdkUtils.lookupSdk(project));
  }

  HaxeLibraryList libs = new HaxeLibraryList(HaxelibSdkUtils.lookupSdk(project));
  Library[] libraries = libraryTable.getLibraries();
  for (Library library : libraries) {
    String name = library.getName();
    if (name == null) continue;

    boolean isManaged = HaxelibNameUtil.isManagedLibrary(name);
    if (filterManagedLibs && isManaged) continue;
    if (filterUnmanagedLibs && !isManaged) continue;

    libs.add(HaxeLibraryReference.create(project, name));
  }
  return libs;
}
 
Example 3
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addAndroidLibraryDependencies(@NotNull Project androidProject,
                                           @NotNull Module androidModule,
                                           @NotNull Module flutterModule) {
  AndroidSdkUtils.setupAndroidPlatformIfNecessary(androidModule, true);
  Sdk currentSdk = ModuleRootManager.getInstance(androidModule).getSdk();
  if (currentSdk != null) {
    // TODO(messick) Add sdk dependency on currentSdk if not already set
  }
  LibraryTable androidProjectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(androidProject);
  Library[] androidProjectLibraries = androidProjectLibraryTable.getLibraries();
  LibraryTable flutterProjectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(getProject());
  Library[] flutterProjectLibraries = flutterProjectLibraryTable.getLibraries();
  Set<String> knownLibraryNames = new HashSet<>(flutterProjectLibraries.length);
  for (Library lib : flutterProjectLibraries) {
    if (lib.getName() != null) {
      knownLibraryNames.add(lib.getName());
    }
  }
  for (Library library : androidProjectLibraries) {
    if (library.getName() != null && !knownLibraryNames.contains(library.getName())) {

      List<String> roots = Arrays.asList(library.getRootProvider().getUrls(OrderRootType.CLASSES));
      Set<String> filteredRoots = roots.stream().filter(s -> shouldIncludeRoot(s)).collect(Collectors.toSet());
      if (filteredRoots.isEmpty()) continue;

      HashSet<String> sources = new HashSet<>(Arrays.asList(library.getRootProvider().getUrls(OrderRootType.SOURCES)));

      updateLibraryContent(library.getName(), filteredRoots, sources);
      updateAndroidModuleLibraryDependencies(flutterModule);
    }
  }
}
 
Example 4
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addAndroidLibraryDependencies(@NotNull Project androidProject,
                                           @NotNull Module androidModule,
                                           @NotNull Module flutterModule) {
  AndroidSdkUtils.setupAndroidPlatformIfNecessary(androidModule, true);
  Sdk currentSdk = ModuleRootManager.getInstance(androidModule).getSdk();
  if (currentSdk != null) {
    // TODO(messick) Add sdk dependency on currentSdk if not already set
  }
  LibraryTable androidProjectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(androidProject);
  Library[] androidProjectLibraries = androidProjectLibraryTable.getLibraries();
  LibraryTable flutterProjectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(getProject());
  Library[] flutterProjectLibraries = flutterProjectLibraryTable.getLibraries();
  Set<String> knownLibraryNames = new HashSet<>(flutterProjectLibraries.length);
  for (Library lib : flutterProjectLibraries) {
    if (lib.getName() != null) {
      knownLibraryNames.add(lib.getName());
    }
  }
  for (Library library : androidProjectLibraries) {
    if (library.getName() != null && !knownLibraryNames.contains(library.getName())) {

      List<String> roots = Arrays.asList(library.getRootProvider().getUrls(OrderRootType.CLASSES));
      Set<String> filteredRoots = roots.stream().filter(s -> shouldIncludeRoot(s)).collect(Collectors.toSet());
      if (filteredRoots.isEmpty()) continue;

      HashSet<String> sources = new HashSet<>(Arrays.asList(library.getRootProvider().getUrls(OrderRootType.SOURCES)));

      updateLibraryContent(library.getName(), filteredRoots, sources);
      updateAndroidModuleLibraryDependencies(flutterModule);
    }
  }
}
 
Example 5
Source File: FlutterSdk.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static Library getDartSdkLibrary(@NotNull Project project) {
  final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project);
  for (Library lib : libraryTable.getLibraries()) {
    if ("Dart SDK".equals(lib.getName())) {
      return lib;
    }
  }
  return null;
}
 
Example 6
Source File: FlutterSdk.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static Library getDartSdkLibrary(@NotNull Project project) {
  final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project);
  for (Library lib : libraryTable.getLibraries()) {
    if ("Dart SDK".equals(lib.getName())) {
      return lib;
    }
  }
  return null;
}
 
Example 7
Source File: HaxelibClasspathUtils.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the libraries specified for the IDEA project; source paths and
 * class paths for project libraries excepting those named "haxelib|<lib_name>".
 *
 * @param project a project to get the class path settings for.
 * @return a list of class path URLs.
 */
@NotNull
public static HaxeClasspath getUnmanagedProjectLibraryClasspath(@NotNull Project project) {
  LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
  if (null == libraryTable) return HaxeClasspath.EMPTY_CLASSPATH;

  HaxeClasspath classpath = new HaxeClasspath();

  Library[] libraries = libraryTable.getLibraries();
  for (Library library : libraries) {
    //
    // This is checking that the library name doesn't match "haxelib|lib_name".
    // That is, if it /is/ a haxelib entry, ignore it; grab the classpaths for
    // libs that aren't haxelibs.
    //
    if (!HaxelibNameUtil.isManagedLibrary(library.getName())) {
      OrderRootType interestingRootTypes[] = {OrderRootType.SOURCES, OrderRootType.CLASSES};
      for (OrderRootType rootType : interestingRootTypes) {
        for (String url : library.getUrls(rootType)) {
          if (!classpath.containsUrl(url)) {  // The if just keeps us from churning.
            classpath.add(new HaxeClasspathEntry(library.getName(), url));
          }
        }
      }
    }
  }
  return classpath;
}
 
Example 8
Source File: HaxelibClasspathUtils.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
/**
 * Get the list of library names specified on the project.  Managed haxelib
 * (of the form "haxelib|<lib_name>") libraries are included unless
 * filterManagedLibs is true.
 *
 * @param project to get the libraries for.
 * @param filterManagedLibs whether to remove managed haxelibs from the list.
 * @return a (possibly empty) list of libraries that are specified for the
 *         project (in the library pane).
 */
@NotNull
public static List<String> getProjectLibraryNames(@NotNull Project project, boolean filterManagedLibs) {
  List<String> nameList = new ArrayList<String>();
  LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
  Library[] libraries = libraryTable.getLibraries();
  for (Library library : libraries) {
    if (filterManagedLibs && HaxelibNameUtil.isManagedLibrary(library.getName())) {
      continue;
    }
    nameList.add(library.getName());
  }
  return nameList;
}
 
Example 9
Source File: ProjectStructureHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Library findIdeLibrary(@Nonnull final LibraryData libraryData, @Nonnull Project ideProject) {
  final LibraryTable libraryTable = ProjectLibraryTable.getInstance(ideProject);
  for (Library ideLibrary : libraryTable.getLibraries()) {
    if (ExternalSystemApiUtil.isRelated(ideLibrary, libraryData)) return ideLibrary;
  }
  return null;
}
 
Example 10
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void processOrphanProjectLibraries() {
  List<Library> orphanIdeLibraries = ContainerUtilRt.newArrayList();

  LibraryTable projectLibraryTable = ProjectLibraryTable.getInstance(myProject);
  for (Library library : projectLibraryTable.getLibraries()) {
    if (!ExternalSystemApiUtil.isExternalSystemLibrary(library, myExternalSystemId)) continue;
    if (ProjectStructureHelper.isOrphanProjectLibrary(library, ModuleManager.getInstance(myProject).getModules())) {
      orphanIdeLibraries.add(library);
    }
  }
  for (Library orphanIdeLibrary : orphanIdeLibraries) {
    projectLibraryTable.removeLibrary(orphanIdeLibrary);
  }
}
 
Example 11
Source File: ChooseLibrariesFromTablesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected Library[] getLibraries(@Nonnull LibraryTable table) {
  return table.getLibraries();
}