Search in sources :

Example 6 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx 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 7 with LibraryEx

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

the class RootModelImpl method addLibraryEntry.

@NotNull
@Override
public LibraryOrderEntry addLibraryEntry(@NotNull Library library) {
    assertWritable();
    final LibraryOrderEntry libraryOrderEntry = new LibraryOrderEntryImpl(library, this, myProjectRootManager);
    if (!libraryOrderEntry.isValid()) {
        LibraryEx libraryEx = ObjectUtils.tryCast(library, LibraryEx.class);
        boolean libraryDisposed = libraryEx != null ? libraryEx.isDisposed() : Disposer.isDisposed(library);
        throw new AssertionError("Invalid libraryOrderEntry, library: " + library + " of type " + library.getClass() + ", disposed: " + libraryDisposed + ", kind: " + (libraryEx != null ? libraryEx.getKind() : "<undefined>"));
    }
    myOrderEntries.add(libraryOrderEntry);
    return libraryOrderEntry;
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx 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 9 with LibraryEx

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

the class LibraryItem method getTooltipText.

@Override
public String getTooltipText() {
    if (myEntry == null)
        return null;
    final Library library = myEntry.getLibrary();
    if (library == null)
        return null;
    final String name = library.getName();
    if (name != null) {
        final List<String> invalidUrls = ((LibraryEx) library).getInvalidRootUrls(OrderRootType.CLASSES);
        if (!invalidUrls.isEmpty()) {
            return ProjectBundle.message("project.roots.tooltip.library.has.broken.paths", name, invalidUrls.size());
        }
    }
    final List<String> descriptions = LibraryPresentationManager.getInstance().getDescriptions(library, myContext);
    if (descriptions.isEmpty())
        return null;
    return XmlStringUtil.wrapInHtml(StringUtil.join(descriptions, "<br>"));
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library)

Example 10 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx 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)

Aggregations

LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)38 Library (com.intellij.openapi.roots.libraries.Library)19 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)8 Nullable (org.jetbrains.annotations.Nullable)8 Module (com.intellij.openapi.module.Module)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Project (com.intellij.openapi.project.Project)5 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)4 Logger (com.intellij.openapi.diagnostic.Logger)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 Disposable (com.intellij.openapi.Disposable)3 OrderRootType (com.intellij.openapi.roots.OrderRootType)3 LibraryProperties (com.intellij.openapi.roots.libraries.LibraryProperties)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 List (java.util.List)3 FlexCommonUtils (com.intellij.flex.FlexCommonUtils)2 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)2 OutputType (com.intellij.flex.model.bc.OutputType)2