Search in sources :

Example 1 with FlexCompositeSdk

use of com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk in project intellij-plugins by JetBrains.

the class FlexCompositeSdkProjectViewStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (!(parent instanceof ExternalLibrariesNode)) {
        return children;
    }
    Set<Sdk> processedSdks = new HashSet<>();
    Collection<AbstractTreeNode> result = new ArrayList<>();
    for (AbstractTreeNode child : children) {
        Object value = child.getValue();
        if (!(value instanceof NamedLibraryElement)) {
            result.add(child);
            continue;
        }
        NamedLibraryElement libraryElement = (NamedLibraryElement) value;
        OrderEntry orderEntry = libraryElement.getOrderEntry();
        if (!(orderEntry instanceof JdkOrderEntry)) {
            result.add(child);
            continue;
        }
        Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
        if (!(sdk instanceof FlexCompositeSdk)) {
            result.add(child);
            continue;
        }
        Sdk[] sdks = ((FlexCompositeSdk) sdk).getSdks();
        for (Sdk individualSdk : sdks) {
            if (processedSdks.add(individualSdk)) {
                IndividualSdkOrderEntry entry = new IndividualSdkOrderEntry(individualSdk, orderEntry.getOwnerModule());
                result.add(new NamedLibraryElementNode(parent.getProject(), new NamedLibraryElement(null, entry), ((ExternalLibrariesNode) parent).getSettings()));
            }
        }
    }
    return result;
}
Also used : FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) ExternalLibrariesNode(com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) HashSet(com.intellij.util.containers.hash.HashSet) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FlexCompositeSdk

use of com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk in project intellij-plugins by JetBrains.

the class FlexProjectConfigurationEditor method commit.

public void commit() throws ConfigurationException {
    final Map<Pair<String, String>, String> renamedConfigs = new HashMap<>();
    for (Module module : myModule2Editors.keySet()) {
        ModifiableRootModel modifiableModel = myProvider.getModuleModifiableModel(module);
        Collection<String> usedModulesLibrariesIds = new ArrayList<>();
        // ---------------- SDK and shared libraries entries ----------------------
        // Library -> add_library_entry_flag
        Map<Library, Boolean> librariesToAdd = new LinkedHashMap<>();
        final Collection<String> sdkNames = new HashSet<>();
        for (Editor editor : myModule2Editors.get(module)) {
            final SdkEntry sdkEntry = editor.getDependencies().getSdkEntry();
            if (sdkEntry != null) {
                sdkNames.add(sdkEntry.getName());
            }
            for (DependencyEntry dependencyEntry : editor.getDependencies().getEntries()) {
                if (dependencyEntry instanceof ModuleLibraryEntry) {
                    ModuleLibraryEntry moduleLibraryEntry = (ModuleLibraryEntry) dependencyEntry;
                    usedModulesLibrariesIds.add(moduleLibraryEntry.getLibraryId());
                }
                if (dependencyEntry instanceof SharedLibraryEntry) {
                    SharedLibraryEntry sharedLibraryEntry = (SharedLibraryEntry) dependencyEntry;
                    Library library = myProvider.findSourceLibraryForLiveName(sharedLibraryEntry.getLibraryName(), sharedLibraryEntry.getLibraryLevel());
                    if (library != null) {
                        librariesToAdd.put(library, true);
                    }
                }
            }
            String originalName = editor.getOriginalName();
            if (originalName != null && !originalName.equals(editor.getName())) {
                renamedConfigs.put(Pair.create(module.getName(), originalName), editor.getName());
            }
        }
        final Sdk sdk;
        if (sdkNames.isEmpty()) {
            sdk = null;
        } else if (sdkNames.size() == 1) {
            sdk = FlexSdkUtils.findFlexOrFlexmojosSdk(sdkNames.iterator().next());
        } else {
            sdk = new FlexCompositeSdk(ArrayUtil.toStringArray(sdkNames));
        }
        modifiableModel.setSdk(sdk);
        Collection<OrderEntry> entriesToRemove = new ArrayList<>();
        for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
            if (orderEntry instanceof LibraryOrderEntry) {
                if (((LibraryOrderEntry) orderEntry).isModuleLevel()) {
                    LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
                    if (FlexProjectRootsUtil.isFlexLibrary(library) && !usedModulesLibrariesIds.contains(FlexProjectRootsUtil.getLibraryId(library))) {
                        entriesToRemove.add(orderEntry);
                    }
                } else {
                    LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
                    if (librariesToAdd.containsKey(library)) {
                        // entry already exists for this library
                        librariesToAdd.put(library, false);
                    } else if (library != null && FlexProjectRootsUtil.isFlexLibrary(library)) {
                        entriesToRemove.add(orderEntry);
                    }
                }
            }
        }
        for (OrderEntry e : entriesToRemove) {
            modifiableModel.removeOrderEntry(e);
        }
        for (Library library : librariesToAdd.keySet()) {
            if (!((LibraryEx) library).isDisposed() && librariesToAdd.get(library) && myProvider.findSourceLibrary(library.getName(), library.getTable().getTableLevel()) != null) {
                modifiableModel.addLibraryEntry(library);
            }
        }
        // ---------------- modules entries ----------------------
        final Set<Module> modulesToAdd = new THashSet<>();
        for (Editor editor : myModule2Editors.get(module)) {
            for (DependencyEntry dependencyEntry : editor.getDependencies().getEntries()) {
                if (dependencyEntry instanceof BuildConfigurationEntry) {
                    final Module dependencyModule = findModuleWithBC((BuildConfigurationEntry) dependencyEntry);
                    if (dependencyModule != null && dependencyModule != module) {
                        modulesToAdd.add(dependencyModule);
                    }
                }
            }
        }
        List<OrderEntry> moduleOrderEntriesToRemove = ContainerUtil.filter(modifiableModel.getOrderEntries(), orderEntry -> orderEntry instanceof ModuleOrderEntry && !modulesToAdd.remove(((ModuleOrderEntry) orderEntry).getModule()));
        for (OrderEntry orderEntry : moduleOrderEntriesToRemove) {
            modifiableModel.removeOrderEntry(orderEntry);
        }
        for (Module moduleToAdd : modulesToAdd) {
            modifiableModel.addModuleOrderEntry(moduleToAdd);
        }
        for (OrderEntry entry : modifiableModel.getOrderEntries()) {
            if (entry instanceof ExportableOrderEntry) {
                // transitiveness will be filtered out in FlexOrderEnumeratorHandler if needed
                ((ExportableOrderEntry) entry).setExported(true);
            }
        }
    }
    // ---------------- do commit ----------------------
    Collection<Module> modulesWithChangedModifiableModel = ContainerUtil.findAll(myModule2Editors.keySet(), module -> myProvider.getModuleModifiableModel(module).isChanged());
    if (!modulesWithChangedModifiableModel.isEmpty()) {
        myProvider.commitModifiableModels();
        myModulesModelChangeEventDispatcher.getMulticaster().modulesModelsChanged(modulesWithChangedModifiableModel);
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        for (Module module : myModule2Editors.keySet()) {
            Function<Editor, FlexBuildConfigurationImpl> f = editor -> editor.commit();
            FlexBuildConfigurationImpl[] current = ContainerUtil.map2Array(myModule2Editors.get(module), FlexBuildConfigurationImpl.class, f);
            ((FlexBuildConfigurationManagerImpl) FlexBuildConfigurationManager.getInstance(module)).setBuildConfigurations(current);
        }
        if (myProject != null) {
            FlexBuildConfigurationManagerImpl.resetHighlighting(myProject);
            if (!renamedConfigs.isEmpty()) {
                myProject.getMessageBus().syncPublisher(FlexBuildConfigurationChangeListener.TOPIC).buildConfigurationsRenamed(renamedConfigs);
            }
        }
    });
}
Also used : FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) java.util(java.util) OutputType(com.intellij.flex.model.bc.OutputType) ArrayUtil(com.intellij.util.ArrayUtil) EventDispatcher(com.intellij.util.EventDispatcher) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) HashMap(com.intellij.util.containers.HashMap) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) FlexCommonUtils(com.intellij.flex.FlexCommonUtils) com.intellij.openapi.roots(com.intellij.openapi.roots) Library(com.intellij.openapi.roots.libraries.Library) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) FlexBCConfigurable(com.intellij.lang.javascript.flex.projectStructure.ui.FlexBCConfigurable) Project(com.intellij.openapi.project.Project) ModuleType(com.intellij.openapi.module.ModuleType) ChangeListener(javax.swing.event.ChangeListener) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) 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) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) LibraryTablesRegistrar(com.intellij.openapi.roots.libraries.LibraryTablesRegistrar) 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) BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) FlexProjectRootsUtil(com.intellij.lang.javascript.flex.projectStructure.options.FlexProjectRootsUtil) Nullable(org.jetbrains.annotations.Nullable) LibraryEditingUtil(com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil) Function(com.intellij.util.Function) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) FlexLibraryProperties(com.intellij.lang.javascript.flex.library.FlexLibraryProperties) Consumer(com.intellij.util.Consumer) HashMap(com.intellij.util.containers.HashMap) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Pair(com.intellij.openapi.util.Pair) THashSet(gnu.trove.THashSet) FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) THashSet(gnu.trove.THashSet) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

Aggregations

FlexCompositeSdk (com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 NotNull (org.jetbrains.annotations.NotNull)2 FlexCommonUtils (com.intellij.flex.FlexCommonUtils)1 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)1 OutputType (com.intellij.flex.model.bc.OutputType)1 TargetPlatform (com.intellij.flex.model.bc.TargetPlatform)1 ExternalLibrariesNode (com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode)1 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)1 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 FlexModuleType (com.intellij.lang.javascript.flex.FlexModuleType)1 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)1 FlexLibraryType (com.intellij.lang.javascript.flex.library.FlexLibraryType)1 FlexBCConfigurator (com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator)1 FlexBuildConfigurationsExtension (com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension)1 com.intellij.lang.javascript.flex.projectStructure.model (com.intellij.lang.javascript.flex.projectStructure.model)1 BCUtils (com.intellij.lang.javascript.flex.projectStructure.options.BCUtils)1 FlexProjectRootsUtil (com.intellij.lang.javascript.flex.projectStructure.options.FlexProjectRootsUtil)1 FlexBCConfigurable (com.intellij.lang.javascript.flex.projectStructure.ui.FlexBCConfigurable)1