void (@NotNull AnActionEvent e) { final Project project = e.getProject(); LOG.assertTrue(project != null); final ExportTestResultsConfiguration config = ExportTestResultsConfiguration.getInstance(project); final String name = ExecutionBundle.message("export.test.results.filename", PathUtil.suggestFileName(myRunConfiguration.getName())); String filename = name + "." + config.getExportFormat().getDefaultExtension(); boolean showDialog = true; while (showDialog) { final ExportTestResultsDialog d = new ExportTestResultsDialog(project, config, filename); if (!d.showAndGet()) { return; } filename = d.getFileName(); showDialog = getOutputFile(config, project, filename).exists() && Messages.showOkCancelDialog(project, ExecutionBundle.message("export.test.results.file.exists.message", filename), ExecutionBundle.message("export.test.results.file.exists.title"), TestRunnerBundle.message("export.test.results.overwrite.button.text"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon() ) != Messages.OK; } final File outputFile = getOutputFile(config, project, filename); File parentFile = outputFile.getParentFile(); final VirtualFile parent = parentFile.exists() || parentFile.mkdirs() ? LocalFileSystem.getInstance().refreshAndFindFileByIoFile(parentFile) : null; if (parent == null || !parent.isValid()) { showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ExecutionBundle.message("failed.to.create.output.file", outputFile.getPath())), null); return; } ProgressManager.getInstance().run( new Task.Backgroundable(project, ExecutionBundle.message("export.test.results.task.name"), false, PerformInBackgroundOption.ALWAYS_BACKGROUND) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); try { if (!writeOutputFile(config, outputFile)) return; } catch (IOException | SAXException | TransformerException ex) { LOG.warn(ex); showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ex.getMessage()), null); return; } catch (RuntimeException ex) { File tempFile; try { tempFile = FileUtil.createTempFile("", "_xml"); } catch (IOException exception) { LOG.error("Failed to create temp file", exception); LOG.error("Failed to export test results", ex); return; } try { ExportTestResultsConfiguration c = new ExportTestResultsConfiguration(); c.setExportFormat(ExportTestResultsConfiguration.ExportFormat.Xml); c.setOpenResults(false); writeOutputFile(c, tempFile); } catch (Throwable ignored) { } LOG.error("Failed to export test results", ex, AttachmentFactory.createAttachment(tempFile.toPath(), false)); FileUtil.delete(tempFile); return; } final Ref<VirtualFile> result = new Ref<>(); final Ref<String> error = new Ref<>(); ApplicationManager.getApplication().invokeAndWait(() -> { result.set(WriteAction.compute(() -> { try { VirtualFile child = parent.findChild(outputFile.getName()); return child == null ? parent.createChildData(this, outputFile.getName()) : child; } catch (IOException e) { LOG.warn(e); error.set(e.getMessage()); return null; } })); }); if (!result.isNull()) { if (config.isOpenResults()) { openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml); } else { HyperlinkListener listener = new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml); } } }; showBalloon(project, MessageType.INFO, ExecutionBundle.message("export.test.results.succeeded", outputFile.getName()), listener); } } else { showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", error.get()), null); } } }); }