Search in sources :

Example 21 with LibraryOrderEntry

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

the class AndroidModuleDependenciesSetupTest method testSetUpLibraryWithExistingLibrary.

public void testSetUpLibraryWithExistingLibrary() throws IOException {
    File binaryPath = createTempFile("fakeLibrary", "jar");
    File sourcePath = createTempFile("fakeLibrary-src", "jar");
    Library newLibrary = createLibrary(binaryPath, 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);
    LibraryOrderEntry libraryOrderEntry = libraryOrderEntries.get(0);
    // The existing library should not have been changed.
    assertSame(newLibrary, libraryOrderEntry.getLibrary());
    verify(myLibraryRegistry).markAsUsed(newLibrary, binaryPaths);
    // Should not attemp to look up sources for existing libraries.
    verify(myLibraryFilePaths, never()).findSourceJarPath(binaryPath);
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) File(java.io.File)

Example 22 with LibraryOrderEntry

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

the class DartUrlResolverImpl method initPackagesMapFromLib.

private void initPackagesMapFromLib(@NotNull final VirtualFile contextFile) {
    final Module module = ModuleUtilCore.findModuleForFile(contextFile, myProject);
    final List<OrderEntry> orderEntries = module != null ? Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries()) : ProjectRootManager.getInstance(myProject).getFileIndex().getOrderEntriesForFile(contextFile);
    for (OrderEntry orderEntry : orderEntries) {
        if (orderEntry instanceof LibraryOrderEntry && LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry) orderEntry).getLibraryLevel()) && DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(((LibraryOrderEntry) orderEntry).getLibraryName())) {
            final LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
            final LibraryProperties properties = library == null ? null : library.getProperties();
            if (properties instanceof DartPackagesLibraryProperties) {
                for (Map.Entry<String, List<String>> entry : ((DartPackagesLibraryProperties) properties).getPackageNameToDirsMap().entrySet()) {
                    if (entry != null && entry.getKey() != null && entry.getValue() != null) {
                        myPackagesMapFromLib.put(entry.getKey(), entry.getValue());
                    }
                }
                return;
            }
        }
    }
}
Also used : DartPackagesLibraryProperties(com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) DartPackagesLibraryProperties(com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties) LibraryProperties(com.intellij.openapi.roots.libraries.LibraryProperties) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) List(java.util.List) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Module(com.intellij.openapi.module.Module) THashMap(gnu.trove.THashMap) Map(java.util.Map)

Example 23 with LibraryOrderEntry

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

the class CodeContext method createCodeContextFromLibraries.

private static CodeContext createCodeContextFromLibraries(final String namespace, final Module module, final FlexBuildConfiguration bc) {
    final Map<String, CodeContext> contextsOfModule = new THashMap<>();
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    // If fixed - then method usage at getStdCodeContext() must be changed to make sure that all namespaces handled at that point.
    for (DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry.getDependencyType().getLinkageType() == LinkageType.LoadInRuntime)
            continue;
        if (entry instanceof BuildConfigurationEntry) {
            final FlexBuildConfiguration bcDependency = ((BuildConfigurationEntry) entry).findBuildConfiguration();
            if (bcDependency != null && bcDependency.getOutputType() == OutputType.Library) {
                addComponentsFromManifests(module, contextsOfModule, bcDependency, true);
            }
        } else if (entry instanceof ModuleLibraryEntry) {
            final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, rootManager);
            if (orderEntry != null) {
                for (VirtualFile file : orderEntry.getRootFiles(OrderRootType.CLASSES)) {
                    handleFileDependency(module, contextsOfModule, file);
                }
            }
        } else if (entry instanceof SharedLibraryEntry) {
            final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
                    handleFileDependency(module, contextsOfModule, file);
                }
            }
        }
    }
    addComponentsFromManifests(module, contextsOfModule, bc, false);
    final CodeContextHolder contextHolder = CodeContextHolder.getInstance(module.getProject());
    for (Map.Entry<String, CodeContext> entry : contextsOfModule.entrySet()) {
        contextHolder.putCodeContext(entry.getKey(), module, entry.getValue());
    }
    CodeContext codeContext = contextsOfModule.get(namespace);
    if (codeContext == null) {
        codeContext = CodeContextHolder.EMPTY;
    }
    return codeContext;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) THashMap(gnu.trove.THashMap) Library(com.intellij.openapi.roots.libraries.Library) THashMap(gnu.trove.THashMap) Map(java.util.Map)

Example 24 with LibraryOrderEntry

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

the class AddAsSwcLibDialog method filterAlreadyExistingRoots.

private static Collection<VirtualFile> filterAlreadyExistingRoots(final Collection<VirtualFile> roots, final FlexProjectConfigurationEditor flexConfigEditor, final Module module, final ModifiableFlexBuildConfiguration bc) {
    final Set<VirtualFile> result = new THashSet<>(roots);
    final DependencyEntry[] entries = bc.getDependencies().getEntries();
    for (DependencyEntry entry : entries) {
        if (entry instanceof ModifiableModuleLibraryEntry) {
            final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, flexConfigEditor.getModifiableRootModel(module));
            if (orderEntry != null) {
                for (VirtualFile file : orderEntry.getRootFiles(OrderRootType.CLASSES)) {
                    if (result.contains(file)) {
                        result.remove(file);
                    }
                }
            }
        } else if (entry instanceof ModifiableSharedLibraryEntry) {
            final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
                    if (result.contains(file)) {
                        result.remove(file);
                    }
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) THashSet(gnu.trove.THashSet)

Example 25 with LibraryOrderEntry

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

the class FlexmojosImporterTestBase method checkLibrariesOfFlexType.

private static void checkLibrariesOfFlexType(final Module module, final FlexBuildConfiguration bc) {
    final List<LibraryOrderEntry> moduleLibEntries = ContainerUtil.filter(ModuleRootManager.getInstance(module).getOrderEntries(), new FilteringIterator.InstanceOf(LibraryOrderEntry.class));
    final List<SharedLibraryEntry> bcLibEntries = ContainerUtil.filter(bc.getDependencies().getEntries(), new FilteringIterator.InstanceOf(SharedLibraryEntry.class));
    assertTrue(bcLibEntries.size() > 0);
    assertEquals(moduleLibEntries.size(), bcLibEntries.size());
    for (SharedLibraryEntry entry : bcLibEntries) {
        assertTrue(entry.getLibraryName().contains(":swc:") || entry.getLibraryName().contains(":rb.swc:") || entry.getLibraryName().contains(":resource-bundle:"));
        assertEquals(LibraryTablesRegistrar.PROJECT_LEVEL, entry.getLibraryLevel());
        final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), entry);
        assertNotNull(library);
        assertTrue(((LibraryEx) library).getKind() == FlexLibraryType.FLEX_LIBRARY);
        checkContainsLibrary(moduleLibEntries, library);
    }
}
Also used : FilteringIterator(com.intellij.util.containers.FilteringIterator) SharedLibraryEntry(com.intellij.lang.javascript.flex.projectStructure.model.SharedLibraryEntry) 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