Search in sources :

Example 16 with WriteExternalException

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

the class CfmlUnitRunConfiguration method clone.

@SuppressWarnings({ "CloneDoesntDeclareCloneNotSupportedException", "CloneDoesntCallSuperClone" })
@Override
public CfmlUnitRunConfiguration clone() {
    try {
        Element element = new Element("tmp");
        writeExternal(element);
        CfmlUnitRunConfiguration clone = new CfmlUnitRunConfiguration(getProject(), getFactory(), getName());
        clone.readExternal(element);
        return clone;
    } catch (WriteExternalException e) {
        throw new RuntimeException(e);
    }
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 17 with WriteExternalException

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

the class PsiAwareTextEditorProvider method writeState.

@Override
public void writeState(@NotNull final FileEditorState _state, @NotNull final Project project, @NotNull final Element element) {
    super.writeState(_state, project, element);
    TextEditorState state = (TextEditorState) _state;
    // Foldings
    CodeFoldingState foldingState = state.getFoldingState();
    if (foldingState != null) {
        Element e = new Element(FOLDING_ELEMENT);
        try {
            CodeFoldingManager.getInstance(project).writeFoldingState(foldingState, e);
        } catch (WriteExternalException e1) {
        //ignore
        }
        element.addContent(e);
    }
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 18 with WriteExternalException

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

the class DeployToServerRunConfiguration method clone.

@Override
public RunConfiguration clone() {
    Element element = new Element("tag");
    try {
        writeExternal(element);
    } catch (WriteExternalException e) {
        LOG.error(e);
    }
    DeployToServerRunConfiguration result = (DeployToServerRunConfiguration) super.clone();
    try {
        result.readExternal(element);
    } catch (InvalidDataException e) {
        LOG.error(e);
    }
    return result;
}
Also used : Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 19 with WriteExternalException

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

the class SystemFileProcessor method encodeFileText.

@Nullable
@Override
protected String encodeFileText(String content, VirtualFile file, Project project) throws IOException {
    final String fileName = file.getName();
    if (file.getParent().getName().equals(Project.DIRECTORY_STORE_FOLDER) && fileName.equals("workspace.xml")) {
        List<Object> componentList = new ArrayList<>();
        for (String componentName : COMPONENT_NAMES) {
            Object component = project.getComponent(componentName);
            if (component == null) {
                try {
                    Class<?> aClass = Class.forName(componentName);
                    component = project.getComponent(aClass);
                    if (component == null) {
                        component = ServiceManager.getService(project, aClass);
                    }
                } catch (ClassNotFoundException ignore) {
                }
            }
            ContainerUtil.addIfNotNull(componentList, component);
        }
        if (!componentList.isEmpty()) {
            final Element root = new Element("project");
            for (final Object component : componentList) {
                final Element element = new Element("component");
                element.setAttribute("name", ComponentManagerImpl.getComponentName(component));
                root.addContent(element);
                ApplicationManager.getApplication().invokeAndWait(() -> {
                    if (component instanceof JDOMExternalizable) {
                        try {
                            ((JDOMExternalizable) component).writeExternal(element);
                        } catch (WriteExternalException ignore) {
                            LOG.error(ignore);
                        }
                    } else if (component instanceof PersistentStateComponent) {
                        Object state = WriteAction.compute(() -> ((PersistentStateComponent) component).getState());
                        if (state == null) {
                            return;
                        }
                        Element element1 = state instanceof Element ? (Element) state : XmlSerializer.serialize(state);
                        element.addContent(element1.cloneContent());
                        element.setAttribute("name", StoreUtil.getStateSpec((PersistentStateComponent) component).name());
                    }
                }, ModalityState.defaultModalityState());
            }
            PathMacroManager.getInstance(project).collapsePaths(root);
            return JDOMUtil.writeElement(root);
        }
    }
    return null;
}
Also used : PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) Element(org.jdom.Element) JDOMExternalizable(com.intellij.openapi.util.JDOMExternalizable) ArrayList(java.util.ArrayList) WriteExternalException(com.intellij.openapi.util.WriteExternalException) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with WriteExternalException

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

the class ProjectFacetManagerImpl method setDefaultConfiguration.

@Override
public <C extends FacetConfiguration> void setDefaultConfiguration(@NotNull final FacetType<?, C> facetType, @NotNull final C configuration) {
    Map<String, DefaultFacetConfigurationState> defaultConfigurations = myState.getDefaultConfigurations();
    DefaultFacetConfigurationState state = defaultConfigurations.get(facetType.getStringId());
    if (state == null) {
        state = new DefaultFacetConfigurationState();
        defaultConfigurations.put(facetType.getStringId(), state);
    }
    try {
        Element element = FacetUtil.saveFacetConfiguration(configuration);
        state.setDefaultConfiguration(element);
    } catch (WriteExternalException e) {
        LOG.info(e);
    }
}
Also used : 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