Java Code Examples for com.intellij.openapi.roots.libraries.Library#getTable()

The following examples show how to use com.intellij.openapi.roots.libraries.Library#getTable() . 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: PackagingElementFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends PackagingElement<?>> createLibraryElements(@Nonnull Library library) {
  final LibraryTable table = library.getTable();
  final String libraryName = library.getName();
  if (table != null) {
    return Collections.singletonList(createLibraryFiles(libraryName, table.getTableLevel(), null));
  }
  if (libraryName != null) {
    final Module module = ((LibraryImpl)library).getModule();
    if (module != null) {
      return Collections.singletonList(createLibraryFiles(libraryName, LibraryTableImplUtil.MODULE_LEVEL, module.getName()));
    }
  }
  final List<PackagingElement<?>> elements = new ArrayList<>();
  for (VirtualFile file : library.getFiles(BinariesOrderRootType.getInstance())) {
    final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file));
    elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
  }
  return elements;
}
 
Example 2
Source File: ArtifactEditorContextImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void selectLibrary(@Nonnull Library library) {
  final LibraryTable table = library.getTable();
  if (table != null) {
    ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
  }
  else {
    final Module module = ((LibraryImpl)library).getModule();
    if (module != null) {
      final ModuleRootModel rootModel = myParent.getModulesProvider().getRootModel(module);
      final String libraryName = library.getName();
      for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (entry instanceof ModuleLibraryOrderEntryImpl) {
          final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl)entry;
          if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName())
             || libraryName == null && library.equals(libraryEntry.getLibrary())) {
            ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry);
            return;
          }
        }
      }
    }
  }
}
 
Example 3
Source File: OrderEntryUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean equals(Library library1, Library library2) {
  if (library1 == library2) return true;
  if (library1 == null || library2 == null) return false;

  final LibraryTable table = library1.getTable();
  if (table != null) {
    if (library2.getTable() != table) return false;
    final String name = library1.getName();
    return name != null && name.equals(library2.getName());
  }

  if (library2.getTable() != null) return false;

  for (OrderRootType type : OrderRootType.getAllTypes()) {
    if (!Comparing.equal(library1.getUrls(type), library2.getUrls(type))) {
      return false;
    }
  }
  return true;
}
 
Example 4
Source File: OrderEntryUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void addLibraryToRoots(@Nonnull Module module, @Nonnull Library library) {
  final ModuleRootManager manager = ModuleRootManager.getInstance(module);
  final ModifiableRootModel rootModel = manager.getModifiableModel();

  if (library.getTable() == null) {
    final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
    final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
    for (OrderRootType orderRootType : OrderRootType.getAllTypes()) {
      VirtualFile[] files = library.getFiles(orderRootType);
      for (VirtualFile jarFile : files) {
        libraryModel.addRoot(jarFile, orderRootType);
      }
    }
    libraryModel.commit();
  }
  else {
    rootModel.addLibraryEntry(library);
  }
  rootModel.commit();
}
 
Example 5
Source File: QuarkusLanguageClient.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void handleLibraryUpdate(Library library) {
  if (library.getTable() instanceof LibraryTableBase) {
    long modif = ((LibraryTableBase)library.getTable()).getStateModificationCount();
    if (modif > lastModification) {
      sendPropertiesChangeEvent(MicroProfilePropertiesScope.dependencies, QuarkusModuleUtil.getModulesURIs(getProject()));
      lastModification = modif;
    }
  }
}
 
Example 6
Source File: LibraryElementPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String getLibraryTableComment(final Library library) {
  LibraryTable libraryTable = library.getTable();
  String displayName;
  if (libraryTable != null) {
    displayName = libraryTable.getPresentation().getDisplayName(false);
  }
  else {
    Module module = ((LibraryImpl)library).getModule();
    String tableName = getLibraryTableDisplayName(library);
    displayName = module != null ? "'" + module.getName() + "' " + tableName : tableName;
  }
  return " (" + displayName + ")";
}
 
Example 7
Source File: ProjectStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> select(@Nonnull LibraryOrderEntry libraryOrderEntry, final boolean requestFocus) {
  final Library lib = libraryOrderEntry.getLibrary();
  if (lib == null || lib.getTable() == null) {
    return selectOrderEntry(libraryOrderEntry.getOwnerModule(), libraryOrderEntry);
  }
  Place place = createPlaceFor(getConfigurableFor(lib));
  place.putPath(BaseStructureConfigurable.TREE_NAME, libraryOrderEntry.getLibraryName());
  return navigateTo(place, requestFocus);
}
 
Example 8
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ExistingLibraryEditor getLibraryEditor(@Nonnull Library library) {
  final LibraryTable table = library.getTable();
  if (table == null) return null;

  final LibraryTable.ModifiableModel model = myContext.getModifiableLibraryTable(table);
  if (model instanceof LibrariesModifiableModel) {
    return ((LibrariesModifiableModel)model).getLibraryEditor(library);
  }
  return null;
}
 
Example 9
Source File: StructureConfigurableContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
public VirtualFile[] getLibraryFiles(Library library, final OrderRootType type) {
  final LibraryTable table = library.getTable();
  if (table != null) {
    final LibraryTable.ModifiableModel modifiableModel = getModifiableLibraryTable(table);
    if (modifiableModel instanceof LibrariesModifiableModel) {
      final LibrariesModifiableModel librariesModel = (LibrariesModifiableModel)modifiableModel;
      if (librariesModel.hasLibraryEditor(library)) {
        return librariesModel.getLibraryEditor(library).getFiles(type);
      }
    }
  }
  return library.getFiles(type);
}
 
Example 10
Source File: StructureConfigurableContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public Library getLibraryModel(@Nonnull Library library) {
  final LibraryTable libraryTable = library.getTable();
  if (libraryTable != null) {
    return findLibraryModel(library, myLevel2Providers.get(libraryTable.getTableLevel()));
  }
  return library;
}
 
Example 11
Source File: BaseLibrariesConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void createLibraryNode(Library library) {
  final LibraryTable table = library.getTable();
  if (table != null) {
    final String level = table.getTableLevel();
    final LibraryConfigurable configurable =
      new LibraryConfigurable(myContext.createModifiableModelProvider(level), library, myContext, TREE_UPDATER);
    final MyNode node = new MyNode(configurable);
    addNode(node, myRoot);
    final ProjectStructureDaemonAnalyzer daemonAnalyzer = myContext.getDaemonAnalyzer();
    daemonAnalyzer.queueUpdate(new LibraryProjectStructureElement(myContext, library));
    daemonAnalyzer.queueUpdateForAllElementsWithErrors();
  }
}
 
Example 12
Source File: ArtifactsStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isResolvedToLibrary(LibraryPackagingElement element, Library library, String name) {
  if (!element.getLibraryName().equals(name)) {
    return false;
  }

  final LibraryTable table = library.getTable();
  if (table != null) {
    return table.getTableLevel().equals(element.getLevel());
  }
  return element.getLevel().equals(LibraryTableImplUtil.MODULE_LEVEL);
}
 
Example 13
Source File: LibraryClasspathTableItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void doEdit(ClasspathPanelImpl panel) {
  final Library library = getEntry().getLibrary();
  if (library == null) {
    return;
  }
  final LibraryTable table = library.getTable();
  final String tableLevel = table != null ? table.getTableLevel() : LibraryTableImplUtil.MODULE_LEVEL;
  final LibraryTablePresentation presentation = LibraryEditingUtil.getLibraryTablePresentation(myContext.getProject(), tableLevel);
  final LibraryTableModifiableModelProvider provider = panel.getModifiableModelProvider(tableLevel);
  EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(panel, provider, library, myContext.getProject(), presentation, myContext);
  dialog.setContextModule(getEntry().getOwnerModule());
  dialog.show();
}
 
Example 14
Source File: LibraryElementPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static String getLibraryTableDisplayName(final Library library) {
  LibraryTable table = library.getTable();
  LibraryTablePresentation presentation = table != null ? table.getPresentation() : ModuleLibraryTable.MODULE_LIBRARY_TABLE_PRESENTATION;
  return presentation.getDisplayName(false);
}