Search in sources :

Example 21 with WriteExternalException

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

the class RunInspectionIntention method createProfile.

@NotNull
public static InspectionProfileImpl createProfile(@NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionManagerEx managerEx, @Nullable PsiElement psiElement) {
    InspectionProfileImpl rootProfile = InspectionProfileManager.getInstance().getCurrentProfile();
    LinkedHashSet<InspectionToolWrapper<?, ?>> allWrappers = new LinkedHashSet<>();
    allWrappers.add(toolWrapper);
    rootProfile.collectDependentInspections(toolWrapper, allWrappers, managerEx.getProject());
    List<InspectionToolWrapper<?, ?>> toolWrappers = allWrappers.size() == 1 ? Collections.singletonList(allWrappers.iterator().next()) : new ArrayList<>(allWrappers);
    InspectionProfileImpl model = InspectionProfileKt.createSimple(toolWrapper.getDisplayName(), managerEx.getProject(), toolWrappers);
    try {
        Element element = new Element("toCopy");
        for (InspectionToolWrapper wrapper : toolWrappers) {
            wrapper.getTool().writeSettings(element);
            InspectionToolWrapper tw = psiElement == null ? model.getInspectionTool(wrapper.getShortName(), managerEx.getProject()) : model.getInspectionTool(wrapper.getShortName(), psiElement);
            tw.getTool().readSettings(element);
        }
    } catch (WriteExternalException | InvalidDataException ignored) {
    }
    model.setSingleTool(toolWrapper.getShortName());
    return model;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with WriteExternalException

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

the class LibraryTest method serialize.

private static Element serialize(Library library) {
    try {
        Element element = new Element("root");
        library.writeExternal(element);
        return element;
    } catch (WriteExternalException e) {
        throw new AssertionError(e);
    }
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 23 with WriteExternalException

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

the class TestResultsXmlFormatter method execute.

private void execute() throws SAXException {
    myResultHandler.startDocument();
    TreeMap<String, Integer> counts = new TreeMap<>((o1, o2) -> {
        if (TOTAL_STATUS.equals(o1) && !TOTAL_STATUS.equals(o2))
            return -1;
        if (TOTAL_STATUS.equals(o2) && !TOTAL_STATUS.equals(o1))
            return 1;
        return o1.compareTo(o2);
    });
    for (AbstractTestProxy node : myTestRoot.getAllTests()) {
        if (!node.isLeaf())
            continue;
        String status = getStatusString(node);
        increment(counts, status);
        increment(counts, TOTAL_STATUS);
    }
    Map<String, String> runAttrs = new HashMap<>();
    runAttrs.put(ATTR_NAME, myRuntimeConfiguration.getName());
    String footerText = ExecutionBundle.message("export.test.results.footer", ApplicationNamesInfo.getInstance().getFullProductName(), new SimpleDateFormat().format(new Date()));
    runAttrs.put(ATTR_FOORTER_TEXT, footerText);
    Long duration = myTestRoot.getDuration();
    if (duration != null) {
        runAttrs.put(ATTR_DURATION, String.valueOf(duration));
    }
    startElement(ELEM_RUN, runAttrs);
    for (Map.Entry<String, Integer> entry : counts.entrySet()) {
        Map<String, String> a = new HashMap<>();
        a.put(ATTR_NAME, entry.getKey());
        a.put(ATTR_VALUE, String.valueOf(entry.getValue()));
        startElement(ELEM_COUNT, a);
        endElement(ELEM_COUNT);
    }
    final Element config = new Element("config");
    try {
        myRuntimeConfiguration.writeExternal(config);
        config.setAttribute("configId", myRuntimeConfiguration.getType().getId());
        config.setAttribute("name", myRuntimeConfiguration.getName());
        if (!DefaultExecutionTarget.INSTANCE.equals(myExecutionTarget)) {
            config.setAttribute("target", myExecutionTarget.getId());
        }
    } catch (WriteExternalException ignore) {
    }
    processJDomElement(config);
    if (myTestRoot instanceof TestProxyRoot) {
        final String presentation = ((TestProxyRoot) myTestRoot).getPresentation();
        if (presentation != null) {
            final LinkedHashMap<String, String> rootAttrs = new LinkedHashMap<>();
            rootAttrs.put("name", presentation);
            final String comment = ((TestProxyRoot) myTestRoot).getComment();
            if (comment != null) {
                rootAttrs.put("comment", comment);
            }
            final String rootLocation = ((TestProxyRoot) myTestRoot).getRootLocation();
            if (rootLocation != null) {
                rootAttrs.put("location", rootLocation);
            }
            startElement(ROOT_ELEM, rootAttrs);
            writeOutput(myTestRoot);
            endElement(ROOT_ELEM);
        }
    }
    if (myTestRoot.shouldSkipRootNodeForExport()) {
        for (AbstractTestProxy node : myTestRoot.getChildren()) {
            processNode(node);
        }
    } else {
        processNode(myTestRoot);
    }
    endElement(ELEM_RUN);
    myResultHandler.endDocument();
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with WriteExternalException

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

the class InspectionElementsMergerBase method merge.

protected Element merge(Map<String, Element> inspectionElements, boolean includeDefaults) {
    LinkedHashMap<String, Element> scopes = null;
    List<Element> content = null;
    boolean enabled = false;
    String level = null;
    for (String sourceToolName : getSourceToolNames()) {
        Element sourceElement = inspectionElements.get(sourceToolName);
        if (sourceElement == null) {
            if (includeDefaults) {
                try {
                    sourceElement = writeOldSettings(sourceToolName);
                } catch (WriteExternalException ignored) {
                }
            } else {
                enabled |= isEnabledByDefault(sourceToolName);
                if (level == null) {
                    level = getDefaultSeverityLevel(sourceToolName);
                }
            }
        }
        if (sourceElement != null) {
            if (content == null) {
                content = new ArrayList<>();
                scopes = new LinkedHashMap<>();
            }
            collectContent(sourceElement, content, scopes);
            enabled |= Boolean.parseBoolean(sourceElement.getAttributeValue(ToolsImpl.ENABLED_ATTRIBUTE));
            if (level == null) {
                level = getLevel(sourceElement);
            }
        }
    }
    if (content != null && !content.isEmpty()) {
        final Element toolElement = new Element(InspectionProfileImpl.INSPECTION_TOOL_TAG);
        toolElement.setAttribute(InspectionProfileImpl.CLASS_TAG, getMergedToolName());
        toolElement.setAttribute(ToolsImpl.ENABLED_ATTRIBUTE, String.valueOf(enabled));
        if (level != null) {
            toolElement.setAttribute(ToolsImpl.LEVEL_ATTRIBUTE, level);
        }
        toolElement.setAttribute(ToolsImpl.ENABLED_BY_DEFAULT_ATTRIBUTE, String.valueOf(enabled));
        for (Element scopeEl : scopes.values()) {
            toolElement.addContent(scopeEl);
        }
        for (Element element : content) {
            toolElement.addContent(element);
        }
        return toolElement;
    }
    return null;
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 25 with WriteExternalException

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

the class ExternalProjectsViewImpl method getState.

@Nullable
public ExternalProjectsViewState getState() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myStructure != null) {
        try {
            myState.treeState = new Element("root");
            TreeState.createOn(myTree).writeExternal(myState.treeState);
        } catch (WriteExternalException e) {
            LOG.warn(e);
        }
    }
    return myState;
}
Also used : Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException) Nullable(org.jetbrains.annotations.Nullable)

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