Search in sources :

Example 1 with LibraryPresentationManager

use of com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager in project kotlin by JetBrains.

the class CustomLibraryDescriptorWithDeferredConfig method finishLibConfiguration.

public void finishLibConfiguration(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
    DeferredCopyFileRequests deferredCopyFileRequests = getCopyFileRequests();
    if (deferredCopyFileRequests == null)
        return;
    Library library = ProjectStructureUtilKt.findLibrary(rootModel.orderEntries(), new Function1<Library, Boolean>() {

        @Override
        public Boolean invoke(@NotNull Library library) {
            LibraryPresentationManager libraryPresentationManager = LibraryPresentationManager.getInstance();
            List<VirtualFile> classFiles = Arrays.asList(library.getFiles(OrderRootType.CLASSES));
            return libraryPresentationManager.isLibraryOfKind(classFiles, libraryKind);
        }
    });
    if (library == null) {
        return;
    }
    Library.ModifiableModel model = library.getModifiableModel();
    try {
        deferredCopyFileRequests.performRequests(module.getProject(), ProjectStructureUtilKt.getModuleDir(module), model);
    } finally {
        model.commit();
    }
}
Also used : List(java.util.List) Library(com.intellij.openapi.roots.libraries.Library) LibraryPresentationManager(com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager)

Example 2 with LibraryPresentationManager

use of com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager in project intellij-community by JetBrains.

the class MvcUpgradeAction method removeOldMvcSdk.

public static void removeOldMvcSdk(MvcFramework framework, ModifiableRootModel model) {
    final LibraryPresentationManager presentationManager = LibraryPresentationManager.getInstance();
    for (OrderEntry entry : model.getOrderEntries()) {
        if (entry instanceof LibraryOrderEntry) {
            final Library library = ((LibraryOrderEntry) entry).getLibrary();
            final LibrariesContainer container = LibrariesContainerFactory.createContainer(model);
            if (library != null) {
                final VirtualFile[] files = container.getLibraryFiles(library, OrderRootType.CLASSES);
                if (presentationManager.isLibraryOfKind(Arrays.asList(files), framework.getLibraryKind())) {
                    model.removeOrderEntry(entry);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) LibraryPresentationManager(com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)2 LibraryPresentationManager (com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager)2 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 OrderEntry (com.intellij.openapi.roots.OrderEntry)1 LibrariesContainer (com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 List (java.util.List)1