in src/main/java/org/jetbrains/plugins/spotbugs/actions/ExportBugCollection.java [74:149]
void actionPerformedImpl(
@NotNull final AnActionEvent e,
@NotNull final Project project,
@NotNull final ToolWindow toolWindow,
@NotNull final FindBugsState state
) {
final ToolWindowPanel panel = ToolWindowPanel.getInstance(toolWindow);
if (panel == null) {
return;
}
final ExportBugCollectionDialog dialog = new ExportBugCollectionDialog(project);
dialog.reset();
if (!dialog.showAndGet()) {
return;
}
dialog.apply();
final WorkspaceSettings workspaceSettings = WorkspaceSettings.getInstance(project);
final String exportDir = workspaceSettings.exportBugCollectionDirectory;
final boolean exportXml = workspaceSettings.exportBugCollectionAsXml;
final boolean exportHtml = workspaceSettings.exportBugCollectionAsHtml;
final boolean createSubDir = workspaceSettings.exportBugCollectionCreateSubDirectory;
final boolean openInBrowser = workspaceSettings.openExportedHtmlBugCollectionInBrowser;
final File exportDirPath = new File(exportDir);
ExportErrorType errorType = ExportErrorType.from(exportDirPath);
if (errorType != null) {
showError(errorType.getText(exportDirPath));
actionPerformedImpl(e, project, toolWindow, state);
return;
}
final FindBugsResult result = panel.getResult();
new Task.Backgroundable(project, ResourcesLoader.getString("export.progress.title"), false) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
try {
FileUtilFb.mkdirs(exportDirPath);
File finalExportDir = exportDirPath;
final String currentTime = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.ENGLISH).format(new Date());
if (createSubDir) {
final String dirName = "spotbugs-result-" + project.getName() + "_" + currentTime;
finalExportDir = new File(exportDirPath, dirName);
FileUtilFb.mkdirs(finalExportDir);
}
final boolean multiModule = result.getResults().size() > 1;
for (final Map.Entry<edu.umd.cs.findbugs.Project, SortedBugCollection> entry : result.getResults().entrySet()) {
final String fileName;
if (createSubDir) {
if (multiModule && entry.getKey() instanceof FindBugsProject) {
fileName = ((FindBugsProject) entry.getKey()).getModule().getName();
} else {
fileName = "result";
}
} else {
fileName = "spotbugs-result-" + entry.getKey().getProjectName() + "_" + currentTime;
}
exportImpl(
entry.getValue(),
finalExportDir,
fileName,
exportXml,
exportHtml,
openInBrowser
);
}
} catch (final Exception e) {
throw ErrorUtil.toUnchecked(e);
}
}
}.queue();
}