Search in sources :

Example 26 with LibraryEx

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

the class Flexmojos3Configurator method handleDependencies.

private TargetPlatform handleDependencies(final ModifiableFlexBuildConfiguration bc) {
    bc.getDependencies().getModifiableEntries().clear();
    boolean playerglobal = false;
    boolean airglobal = false;
    boolean mobilecomponents = false;
    final ModifiableRootModel rootModel = myModelsProvider.getModifiableRootModel(myModule);
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        final DependencyScope scope = entry instanceof ExportableOrderEntry ? ((ExportableOrderEntry) entry).getScope() : DependencyScope.COMPILE;
        final boolean isExported = entry instanceof ExportableOrderEntry && ((ExportableOrderEntry) entry).isExported();
        if (entry instanceof ModuleOrderEntry) {
            rootModel.removeOrderEntry(entry);
            final String dependencyModuleName = ((ModuleOrderEntry) entry).getModuleName();
            final MavenProject dependencyMavenProject = findMavenProjectByModuleName(dependencyModuleName);
            if (dependencyMavenProject == null) {
                MavenLog.LOG.warn("Maven project not found, module dependency skipped: " + myModule.getName() + " on " + dependencyModuleName);
                continue;
            }
            if (!ArrayUtil.contains(dependencyMavenProject.getPackaging(), FlexmojosImporter.SUPPORTED_PACKAGINGS)) {
                MavenLog.LOG.info("Unexpected packaging (" + dependencyMavenProject.getPackaging() + "), module dependency skipped: " + myModule.getName() + " on " + dependencyModuleName);
                continue;
            }
            final ModifiableDependencyEntry existingEntry = ContainerUtil.find(bc.getDependencies().getModifiableEntries(), entry1 -> (entry1 instanceof BuildConfigurationEntry) && ((BuildConfigurationEntry) entry1).getModuleName().equals(dependencyModuleName) && ((BuildConfigurationEntry) entry1).getBcName().equals(dependencyModuleName));
            final LinkageType linkageType = "swc".equals(dependencyMavenProject.getPackaging()) ? FlexUtils.convertLinkageType(scope, isExported) : LinkageType.LoadInRuntime;
            if (existingEntry != null) {
                if (existingEntry.getDependencyType().getLinkageType() == LinkageType.Test) {
                    existingEntry.getDependencyType().setLinkageType(linkageType);
                }
                continue;
            }
            final ModifiableBuildConfigurationEntry bcEntry = myFlexEditor.createBcEntry(bc.getDependencies(), dependencyModuleName, dependencyModuleName);
            bcEntry.getDependencyType().setLinkageType(linkageType);
            bc.getDependencies().getModifiableEntries().add(0, bcEntry);
            continue;
        }
        if (entry instanceof JdkOrderEntry) {
            rootModel.removeOrderEntry(entry);
        }
        if (!(entry instanceof LibraryOrderEntry))
            continue;
        rootModel.removeOrderEntry(entry);
        if (!LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry) entry).getLibraryLevel()))
            continue;
        final Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library == null || !MavenRootModelAdapter.isMavenLibrary(library))
            continue;
        final String libraryName = library.getName();
        if (libraryName.contains(":rb.swc:") || libraryName.contains(":resource-bundle:")) {
            // fix rb.swc placeholders to real SWCs according to used locales
            final Library.ModifiableModel libraryModifiableModel = myModelsProvider.getModifiableLibraryModel(library);
            for (final String rbSwcPlaceholdersUrl : findRbSwcPlaceholderUrls(libraryModifiableModel)) {
                final Collection<String> rootsToAdd = getRbSwcUrlsForCompiledLocales(rbSwcPlaceholdersUrl);
                libraryModifiableModel.removeRoot(rbSwcPlaceholdersUrl, OrderRootType.CLASSES);
                for (final String rootToAdd : rootsToAdd) {
                    if (!ArrayUtil.contains(rootToAdd, libraryModifiableModel.getUrls(OrderRootType.CLASSES))) {
                        libraryModifiableModel.addRoot(rootToAdd, OrderRootType.CLASSES);
                    }
                }
            // sources and docs could be updated as well, but currently they are always senseless, because they do not exist
            }
        }
        if (libraryName.contains(":swc:") || libraryName.contains(":rb.swc:") || libraryName.contains(":resource-bundle:") || libraryName.contains(":ane:")) {
            playerglobal |= libraryName.contains("playerglobal");
            airglobal |= libraryName.contains("airglobal");
            mobilecomponents |= libraryName.contains("mobilecomponents");
            final boolean ane = libraryName.contains(":ane:") && !libraryName.contains(":swc:");
            final LibraryKind kind = ((LibraryEx) library).getKind();
            if (kind != FlexLibraryType.FLEX_LIBRARY) {
                if (kind == null) {
                    final LibraryEx.ModifiableModelEx libraryModel = (LibraryEx.ModifiableModelEx) myModelsProvider.getModifiableLibraryModel(library);
                    libraryModel.setKind(FlexLibraryType.FLEX_LIBRARY);
                }
            }
            final ModifiableDependencyEntry sharedLibraryEntry = myFlexEditor.createSharedLibraryEntry(bc.getDependencies(), ((LibraryOrderEntry) entry).getLibraryName(), ((LibraryOrderEntry) entry).getLibraryLevel());
            final LinkageType linkageType = ane ? DependencyType.DEFAULT_LINKAGE : FlexUtils.convertLinkageType(scope, isExported);
            sharedLibraryEntry.getDependencyType().setLinkageType(linkageType);
            bc.getDependencies().getModifiableEntries().add(sharedLibraryEntry);
        } else {
            MavenLog.LOG.info("Non-swc dependency for flexmojos project '" + myModule.getName() + "': " + libraryName);
        }
    }
    // todo better target platform detection if both airglobal and playerglobal present?
    return mobilecomponents && airglobal ? TargetPlatform.Mobile : airglobal && !playerglobal ? TargetPlatform.Desktop : TargetPlatform.Web;
}
Also used : LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Library(com.intellij.openapi.roots.libraries.Library)

Example 27 with LibraryEx

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

the class DartFileListener method updatePackagesLibraryRoots.

@NotNull
public static Library updatePackagesLibraryRoots(@NotNull final Project project, @NotNull final DartLibInfo libInfo) {
    final LibraryTable projectLibraryTable = ProjectLibraryTable.getInstance(project);
    final Library existingLibrary = projectLibraryTable.getLibraryByName(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME);
    final Library library = existingLibrary != null ? existingLibrary : WriteAction.compute(() -> {
        final LibraryTableBase.ModifiableModel libTableModel = ProjectLibraryTable.getInstance(project).getModifiableModel();
        final Library lib = libTableModel.createLibrary(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME, DartPackagesLibraryType.LIBRARY_KIND);
        libTableModel.commit();
        return lib;
    });
    final String[] existingUrls = library.getUrls(OrderRootType.CLASSES);
    final Collection<String> libRootUrls = libInfo.getLibRootUrls();
    if ((!libInfo.isProjectWithoutPubspec() && isBrokenPackageMap(((LibraryEx) library).getProperties())) || existingUrls.length != libRootUrls.size() || !libRootUrls.containsAll(Arrays.asList(existingUrls))) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
            for (String url : existingUrls) {
                model.removeRoot(url, OrderRootType.CLASSES);
            }
            for (String url : libRootUrls) {
                model.addRoot(url, OrderRootType.CLASSES);
            }
            final DartPackagesLibraryProperties libraryProperties = new DartPackagesLibraryProperties();
            libraryProperties.setPackageNameToDirsMap(libInfo.getPackagesMap());
            model.setProperties(libraryProperties);
            model.commit();
        });
    }
    return library;
}
Also used : DartPackagesLibraryProperties(com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with LibraryEx

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

Example 29 with LibraryEx

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

the class DependenciesConfigurable method resetTable.

private void resetTable(SdkEntry sdkEntry, boolean keepSelection) {
    int[] selectedRows = keepSelection ? myTable.getSelectedRows() : new int[0];
    DefaultMutableTreeNode root = myTable.getRoot();
    root.removeAllChildren();
    if (sdkEntry != null) {
        Sdk flexSdk = FlexSdkUtils.findFlexOrFlexmojosSdk(sdkEntry.getName());
        if (flexSdk != null) {
            DefaultMutableTreeNode sdkNode = new DefaultMutableTreeNode(new SdkItem(flexSdk), true);
            myTable.getRoot().insert(sdkNode, 0);
            updateSdkEntries(sdkNode, flexSdk);
        }
    }
    FlexBCConfigurator configurator = FlexBuildConfigurationsExtension.getInstance().getConfigurator();
    for (DependencyEntry entry : myDependencies.getEntries()) {
        MyTableItem item = null;
        if (entry instanceof BuildConfigurationEntry) {
            final BuildConfigurationEntry bcEntry = (BuildConfigurationEntry) entry;
            Module module = bcEntry.findModule();
            CompositeConfigurable configurable = module != null ? ContainerUtil.find(configurator.getBCConfigurables(module), configurable1 -> configurable1.getDisplayName().equals(bcEntry.getBcName())) : null;
            if (configurable == null) {
                item = new BCItem(bcEntry.getModuleName(), bcEntry.getBcName());
            } else {
                item = new BCItem(FlexBCConfigurable.unwrap(configurable));
            }
            ((BCItem) item).dependencyType.copyFrom(entry.getDependencyType());
        } else if (entry instanceof ModuleLibraryEntry) {
            ModuleLibraryEntry moduleLibraryEntry = (ModuleLibraryEntry) entry;
            item = new ModuleLibraryItem(moduleLibraryEntry.getLibraryId(), myConfigEditor.findLibraryOrderEntry(myDependencies, moduleLibraryEntry), myProject);
            ((ModuleLibraryItem) item).dependencyType.copyFrom(entry.getDependencyType());
        } else if (entry instanceof SharedLibraryEntry) {
            SharedLibraryEntry sharedLibraryEntry = (SharedLibraryEntry) entry;
            LibrariesModifiableModel model = ProjectStructureConfigurable.getInstance(myProject).getContext().createModifiableModelProvider(sharedLibraryEntry.getLibraryLevel()).getModifiableModel();
            LibraryEx library = (LibraryEx) model.getLibraryByName(sharedLibraryEntry.getLibraryName());
            item = new SharedLibraryItem(sharedLibraryEntry.getLibraryName(), sharedLibraryEntry.getLibraryLevel(), library, myProject);
            ((SharedLibraryItem) item).dependencyType.copyFrom(entry.getDependencyType());
        }
        if (item != null) {
            root.add(new DefaultMutableTreeNode(item, false));
        }
    }
    myTable.refresh();
    myTable.clearSelection();
    for (int row : selectedRows) {
        myTable.getSelectionModel().addSelectionInterval(row, row);
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) UIUtil(com.intellij.util.ui.UIUtil) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) EventDispatcher(com.intellij.util.EventDispatcher) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ProjectModelExternalSource(com.intellij.openapi.roots.ProjectModelExternalSource) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ComponentSet(com.intellij.flex.model.bc.ComponentSet) ColumnInfo(com.intellij.util.ui.ColumnInfo) TableCellRenderer(javax.swing.table.TableCellRenderer) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) FlexCommonUtils(com.intellij.flex.FlexCommonUtils) EditExistingLibraryDialog(com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) Nls(org.jetbrains.annotations.Nls) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) MasterDetailsComponent(com.intellij.openapi.ui.MasterDetailsComponent) JdkComboBox(com.intellij.openapi.roots.ui.configuration.JdkComboBox) com.intellij.openapi.roots.ui.configuration.projectRoot(com.intellij.openapi.roots.ui.configuration.projectRoot) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) ChangeListener(javax.swing.event.ChangeListener) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) FlexLibraryType(com.intellij.lang.javascript.flex.library.FlexLibraryType) FlexBuildConfigurationsExtension(com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension) ChangeEvent(javax.swing.event.ChangeEvent) OrderRootType(com.intellij.openapi.roots.OrderRootType) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) com.intellij.ui(com.intellij.ui) ChooseLibrariesFromTablesDialog(com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) List(java.util.List) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider) FlexLibraryIdGenerator(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexLibraryIdGenerator) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) java.awt.event(java.awt.event) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) SdkType(com.intellij.openapi.projectRoots.SdkType) NamedConfigurable(com.intellij.openapi.ui.NamedConfigurable) NotNull(org.jetbrains.annotations.NotNull) FilteringIterator(com.intellij.util.containers.FilteringIterator) java.util(java.util) OutputType(com.intellij.flex.model.bc.OutputType) ContainerUtil(com.intellij.util.containers.ContainerUtil) MessageFormat(java.text.MessageFormat) History(com.intellij.ui.navigation.History) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2) TableCellEditor(javax.swing.table.TableCellEditor) Factory(com.intellij.lang.javascript.flex.projectStructure.model.impl.Factory) Project(com.intellij.openapi.project.Project) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) CreateModuleLibraryChooser(com.intellij.openapi.roots.ui.configuration.classpath.CreateModuleLibraryChooser) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) PlatformIcons(com.intellij.util.PlatformIcons) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) com.intellij.openapi.roots.libraries(com.intellij.openapi.roots.libraries) ProjectBundle(com.intellij.openapi.project.ProjectBundle) StringUtil(com.intellij.openapi.util.text.StringUtil) SdkModel(com.intellij.openapi.projectRoots.SdkModel) ComboBoxTableRenderer(com.intellij.openapi.ui.ComboBoxTableRenderer) com.intellij.lang.javascript.flex.projectStructure.model(com.intellij.lang.javascript.flex.projectStructure.model) Disposable(com.intellij.openapi.Disposable) Sdk(com.intellij.openapi.projectRoots.Sdk) JBPopup(com.intellij.openapi.ui.popup.JBPopup) BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) LinkageType(com.intellij.flex.model.bc.LinkageType) FlexProjectRootsUtil(com.intellij.lang.javascript.flex.projectStructure.options.FlexProjectRootsUtil) java.awt(java.awt) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Place(com.intellij.ui.navigation.Place) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) FlexIcons(icons.FlexIcons) OrderEntryAppearanceService(com.intellij.openapi.roots.ui.OrderEntryAppearanceService) ProjectStructureConfigurable(com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable) UIRootConfigurationAccessor(com.intellij.openapi.roots.ui.configuration.UIRootConfigurationAccessor) FlexLibraryProperties(com.intellij.lang.javascript.flex.library.FlexLibraryProperties) javax.swing(javax.swing) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 30 with LibraryEx

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

the class ProjectSettingsService method getLibrarySettingsConfigurable.

@Nullable
private static Configurable getLibrarySettingsConfigurable(OrderEntry orderEntry) {
    if (!(orderEntry instanceof LibraryOrderEntry))
        return null;
    LibraryOrderEntry libOrderEntry = (LibraryOrderEntry) orderEntry;
    Library lib = libOrderEntry.getLibrary();
    if (lib instanceof LibraryEx) {
        Project project = libOrderEntry.getOwnerModule().getProject();
        PersistentLibraryKind<?> libKind = ((LibraryEx) lib).getKind();
        if (libKind != null) {
            return LibrarySettingsProvider.getAdditionalSettingsConfigurable(project, libKind);
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) Nullable(org.jetbrains.annotations.Nullable)

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