Search in sources :

Example 11 with LibraryOrderEntry

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

the class DvcsUtil method getVcsRootForLibraryFile.

@Nullable
private static VirtualFile getVcsRootForLibraryFile(@NotNull Project project, @NotNull VirtualFile file) {
    ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    // for a file inside .jar/.zip consider the .jar/.zip file itself
    VirtualFile root = vcsManager.getVcsRootFor(VfsUtilCore.getVirtualFileForJar(file));
    if (root != null) {
        LOGGER.debug("Found root for zip/jar file: " + root);
        return root;
    }
    // for other libs which don't have jars inside the project dir (such as JDK) take the owner module of the lib
    List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
    Set<VirtualFile> libraryRoots = new HashSet<>();
    for (OrderEntry entry : entries) {
        if (entry instanceof LibraryOrderEntry || entry instanceof JdkOrderEntry) {
            VirtualFile moduleRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleFile());
            if (moduleRoot != null) {
                libraryRoots.add(moduleRoot);
            }
        }
    }
    if (libraryRoots.size() == 0) {
        LOGGER.debug("No library roots");
        return null;
    }
    // if the lib is used in several modules, take the top module
    // (for modules of the same level we can't guess anything => take the first one)
    Iterator<VirtualFile> libIterator = libraryRoots.iterator();
    VirtualFile topLibraryRoot = libIterator.next();
    while (libIterator.hasNext()) {
        VirtualFile libRoot = libIterator.next();
        if (VfsUtilCore.isAncestor(libRoot, topLibraryRoot, true)) {
            topLibraryRoot = libRoot;
        }
    }
    LOGGER.debug("Several library roots, returning " + topLibraryRoot);
    return topLibraryRoot;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with LibraryOrderEntry

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

the class FlexDebugProcess method uniteWithLibrarySourcesOfBC.

private static GlobalSearchScope uniteWithLibrarySourcesOfBC(GlobalSearchScope scope, final Module module, final FlexBuildConfiguration bc, final Collection<FlexBuildConfiguration> processedConfigurations) {
    if (!processedConfigurations.add(bc))
        return scope;
    final Collection<VirtualFile> libSourceRoots = new THashSet<>();
    final Sdk sdk = bc.getSdk();
    if (sdk != null) {
        Collections.addAll(libSourceRoots, sdk.getRootProvider().getFiles(OrderRootType.SOURCES));
    }
    for (final DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry instanceof BuildConfigurationEntry) {
            final Module otherModule = ((BuildConfigurationEntry) entry).findModule();
            final FlexBuildConfiguration otherBC = ((BuildConfigurationEntry) entry).findBuildConfiguration();
            if (otherModule != null && otherBC != null) {
                scope = uniteWithLibrarySourcesOfBC(scope, otherModule, otherBC, processedConfigurations);
            }
        } else if (entry instanceof ModuleLibraryEntry) {
            final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, ModuleRootManager.getInstance(module));
            if (orderEntry != null) {
                Collections.addAll(libSourceRoots, orderEntry.getFiles(OrderRootType.SOURCES));
            }
        } else if (entry instanceof SharedLibraryEntry) {
            final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                Collections.addAll(libSourceRoots, library.getFiles(OrderRootType.SOURCES));
            }
        }
    }
    return libSourceRoots.isEmpty() ? scope : scope.uniteWith(new LibrarySourcesSearchScope(module.getProject(), libSourceRoots));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) THashSet(gnu.trove.THashSet) Sdk(com.intellij.openapi.projectRoots.Sdk) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

Example 13 with LibraryOrderEntry

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

the class FlexBuildConfigurationsExtension method selectOrderEntry.

@Nullable
public ActionCallback selectOrderEntry(@NotNull final Module module, @Nullable final OrderEntry entry) {
    if (ModuleType.get(module) != FlexModuleType.getInstance()) {
        return null;
    }
    if (entry instanceof LibraryOrderEntry) {
        final Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library != null && library.getTable() == null && ((LibraryEx) library).getKind() == FlexLibraryType.FLEX_LIBRARY) {
            final String libraryId = FlexProjectRootsUtil.getLibraryId(library);
            final List<CompositeConfigurable> configurables = myConfigurator.getBCConfigurables(module);
            // several build configurations may depend on the same library, here we select the first one we find
            for (CompositeConfigurable configurable : configurables) {
                final FlexBCConfigurable bcConfigurable = FlexBCConfigurable.unwrap(configurable);
                final Dependencies dependencies = bcConfigurable.getDependenciesConfigurable().getEditableObject();
                for (DependencyEntry e : dependencies.getEntries()) {
                    if (!(e instanceof ModuleLibraryEntry) || !((ModuleLibraryEntry) e).getLibraryId().equals(libraryId)) {
                        continue;
                    }
                    final Place p = FlexProjectStructureUtil.createPlace(bcConfigurable, DependenciesConfigurable.TAB_NAME);
                    final DependenciesConfigurable.Location.TableEntry tableEntry = DependenciesConfigurable.Location.TableEntry.forModuleLibrary(libraryId);
                    p.putPath(FlexBCConfigurable.LOCATION_ON_TAB, tableEntry);
                    return ProjectStructureConfigurable.getInstance(module.getProject()).navigateTo(p, true);
                }
            }
        }
    }
    return ProjectStructureConfigurable.getInstance(module.getProject()).select(module.getName(), null, true);
}
Also used : ModuleLibraryEntry(com.intellij.lang.javascript.flex.projectStructure.model.ModuleLibraryEntry) CompositeConfigurable(com.intellij.lang.javascript.flex.projectStructure.ui.CompositeConfigurable) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) FlexBCConfigurable(com.intellij.lang.javascript.flex.projectStructure.ui.FlexBCConfigurable) DependencyEntry(com.intellij.lang.javascript.flex.projectStructure.model.DependencyEntry) Library(com.intellij.openapi.roots.libraries.Library) Dependencies(com.intellij.lang.javascript.flex.projectStructure.model.Dependencies) Place(com.intellij.ui.navigation.Place) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with LibraryOrderEntry

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

the class LibraryCollector method collect.

/**
   * We don't use BuildConfigurationEntry as source of libraries. If reference to component declared in such build configuration is resolved, so, we register such bc's module
   */
public void collect(Module module) {
    final FlexBuildConfiguration bc = FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration();
    final Sdk sdk = bc.getSdk();
    assert sdk != null;
    final SdkType sdkType;
    try {
        sdkType = (SdkType) sdk.getClass().getMethod("getSdkType").invoke(sdk);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    final boolean isFlexmojosSdk = sdkType instanceof FlexmojosSdkType;
    if (!isFlexmojosSdk) {
        collectSdkLibraries(bc, sdk);
    } else {
        final String sdkHomePath = sdk.getHomePath();
        LogMessageUtil.LOG.assertTrue(sdkHomePath != null && sdkHomePath.contains("flex"), sdkHomePath + " must be path to maven repo and contains 'flex'");
        flexmojosSdkHomePath = sdkHomePath.substring(0, sdkHomePath.indexOf("flex"));
    }
    flexSdkVersion = sdk.getVersionString();
    assert flexSdkVersion != null;
    if (StringUtil.compareVersionNumbers(flexSdkVersion, "4.5.1") >= 0) {
        flexSdkVersion = "4.6";
    } else {
        flexSdkVersion = flexSdkVersion.substring(0, 3);
    }
    globalCatalogForTests(bc);
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    for (DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry instanceof ModuleLibraryEntry) {
            LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, moduleRootManager);
            if (orderEntry != null) {
                collectFromLibraryOrderEntry(orderEntry.getRootFiles(OrderRootType.CLASSES));
            }
        } else if (entry instanceof SharedLibraryEntry) {
            com.intellij.openapi.roots.libraries.Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                collectFromLibraryOrderEntry(library.getFiles(OrderRootType.CLASSES));
            }
        }
    }
    // IDEA-71055
    // todo css-based themes
    final List<String> themes = BCUtils.getThemes(module, bc);
    for (String theme : themes) {
        if (theme.endsWith(DOT_SWC)) {
            final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(theme);
            if (file != null && uniqueGuard.add(file)) {
                final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file);
                if (jarFile != null) {
                    addLibrary(jarFile, true);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) SdkType(com.intellij.openapi.projectRoots.SdkType) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType)

Example 15 with LibraryOrderEntry

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

the class DependenciesConfigurable method editLibrary.

private void editLibrary(ModuleLibraryItem item) {
    if (!item.canEdit())
        return;
    final LibraryOrderEntry entry = item.orderEntry;
    assert entry != null;
    Library library = entry.getLibrary();
    if (library == null) {
        return;
    }
    LibraryTablePresentation presentation = new LibraryTablePresentation() {

        @Override
        public String getDisplayName(boolean plural) {
            return FlexBundle.message(plural ? "library.editor.title.plural" : "library.editor.title.singular");
        }

        @Override
        public String getDescription() {
            return ProjectBundle.message("libraries.node.text.module");
        }

        @Override
        public String getLibraryTableEditorTitle() {
            // not used as far as I see
            return "Configure Library";
        }
    };
    LibraryTableModifiableModelProvider provider = new LibraryTableModifiableModelProvider() {

        public LibraryTable.ModifiableModel getModifiableModel() {
            return myConfigEditor.getLibraryModel(myDependencies);
        }
    };
    StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
    EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(myMainPanel, provider, library, myProject, presentation, context);
    dialog.setContextModule(myConfigEditor.getModule(myDependencies));
    dialog.show();
    myTable.refresh();
}
Also used : EditExistingLibraryDialog(com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider)

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