Search in sources :

Example 11 with WriteExternalException

use of com.intellij.openapi.util.WriteExternalException in project intellij-community by JetBrains.

the class ModuleRunConfigurationManager method getState.

@Nullable
@Override
public Element getState() {
    try {
        final Element e = new Element("state");
        writeExternal(e);
        return e;
    } catch (WriteExternalException e1) {
        LOG.error(e1);
        return null;
    }
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with WriteExternalException

use of com.intellij.openapi.util.WriteExternalException in project intellij by bazelbuild.

the class BlazeCommandRunConfiguration method writeExternal.

@Override
@SuppressWarnings("ThrowsUncheckedException")
public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    if (sanitizeCorruptedDefaultRunConfiguration(element)) {
        logger.info("Serializing an apparently corrupted run configuration:\n" + new XMLOutputter().outputString(element), new Exception());
    }
    if (targetPattern != null) {
        Element targetElement = new Element(TARGET_TAG);
        targetElement.setText(targetPattern);
        if (targetKind != null) {
            targetElement.setAttribute(KIND_ATTR, targetKind.toString());
        }
        element.addContent(targetElement);
    }
    if (keepInSync != null) {
        element.setAttribute(KEEP_IN_SYNC_TAG, Boolean.toString(keepInSync));
    }
    element.setAttribute(HANDLER_ATTR, handlerProvider.getId());
    handler.getState().writeExternal(elementState);
    // copy our internal state to the provided Element, skipping items already present
    Set<String> baseAttributes = element.getAttributes().stream().map(Attribute::getName).collect(Collectors.toSet());
    for (Attribute attribute : elementState.getAttributes()) {
        if (!baseAttributes.contains(attribute.getName())) {
            element.setAttribute(attribute.clone());
        }
    }
    Set<String> baseChildren = element.getChildren().stream().map(Element::getName).collect(Collectors.toSet());
    // The method tag is written by RunManagerImpl *after* this writeExternal call,
    // so it isn't already present.
    // We still have to avoid writing it ourselves, or we wind up duplicating it.
    baseChildren.add(METHOD_TAG);
    for (Element child : elementState.getChildren()) {
        if (!baseChildren.contains(child.getName())) {
            element.addContent(child.clone());
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Attribute(org.jdom.Attribute) Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException) RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) ExecutionException(com.intellij.execution.ExecutionException) InvalidDataException(com.intellij.openapi.util.InvalidDataException)

Example 13 with WriteExternalException

use of com.intellij.openapi.util.WriteExternalException in project intellij by bazelbuild.

the class RunConfigurationSerializer method writeToXml.

public static Element writeToXml(RunConfiguration configuration) {
    RunnerAndConfigurationSettings settings = RunManagerImpl.getInstanceImpl(configuration.getProject()).getSettings(configuration);
    Element element = new Element("configuration");
    try {
        runWithPathVariableSet(configuration.getProject(), () -> ((RunnerAndConfigurationSettingsImpl) settings).writeExternal(element));
    } catch (WriteExternalException e) {
        logger.warn("Error serializing run configuration to XML", e);
    }
    return element;
}
Also used : Element(org.jdom.Element) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 14 with WriteExternalException

use of com.intellij.openapi.util.WriteExternalException in project netbeans-mmd-plugin by raydac.

the class MindMapFacetConfiguration method writeExternal.

@Override
public void writeExternal(final Element element) throws WriteExternalException {
    try {
        for (final String key : this.preferences.keys()) {
            Element el = element.getChild(key);
            if (el == null) {
                el = new Element(key);
                element.addContent(el);
            }
            el.setText(this.preferences.get(key, null));
        }
    } catch (Exception ex) {
        throw new WriteExternalException("Can't write preferences", ex);
    }
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 15 with WriteExternalException

use of com.intellij.openapi.util.WriteExternalException in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationTestCase method doTestProducedConfigurations.

protected void doTestProducedConfigurations(@Nullable PsiElement context) {
    assertNotNull(context);
    ConfigurationContext configurationContext = new ConfigurationContext(context);
    List<ConfigurationFromContext> configurationAndSettings = configurationContext.getConfigurationsFromContext();
    Element configurationsElement = new Element("configurations");
    if (configurationAndSettings != null) {
        for (ConfigurationFromContext setting : configurationAndSettings) {
            try {
                RunConfiguration configuration = setting.getConfiguration();
                Element configurationElement = new Element("configurations");
                configurationElement.setAttribute("name", configuration.getName());
                configurationElement.setAttribute("class", configuration.getClass().getSimpleName());
                configuration.writeExternal(configurationElement);
                configurationsElement.addContent(configurationElement);
            } catch (WriteExternalException e) {
                throw new RuntimeException(e);
            }
        }
    }
    assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + ".xml", JDOMUtil.writeElement(configurationsElement));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Aggregations

WriteExternalException (com.intellij.openapi.util.WriteExternalException)27 Element (org.jdom.Element)27 InvalidDataException (com.intellij.openapi.util.InvalidDataException)7 Nullable (org.jetbrains.annotations.Nullable)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)2 PsiElement (com.intellij.psi.PsiElement)2 NonNls (org.jetbrains.annotations.NonNls)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionException (com.intellij.execution.ExecutionException)1 Executor (com.intellij.execution.Executor)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)1 LocatableConfiguration (com.intellij.execution.configurations.LocatableConfiguration)1 LocatableConfigurationBase (com.intellij.execution.configurations.LocatableConfigurationBase)1 RunProfileState (com.intellij.execution.configurations.RunProfileState)1 RuntimeConfigurationException (com.intellij.execution.configurations.RuntimeConfigurationException)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1