Search in sources :

Example 36 with InvalidDataException

use of com.intellij.openapi.util.InvalidDataException in project intellij-plugins by JetBrains.

the class FlexModuleConverter method process.

@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
    FlexBuildConfigurationManagerImpl configurationManager = ConversionHelper.createBuildConfigurationManager();
    Collection<Element> orderEntriesToAdd = new ArrayList<>();
    Set<String> usedSdksNames = new HashSet<>();
    final Set<Element> usedModuleLibrariesEntries = new HashSet<>();
    if (isFlexModule(moduleSettings)) {
        ModifiableFlexBuildConfiguration newConfiguration = (ModifiableFlexBuildConfiguration) configurationManager.getBuildConfigurations()[0];
        newConfiguration.setName(generateModuleBcName(moduleSettings));
        Element oldConfigurationElement = moduleSettings.getComponentElement(FlexBuildConfiguration.COMPONENT_NAME);
        FlexBuildConfiguration oldConfiguration = oldConfigurationElement != null ? XmlSerializer.deserialize(oldConfigurationElement, FlexBuildConfiguration.class) : null;
        processConfiguration(oldConfiguration, newConfiguration, moduleSettings, false, null, usedSdksNames, orderEntriesToAdd, usedModuleLibrariesEntries);
        if (oldConfigurationElement != null) {
            oldConfigurationElement.detach();
        }
    } else {
        List<Element> flexFacets = getFlexFacets(moduleSettings);
        for (int i = 0; i < flexFacets.size(); i++) {
            Element facet = flexFacets.get(i);
            ModifiableFlexBuildConfiguration newConfiguration;
            if (i == 0) {
                newConfiguration = (ModifiableFlexBuildConfiguration) configurationManager.getBuildConfigurations()[0];
            } else {
                newConfiguration = ConversionHelper.createBuildConfiguration(configurationManager);
            }
            newConfiguration.setName(generateFacetBcName(flexFacets, facet));
            Element oldConfigurationElement = facet.getChild(JpsFacetSerializer.CONFIGURATION_TAG);
            if (oldConfigurationElement != null) {
                FlexBuildConfiguration oldConfiguration = XmlSerializer.deserialize(oldConfigurationElement, FlexBuildConfiguration.class);
                try {
                    readNamespaceAndManifestInfoList(oldConfigurationElement, oldConfiguration);
                    readConditionalCompilerDefinitionList(oldConfigurationElement, oldConfiguration);
                    readCssFilesList(oldConfigurationElement, oldConfiguration);
                } catch (InvalidDataException ignore) {
                /* unlucky */
                }
                final String facetSdkName = oldConfigurationElement.getAttributeValue(FLEX_SDK_ATTR_NAME);
                processConfiguration(oldConfiguration, newConfiguration, moduleSettings, true, facetSdkName, usedSdksNames, orderEntriesToAdd, usedModuleLibrariesEntries);
            } else {
                processConfiguration(null, newConfiguration, moduleSettings, true, null, usedSdksNames, orderEntriesToAdd, usedModuleLibrariesEntries);
            }
        }
        moduleSettings.setModuleType(FlexModuleType.MODULE_TYPE_ID);
        moduleSettings.getComponentElement(FacetManagerImpl.COMPONENT_NAME).getChildren(JpsFacetSerializer.FACET_TAG).removeAll(flexFacets);
    }
    Collection<Element> allEntries = new ArrayList<>();
    allEntries.addAll(usedModuleLibrariesEntries);
    allEntries.addAll(orderEntriesToAdd);
    for (Element orderEntry : allEntries) {
        if (DependencyScope.readExternal(orderEntry) == DependencyScope.TEST) {
            orderEntry.removeAttribute(DependencyScope.SCOPE_ATTR);
        }
    }
    if (!usedSdksNames.isEmpty()) {
        Element sdkEntryElement = new Element(OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME);
        sdkEntryElement.setAttribute(OrderEntryFactory.ORDER_ENTRY_TYPE_ATTR, "jdk");
        final String compositeSdkName = FlexCompositeSdk.getCompositeName(ArrayUtil.toStringArray(usedSdksNames));
        sdkEntryElement.setAttribute(ModuleJdkOrderEntryImpl.JDK_NAME_ATTR, compositeSdkName);
        sdkEntryElement.setAttribute(ModuleJdkOrderEntryImpl.JDK_TYPE_ATTR, FlexCompositeSdk.TYPE_ID);
        moduleSettings.getOrderEntries().add(sdkEntryElement);
    }
    Element rootManagerElement = JDomSerializationUtil.findOrCreateComponentElement(moduleSettings.getRootElement(), ModuleSettings.MODULE_ROOT_MANAGER_COMPONENT);
    rootManagerElement.addContent(orderEntriesToAdd);
    Element componentElement = JDomSerializationUtil.findOrCreateComponentElement(moduleSettings.getRootElement(), FlexBuildConfigurationManagerImpl.COMPONENT_NAME);
    addContent(ConversionHelper.serialize(configurationManager), componentElement);
    ignoreInapplicableFacets(moduleSettings);
}
Also used : FlexBuildConfigurationManagerImpl(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexBuildConfigurationManagerImpl) Element(org.jdom.Element) FlexBuildConfiguration(com.intellij.lang.javascript.flex.build.FlexBuildConfiguration) InvalidDataException(com.intellij.openapi.util.InvalidDataException)

Aggregations

InvalidDataException (com.intellij.openapi.util.InvalidDataException)36 Element (org.jdom.Element)24 WriteExternalException (com.intellij.openapi.util.WriteExternalException)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 JDOMException (org.jdom.JDOMException)5 NotNull (org.jetbrains.annotations.NotNull)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 List (java.util.List)4 TreeState (com.intellij.ide.util.treeView.TreeState)3 Nullable (org.jetbrains.annotations.Nullable)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 DescriptionAwareSchemeActions (com.intellij.application.options.schemes.DescriptionAwareSchemeActions)1 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)1 InspectionProfileModifiableModel (com.intellij.codeInspection.ex.InspectionProfileModifiableModel)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 UnsupportedExpressionException (com.intellij.debugger.engine.evaluation.expression.UnsupportedExpressionException)1 ExecutionException (com.intellij.execution.ExecutionException)1