Search in sources :

Example 1 with ModuleLibraryOrderEntryImpl

use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsPanel method configureAzureSDK.

private void configureAzureSDK() {
    final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
    for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
            return;
        }
    }
    final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
    AccessToken token = WriteAction.start();
    try {
        Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(AzureLibrary.APP_INSIGHTS.getName(), level, new ArrayList<OrderRoot>());
        for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
            if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                ((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
                break;
            }
        }
        Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
        AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, AzureLibrary.APP_INSIGHTS.getFiles());
        newLibraryModel.commit();
        modifiableModel.commit();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        token.finish();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Example 2 with ModuleLibraryOrderEntryImpl

use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method editLibrary.

private void editLibrary() {
    AzureLibrary azureLibrary = (AzureLibrary) librariesList.getSelectedValue();
    final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
    OrderEntry libraryOrderEntry = null;
    for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
            libraryOrderEntry = orderEntry;
            break;
        }
    }
    if (libraryOrderEntry != null) {
        LibraryPropertiesPanel libraryPropertiesPanel = new LibraryPropertiesPanel(module, azureLibrary, true, ((ModuleLibraryOrderEntryImpl) libraryOrderEntry).isExported());
        DefaultDialogWrapper libraryProperties = new DefaultDialogWrapper(module.getProject(), libraryPropertiesPanel);
        libraryProperties.show();
        if (libraryProperties.isOK()) {
            AccessToken token = WriteAction.start();
            try {
                ((ModuleLibraryOrderEntryImpl) libraryOrderEntry).setExported(libraryPropertiesPanel.isExported());
                modifiableModel.commit();
            } finally {
                token.finish();
            }
            LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
        }
    } else {
        PluginUtil.displayInfoDialog("Library not found", "Library was not found");
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) DefaultDialogWrapper(com.microsoft.intellij.ui.components.DefaultDialogWrapper) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)

Example 3 with ModuleLibraryOrderEntryImpl

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

the class LibraryDependencyDataService method syncExistingAndRemoveObsolete.

private void syncExistingAndRemoveObsolete(@NotNull IdeModifiableModelsProvider modelsProvider, @NotNull Map<Set<String>, LibraryDependencyData> moduleLibrariesToImport, @NotNull Map<String, LibraryDependencyData> projectLibrariesToImport, @NotNull Set<LibraryDependencyData> toImport, @NotNull Map<OrderEntry, OrderAware> orderEntryDataMap, @NotNull ModifiableRootModel moduleRootModel, boolean hasUnresolvedLibraries) {
    for (OrderEntry entry : moduleRootModel.getOrderEntries()) {
        if (entry instanceof ModuleLibraryOrderEntryImpl) {
            ModuleLibraryOrderEntryImpl moduleLibraryOrderEntry = (ModuleLibraryOrderEntryImpl) entry;
            Library library = moduleLibraryOrderEntry.getLibrary();
            if (library == null) {
                LOG.warn("Skipping module-level library entry because it doesn't have backing Library object. Entry: " + entry);
                continue;
            }
            final VirtualFile[] libraryFiles = library.getFiles(OrderRootType.CLASSES);
            final Set<String> moduleLibraryKey = ContainerUtilRt.newHashSet(libraryFiles.length);
            for (VirtualFile file : libraryFiles) {
                moduleLibraryKey.add(ExternalSystemApiUtil.getLocalFileSystemPath(file) + moduleLibraryOrderEntry.getScope().name());
            }
            LibraryDependencyData existing = moduleLibrariesToImport.remove(moduleLibraryKey);
            if (existing == null || !StringUtil.equals(StringUtil.nullize(existing.getInternalName()), library.getName())) {
                moduleRootModel.removeOrderEntry(entry);
            } else {
                orderEntryDataMap.put(entry, existing);
                syncExistingLibraryDependency(modelsProvider, existing, library, moduleRootModel, moduleLibraryOrderEntry.getOwnerModule());
                toImport.remove(existing);
            }
        } else if (entry instanceof LibraryOrderEntry) {
            LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
            String libraryName = libraryOrderEntry.getLibraryName();
            LibraryDependencyData existing = projectLibrariesToImport.remove(libraryName + libraryOrderEntry.getScope().name());
            if (existing != null) {
                toImport.remove(existing);
                orderEntryDataMap.put(entry, existing);
                libraryOrderEntry.setExported(existing.isExported());
                libraryOrderEntry.setScope(existing.getScope());
            } else if (!hasUnresolvedLibraries) {
                // There is a possible case that a project has been successfully imported from external model and after
                // that network/repo goes down. We don't want to drop existing binary mappings then.
                moduleRootModel.removeOrderEntry(entry);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) Library(com.intellij.openapi.roots.libraries.Library)

Example 4 with ModuleLibraryOrderEntryImpl

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

the class ArtifactEditorContextImpl method selectLibrary.

@Override
public void selectLibrary(@NotNull Library library) {
    final LibraryTable table = library.getTable();
    if (table != null) {
        ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
    } else {
        final Module module = ((LibraryImpl) library).getModule();
        if (module != null) {
            final ModuleRootModel rootModel = myParent.getModulesProvider().getRootModel(module);
            final String libraryName = library.getName();
            for (OrderEntry entry : rootModel.getOrderEntries()) {
                if (entry instanceof ModuleLibraryOrderEntryImpl) {
                    final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl) entry;
                    if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName()) || libraryName == null && library.equals(libraryEntry.getLibrary())) {
                        ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry);
                        return;
                    }
                }
            }
        }
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) Module(com.intellij.openapi.module.Module)

Example 5 with ModuleLibraryOrderEntryImpl

use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method addLibrary.

private void addLibrary() {
    AddLibraryWizardModel model = new AddLibraryWizardModel(module);
    AddLibraryWizardDialog wizard = new AddLibraryWizardDialog(model);
    wizard.setTitle(message("addLibraryTitle"));
    wizard.show();
    if (wizard.isOK()) {
        AzureLibrary azureLibrary = model.getSelectedLibrary();
        final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
        AccessToken token = WriteAction.start();
        try {
            final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
            for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
                if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                    PluginUtil.displayErrorDialog(message("error"), message("libraryExistsError"));
                    return;
                }
            }
            Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(azureLibrary.getName(), level, new ArrayList<OrderRoot>());
            if (model.isExported()) {
                for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
                    if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                        ((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
                        break;
                    }
                }
            }
            Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
            // if there is separate resources folder
            if (azureLibrary.getLocation() != null) {
                File file = new File(String.format("%s%s%s", AzurePlugin.pluginFolder, File.separator, azureLibrary.getLocation()));
                AddLibraryUtility.addLibraryRoot(file, newLibraryModel);
            }
            // if some files already contained in plugin dependencies, take them from there - true for azure sdk library
            if (azureLibrary.getFiles().length > 0) {
                AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, azureLibrary.getFiles());
            }
            newLibraryModel.commit();
            modifiableModel.commit();
            ((DefaultListModel) librariesList.getModel()).addElement(azureLibrary);
            tempList.add(azureLibrary);
        } catch (Exception ex) {
            PluginUtil.displayErrorDialogAndLog(message("error"), message("addLibraryError"), ex);
        } finally {
            token.finish();
        }
        LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
    }
}
Also used : ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Aggregations

ModuleLibraryOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)6 OrderEntry (com.intellij.openapi.roots.OrderEntry)5 AccessToken (com.intellij.openapi.application.AccessToken)3 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)3 Library (com.intellij.openapi.roots.libraries.Library)3 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)2 LibrariesContainer (com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)1 ModuleRootModel (com.intellij.openapi.roots.ModuleRootModel)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 LibraryImpl (com.intellij.openapi.roots.impl.libraries.LibraryImpl)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 DefaultDialogWrapper (com.microsoft.intellij.ui.components.DefaultDialogWrapper)1 Nullable (org.jetbrains.annotations.Nullable)1