@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
@Override
public void run(@NotNull final ProgressIndicator indicator) {
EventManagerImpl.getInstance().fireEvent(new BugReporterEventImpl(Operation.ANALYSIS_STARTED, null, 0, project.getName()));
setProgressIndicator(indicator);
indicator.setFraction(0.0);
indicator.setIndeterminate(false);
indicator.setText(fileToImport);
try {
_bugCollection = new SortedBugCollection();
final FindBugsPlugin pluginComponent = IdeaUtilImpl.getPluginComponent(project);
_importBugCollection = _bugCollection.createEmptyCollectionWithMetadata();
final edu.umd.cs.findbugs.Project importProject = _importBugCollection.getProject();
importProject.setGuiCallback(new PluginGuiCallback(pluginComponent));
_importBugCollection.setDoNotUseCloud(true);
for (final Plugin plugin : Plugin.getAllPlugins()) {
importProject.setPluginStatusTrinary(plugin.getPluginId(), !preferences.isPluginDisabled(plugin.getPluginId()));
}
_importBugCollection.readXML(fileToImport);
final ProjectStats projectStats = _importBugCollection.getProjectStats();
int bugCount = 0;
for (final BugInstance bugInstance : _importBugCollection) {
if (indicator.isCanceled()) {
EventManagerImpl.getInstance().fireEvent(new BugReporterEventImpl(Operation.ANALYSIS_ABORTED, project.getName()));
Thread.currentThread().interrupt();
return;
}
final Integer bugCounter = bugCount++;
final double fraction = bugCounter.doubleValue() / projectStats.getTotalBugs();
indicator.setFraction(fraction);
indicator.setText2("Importing bug '" + bugCount + "' of '" + projectStats.getTotalBugs() + "' - " + bugInstance.getMessageWithoutPrefix());
EventManagerImpl.getInstance().fireEvent(new BugReporterEventImpl(Operation.NEW_BUG_INSTANCE, bugInstance, bugCounter, projectStats, project.getName()));
}
showToolWindowNotifier(project, "Imported bug collection from '" + fileToImport + "'.", MessageType.INFO);
_importBugCollection.setDoNotUseCloud(false);
_importBugCollection.setTimestamp(System.currentTimeMillis());
_importBugCollection.reinitializeCloud();
} catch (final IOException e1) {
EventManagerImpl.getInstance().fireEvent(new BugReporterEventImpl(Operation.ANALYSIS_ABORTED, project.getName()));
final String message = "Import failed";
showToolWindowNotifier(project, message, MessageType.ERROR);
LOGGER.error(message, e1);
} catch (final DocumentException e1) {
EventManagerImpl.getInstance().fireEvent(new BugReporterEventImpl(Operation.ANALYSIS_ABORTED, project.getName()));
final String message = "Import failed";
showToolWindowNotifier(project, message, MessageType.ERROR);
LOGGER.error(message, e1);
} finally {
EventManagerImpl.getInstance().fireEvent(new BugReporterEventImpl(Operation.ANALYSIS_FINISHED, null, _importBugCollection, project.getName()));
_importBugCollection = null;
Thread.currentThread().interrupt();
}
}