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;
}
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);
}
}
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();
}
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;
}
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;
}
Aggregations