Search in sources :

Example 21 with Library

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

the class RootIndex method buildRootInfo.

@NotNull
private RootInfo buildRootInfo(@NotNull Project project) {
    final RootInfo info = new RootInfo();
    for (final Module module : ModuleManager.getInstance(project).getModules()) {
        final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        for (final VirtualFile contentRoot : moduleRootManager.getContentRoots()) {
            if (!info.contentRootOf.containsKey(contentRoot) && ensureValid(contentRoot, module)) {
                info.contentRootOf.put(contentRoot, module);
            }
        }
        for (ContentEntry contentEntry : moduleRootManager.getContentEntries()) {
            if (!(contentEntry instanceof ContentEntryImpl) || !((ContentEntryImpl) contentEntry).isDisposed()) {
                for (VirtualFile excludeRoot : contentEntry.getExcludeFolderFiles()) {
                    if (!ensureValid(excludeRoot, contentEntry))
                        continue;
                    info.excludedFromModule.put(excludeRoot, module);
                }
            }
            // Init module sources
            for (final SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
                final VirtualFile sourceFolderRoot = sourceFolder.getFile();
                if (sourceFolderRoot != null && ensureValid(sourceFolderRoot, sourceFolder)) {
                    info.rootTypeId.put(sourceFolderRoot, getRootTypeId(sourceFolder.getRootType()));
                    info.classAndSourceRoots.add(sourceFolderRoot);
                    info.sourceRootOf.putValue(sourceFolderRoot, module);
                    info.packagePrefix.put(sourceFolderRoot, sourceFolder.getPackagePrefix());
                }
            }
        }
        for (OrderEntry orderEntry : moduleRootManager.getOrderEntries()) {
            if (orderEntry instanceof LibraryOrSdkOrderEntry) {
                final LibraryOrSdkOrderEntry entry = (LibraryOrSdkOrderEntry) orderEntry;
                final VirtualFile[] sourceRoots = entry.getRootFiles(OrderRootType.SOURCES);
                final VirtualFile[] classRoots = entry.getRootFiles(OrderRootType.CLASSES);
                // Init library sources
                for (final VirtualFile sourceRoot : sourceRoots) {
                    if (!ensureValid(sourceRoot, entry))
                        continue;
                    info.classAndSourceRoots.add(sourceRoot);
                    info.libraryOrSdkSources.add(sourceRoot);
                    info.packagePrefix.put(sourceRoot, "");
                }
                // init library classes
                for (final VirtualFile classRoot : classRoots) {
                    if (!ensureValid(classRoot, entry))
                        continue;
                    info.classAndSourceRoots.add(classRoot);
                    info.libraryOrSdkClasses.add(classRoot);
                    info.packagePrefix.put(classRoot, "");
                }
                if (orderEntry instanceof LibraryOrderEntry) {
                    Library library = ((LibraryOrderEntry) orderEntry).getLibrary();
                    if (library != null) {
                        for (VirtualFile root : ((LibraryEx) library).getExcludedRoots()) {
                            if (!ensureValid(root, library))
                                continue;
                            info.excludedFromLibraries.putValue(root, library);
                        }
                        for (VirtualFile root : sourceRoots) {
                            if (!ensureValid(root, library))
                                continue;
                            info.sourceOfLibraries.putValue(root, library);
                        }
                        for (VirtualFile root : classRoots) {
                            if (!ensureValid(root, library))
                                continue;
                            info.classOfLibraries.putValue(root, library);
                        }
                    }
                }
            }
        }
    }
    for (AdditionalLibraryRootsProvider provider : Extensions.getExtensions(AdditionalLibraryRootsProvider.EP_NAME)) {
        Collection<SyntheticLibrary> libraries = provider.getAdditionalProjectLibraries(project);
        for (SyntheticLibrary descriptor : libraries) {
            Collection<VirtualFile> roots = ContainerUtil.filter(descriptor.getSourceRoots(), file -> ensureValid(file, project));
            info.libraryOrSdkSources.addAll(roots);
            info.classAndSourceRoots.addAll(roots);
        }
    }
    for (DirectoryIndexExcludePolicy policy : Extensions.getExtensions(DirectoryIndexExcludePolicy.EP_NAME, project)) {
        info.excludedFromProject.addAll(ContainerUtil.filter(policy.getExcludeRootsForProject(), file -> ensureValid(file, policy)));
    }
    return info;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) java.util(java.util) CollectionQuery(com.intellij.util.CollectionQuery) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) Query(com.intellij.util.Query) com.intellij.openapi.roots(com.intellij.openapi.roots) Library(com.intellij.openapi.roots.libraries.Library) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) Project(com.intellij.openapi.project.Project) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) Extensions(com.intellij.openapi.extensions.Extensions) SLRUMap(com.intellij.util.containers.SLRUMap) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) Nullable(org.jetbrains.annotations.Nullable) Pair(com.intellij.openapi.util.Pair) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with Library

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

the class RootModelImpl method orderEntriesEquals.

private static boolean orderEntriesEquals(@NotNull OrderEntry orderEntry1, @NotNull OrderEntry orderEntry2) {
    if (!((OrderEntryBaseImpl) orderEntry1).sameType(orderEntry2))
        return false;
    if (orderEntry1 instanceof JdkOrderEntry) {
        if (!(orderEntry2 instanceof JdkOrderEntry))
            return false;
        if (orderEntry1 instanceof InheritedJdkOrderEntry && orderEntry2 instanceof ModuleJdkOrderEntry) {
            return false;
        }
        if (orderEntry2 instanceof InheritedJdkOrderEntry && orderEntry1 instanceof ModuleJdkOrderEntry) {
            return false;
        }
        if (orderEntry1 instanceof ModuleJdkOrderEntry && orderEntry2 instanceof ModuleJdkOrderEntry) {
            String name1 = ((ModuleJdkOrderEntry) orderEntry1).getJdkName();
            String name2 = ((ModuleJdkOrderEntry) orderEntry2).getJdkName();
            if (!Comparing.strEqual(name1, name2)) {
                return false;
            }
        }
    }
    if (orderEntry1 instanceof ExportableOrderEntry) {
        if (!(((ExportableOrderEntry) orderEntry1).isExported() == ((ExportableOrderEntry) orderEntry2).isExported())) {
            return false;
        }
        if (!(((ExportableOrderEntry) orderEntry1).getScope() == ((ExportableOrderEntry) orderEntry2).getScope())) {
            return false;
        }
    }
    if (orderEntry1 instanceof ModuleOrderEntry) {
        LOG.assertTrue(orderEntry2 instanceof ModuleOrderEntry);
        ModuleOrderEntryImpl entry1 = (ModuleOrderEntryImpl) orderEntry1;
        ModuleOrderEntryImpl entry2 = (ModuleOrderEntryImpl) orderEntry2;
        return entry1.isProductionOnTestDependency() == entry2.isProductionOnTestDependency() && Comparing.equal(entry1.getModuleName(), entry2.getModuleName());
    }
    if (orderEntry1 instanceof LibraryOrderEntry) {
        LOG.assertTrue(orderEntry2 instanceof LibraryOrderEntry);
        LibraryOrderEntry libraryOrderEntry1 = (LibraryOrderEntry) orderEntry1;
        LibraryOrderEntry libraryOrderEntry2 = (LibraryOrderEntry) orderEntry2;
        boolean equal = Comparing.equal(libraryOrderEntry1.getLibraryName(), libraryOrderEntry2.getLibraryName()) && Comparing.equal(libraryOrderEntry1.getLibraryLevel(), libraryOrderEntry2.getLibraryLevel());
        if (!equal)
            return false;
        Library library1 = libraryOrderEntry1.getLibrary();
        Library library2 = libraryOrderEntry2.getLibrary();
        if (library1 != null && library2 != null) {
            if (!Arrays.equals(((LibraryEx) library1).getExcludedRootUrls(), ((LibraryEx) library2).getExcludedRootUrls())) {
                return false;
            }
        }
    }
    final OrderRootType[] allTypes = OrderRootType.getAllTypes();
    for (OrderRootType type : allTypes) {
        final String[] orderedRootUrls1 = orderEntry1.getUrls(type);
        final String[] orderedRootUrls2 = orderEntry2.getUrls(type);
        if (!Arrays.equals(orderedRootUrls1, orderedRootUrls2)) {
            return false;
        }
    }
    return true;
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library)

Example 23 with Library

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

the class LibraryTableBase method createLibrary.

@Override
public Library createLibrary(String name) {
    final ModifiableModel modifiableModel = getModifiableModel();
    final Library library = modifiableModel.createLibrary(name);
    modifiableModel.commit();
    return library;
}
Also used : Library(com.intellij.openapi.roots.libraries.Library)

Example 24 with Library

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

the class LibraryTableBase method commit.

private void commit(LibraryModel model) {
    myFirstLoad = false;
    ApplicationManager.getApplication().assertWriteAccessAllowed();
    if (!model.isChanged()) {
        Disposer.dispose(model);
        return;
    }
    incrementModificationCount();
    //todo[nik] remove LibraryImpl#equals method instead of using identity sets
    Set<Library> addedLibraries = ContainerUtil.newIdentityTroveSet(model.myLibraries);
    addedLibraries.removeAll(myModel.myLibraries);
    Set<Library> removedLibraries = ContainerUtil.newIdentityTroveSet(myModel.myLibraries);
    removedLibraries.removeAll(model.myLibraries);
    for (Library library : removedLibraries) {
        fireBeforeLibraryRemoved(library);
    }
    myModel.copyFrom(model);
    for (Library library : removedLibraries) {
        Disposer.dispose(library);
        fireAfterLibraryRemoved(library);
    }
    for (Library library : addedLibraries) {
        fireLibraryAdded(library);
    }
    Disposer.dispose(model);
}
Also used : Library(com.intellij.openapi.roots.libraries.Library)

Example 25 with Library

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

the class JpsLibraryTableImpl method createLibrary.

@Override
public Library createLibrary(@NonNls String name) {
    final ModifiableModel model = getModifiableModel();
    final Library library = model.createLibrary(name);
    model.commit();
    return library;
}
Also used : Library(com.intellij.openapi.roots.libraries.Library) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)266 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)65 Module (com.intellij.openapi.module.Module)43 NotNull (org.jetbrains.annotations.NotNull)32 File (java.io.File)31 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)28 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)27 Project (com.intellij.openapi.project.Project)25 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)25 Nullable (org.jetbrains.annotations.Nullable)25 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)19 ArrayList (java.util.ArrayList)15 Sdk (com.intellij.openapi.projectRoots.Sdk)13 OrderEntry (com.intellij.openapi.roots.OrderEntry)12 THashSet (gnu.trove.THashSet)9 Element (org.jdom.Element)9 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)8 Result (com.intellij.openapi.application.Result)7 Logger (com.intellij.openapi.diagnostic.Logger)7