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

The following examples show how to use com.intellij.openapi.roots.libraries.LibraryTable#getLibraryByName() . 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: ProtostuffPluginController.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private Library findGlobalProtobufLibrary(Project project, VirtualFile libraryBundle) {
    LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project);
    Library library = libraryTable.getLibraryByName(LIB_NAME);
    if (library != null) {
        // check library - update if needed
        if (Arrays.stream(library.getFiles(ORDER_ROOT_TYPE))
                .anyMatch(file -> file.getName().equals(libraryBundle.getName()))) {
            return library;
        }
    }
    return null;
}
 
Example 2
Source File: LibraryEditor.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void updateLibraryDependency(ModifiableRootModel model, LibraryKey libraryKey) {
  LibraryTable libraryTable = ProjectLibraryTable.getInstance(model.getProject());
  Library library = libraryTable.getLibraryByName(libraryKey.getIntelliJLibraryName());
  if (library == null) {
    logger.error(
        "Library missing: "
            + libraryKey.getIntelliJLibraryName()
            + ". Please resync project to resolve.");
    return;
  }
  model.addLibraryEntry(library);
}
 
Example 3
Source File: LibraryActionHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
static Library findLibraryForAction(AnActionEvent e) {
  Project project = e.getProject();
  if (project != null) {
    NamedLibraryElementNode node = findLibraryNode(e.getDataContext());
    if (node != null) {
      String libraryName = node.getName();
      if (StringUtil.isNotEmpty(libraryName)) {
        LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
        return libraryTable.getLibraryByName(libraryName);
      }
    }
  }
  return null;
}
 
Example 4
Source File: PantsCodeInsightFixtureTestCase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
  final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myFixture.getProject());
  final Library libraryByName = libraryTable.getLibraryByName(PantsConstants.PANTS_LIBRARY_NAME);
  if (libraryByName != null) {
    ApplicationManager.getApplication().runWriteAction(() -> libraryTable.removeLibrary(libraryByName));
  }
  super.tearDown();
}
 
Example 5
Source File: LibraryOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void searchForLibrary(@Nonnull String name, @Nonnull String level) {
  if (myLibrary != null) return;
  final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, getRootModel().getModule().getProject());
  final Library library = libraryTable != null ? libraryTable.getLibraryByName(name) : null;
  if (library == null) {
    myLibraryName = name;
    myLibraryLevel = level;
    myLibrary = null;
  }
  else {
    myLibraryName = null;
    myLibraryLevel = null;
    myLibrary = library;
  }
}
 
Example 6
Source File: LibraryDependencyDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void importMissingProjectLibraries(@Nonnull Module module, @Nonnull Collection<DataNode<LibraryDependencyData>> nodesToImport, boolean synchronous) {
  LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
  List<DataNode<LibraryData>> librariesToImport = ContainerUtilRt.newArrayList();
  for (DataNode<LibraryDependencyData> dataNode : nodesToImport) {
    final LibraryDependencyData dependencyData = dataNode.getData();
    if (dependencyData.getLevel() != LibraryLevel.PROJECT) {
      continue;
    }
    final Library library = libraryTable.getLibraryByName(dependencyData.getInternalName());
    if (library == null) {
      DataNode<ProjectData> projectNode = dataNode.getDataNode(ProjectKeys.PROJECT);
      if (projectNode != null) {
        DataNode<LibraryData> libraryNode = ExternalSystemApiUtil.find(projectNode, ProjectKeys.LIBRARY, new BooleanFunction<DataNode<LibraryData>>() {
          @Override
          public boolean fun(DataNode<LibraryData> node) {
            return node.getData().equals(dependencyData.getTarget());
          }
        });
        if (libraryNode != null) {
          librariesToImport.add(libraryNode);
        }
      }
    }
  }
  if (!librariesToImport.isEmpty()) {
    LibraryDataService.getInstance().importData(librariesToImport, module.getProject(), synchronous);
  }
}
 
Example 7
Source File: CMakeWorkspaceOverride.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static boolean areLibrariesAndRootsModifiedByCMake(ModifiableRootModel modifiableModel) {
  LibraryTable table = modifiableModel.getModuleLibraryTable();
  return table.getLibraryByName("Header Search Paths") != null;
}
 
Example 8
Source File: GaugeLibHelper.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
private void updateGaugeJavaLibIfNeeded(ModifiableRootModel model) {
    LibraryTable libraryTable = model.getModuleLibraryTable();
    Library library = libraryTable.getLibraryByName(GAUGE_LIB);
    ProjectLib latestGaugeLib = gaugeLib(model.getModule());
    updateLibrary(library, latestGaugeLib);
}
 
Example 9
Source File: DefaultPackagingElementResolvingContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public static Library findLibrary(Project project, String level, String libraryName) {
  LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, project);
  return table != null ? table.getLibraryByName(libraryName) : null;
}