Search in sources :

Example 6 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project android by JetBrains.

the class AndroidModuleDependenciesSetupTest method testSetUpLibraryWithNewLibrary.

public void testSetUpLibraryWithNewLibrary() throws IOException {
    File binaryPath = createTempFile("fakeLibrary", "jar");
    File sourcePath = createTempFile("fakeLibrary-src", "jar");
    when(myLibraryFilePaths.findSourceJarPath(binaryPath)).thenReturn(sourcePath);
    String libraryName = binaryPath.getName();
    Module module = getModule();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    File[] binaryPaths = { binaryPath };
    myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, libraryName, COMPILE, binaryPath, binaryPaths, EMPTY_FILE_ARRAY);
    // Apply changes before checking state.
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    List<LibraryOrderEntry> libraryOrderEntries = getLibraryOrderEntries(module);
    // Only one library should be in the library table.
    assertThat(libraryOrderEntries).hasSize(1);
    Library library = libraryOrderEntries.get(0).getLibrary();
    assertNotNull(library);
    assertEquals(libraryName, library.getName());
    String[] binaryUrls = library.getUrls(CLASSES);
    assertThat(binaryUrls).hasLength(1);
    assertEquals(pathToIdeaUrl(binaryPath), binaryUrls[0]);
    String[] sourceUrls = library.getUrls(SOURCES);
    assertThat(sourceUrls).hasLength(1);
    assertEquals(pathToIdeaUrl(sourcePath), sourceUrls[0]);
    // Should not mark new libraries as "used"
    verify(myLibraryRegistry, never()).markAsUsed(library, binaryPaths);
    verify(myLibraryFilePaths).findSourceJarPath(binaryPath);
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) File(java.io.File)

Example 7 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project android by JetBrains.

the class AndroidModuleDependenciesSetupTest method getLibraryOrderEntries.

@NotNull
private static List<LibraryOrderEntry> getLibraryOrderEntries(@NotNull Module module) {
    List<LibraryOrderEntry> libraryOrderEntries = new ArrayList<>();
    OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
    for (OrderEntry orderEntry : orderEntries) {
        if (orderEntry instanceof LibraryOrderEntry) {
            libraryOrderEntries.add((LibraryOrderEntry) orderEntry);
        }
    }
    return libraryOrderEntries;
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ArrayList(java.util.ArrayList) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.

the class LibraryEditingUtil method getNotAddedSuitableLibrariesCondition.

public static Predicate<Library> getNotAddedSuitableLibrariesCondition(final ModuleRootModel rootModel, final FacetsProvider facetsProvider) {
    final OrderEntry[] orderEntries = rootModel.getOrderEntries();
    final Set<Library> result = new HashSet<>(orderEntries.length);
    for (OrderEntry orderEntry : orderEntries) {
        if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
            final LibraryImpl library = (LibraryImpl) ((LibraryOrderEntry) orderEntry).getLibrary();
            if (library != null) {
                final Library source = library.getSource();
                result.add(source != null ? source : library);
            }
        }
    }
    return new Predicate<Library>() {

        @Override
        public boolean apply(Library library) {
            if (result.contains(library))
                return false;
            if (library instanceof LibraryImpl) {
                final Library source = ((LibraryImpl) library).getSource();
                if (source != null && result.contains(source))
                    return false;
            }
            PersistentLibraryKind<?> kind = ((LibraryEx) library).getKind();
            if (kind != null) {
                LibraryType type = LibraryType.findByKind(kind);
                if (type != null && !type.isSuitableModule(rootModel.getModule(), facetsProvider)) {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Predicate(com.intellij.util.containers.Predicate)

Example 9 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.

the class AddNewModuleLibraryAction method createTableItem.

@Override
protected ClasspathTableItem<?> createTableItem(final Library item) {
    final OrderEntry[] entries = myClasspathPanel.getRootModel().getOrderEntries();
    for (OrderEntry entry : entries) {
        if (entry instanceof LibraryOrderEntry) {
            final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
            if (item.equals(libraryOrderEntry.getLibrary())) {
                return ClasspathTableItem.createLibItem(libraryOrderEntry, myContext);
            }
        }
    }
    LOG.error("Unknown library " + item);
    return null;
}
Also used : LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry)

Example 10 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.

the class ChangeLibraryLevelInClasspathAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final OrderEntry entry = myPanel.getSelectedEntry();
    if (!(entry instanceof LibraryOrderEntry))
        return;
    LibraryOrderEntry libraryEntry = (LibraryOrderEntry) entry;
    final LibraryEx library = (LibraryEx) libraryEntry.getLibrary();
    if (library == null)
        return;
    final Library copied = doCopy(library);
    if (copied == null)
        return;
    if (!isConvertingToModuleLibrary()) {
        OrderEntryUtil.replaceLibrary(myPanel.getRootModel(), library, copied);
    } else {
        OrderEntryUtil.replaceLibraryEntryByAdded(myPanel.getRootModel(), libraryEntry);
    }
}
Also used : LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)40 Library (com.intellij.openapi.roots.libraries.Library)27 OrderEntry (com.intellij.openapi.roots.OrderEntry)17 Module (com.intellij.openapi.module.Module)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)5 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 ActionCallback (com.intellij.openapi.util.ActionCallback)3 THashSet (gnu.trove.THashSet)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Notification (com.intellij.notification.Notification)2 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)2