use of edu.umd.cs.findbugs.DetectorFactory in project spotbugs by spotbugs.
the class BugInfoView method addDetectorInfo.
private void addDetectorInfo(StringBuilder text) {
DetectorFactory factory = bug.getDetectorFactory();
if (factory != null) {
Plugin plugin = factory.getPlugin();
if (!plugin.isCorePlugin()) {
text.append("<p><small><i>Reported by: ").append(factory.getFullName());
text.append("<br>Contributed by plugin: ").append(plugin.getPluginId());
text.append("<br>Provider: ").append(plugin.getProvider());
String website = plugin.getWebsite();
if (website != null && website.length() > 0) {
text.append(" (<a href=\"").append(website).append("\">");
text.append(website).append("</a>)");
}
text.append("</i></small>");
}
}
}
use of edu.umd.cs.findbugs.DetectorFactory in project spotbugs by spotbugs.
the class MarkerReporter method createMarkerAttributes.
/**
* @param mp
* @return attributes map which should be assigned to the given marker. If the map is empty,
* the marker shouldn't be generated
*/
@Nonnull
private Map<String, Object> createMarkerAttributes(MarkerParameter mp) {
Map<String, Object> attributes = new HashMap<>(23);
attributes.put(IMarker.LINE_NUMBER, mp.startLine);
attributes.put(PRIMARY_LINE, mp.primaryLine);
attributes.put(BUG_TYPE, mp.bug.getType());
attributes.put(PATTERN_TYPE, mp.bug.getAbbrev());
attributes.put(RANK, Integer.valueOf(mp.bug.getBugRank()));
attributes.put(PRIO_AKA_CONFIDENCE, MarkerConfidence.getConfidence(mp.bug.getPriority()).name());
long seqNum = mp.bug.getFirstVersion();
if (seqNum == 0) {
attributes.put(FIRST_VERSION, "-1");
} else {
AppVersion theVersion = collection.getAppVersionFromSequenceNumber(seqNum);
if (theVersion == null) {
attributes.put(FIRST_VERSION, "Cannot find AppVersion: seqnum=" + seqNum + "; collection seqnum=" + collection.getSequenceNumber());
} else {
attributes.put(FIRST_VERSION, Long.toString(theVersion.getTimestamp()));
}
}
try {
attributes.put(IMarker.MESSAGE, getMessage(mp));
} catch (RuntimeException e) {
FindbugsPlugin.getDefault().logException(e, "Error generating msg for " + mp.bug.getType() + ", attributes: " + attributes);
attributes.clear();
return attributes;
}
attributes.put(IMarker.SEVERITY, mp.markerSeverity);
// Set unique id of warning, so we can easily refer back
// to it later: for example, when the user classifies the warning.
String uniqueId = mp.bug.getInstanceHash();
if (uniqueId != null) {
attributes.put(UNIQUE_ID, uniqueId);
}
// Set unique id of the plugin, so we can easily refer back
// to it later: for example, when the user group markers by plugin.
DetectorFactory detectorFactory = mp.bug.getDetectorFactory();
if (detectorFactory != null) {
String pluginId = detectorFactory.getPlugin().getPluginId();
if (pluginId != null) {
attributes.put(DETECTOR_PLUGIN_ID, pluginId);
}
} else {
// Fix for loading bugs from XML: they do not have detector factory set, so we guess one
BugPattern pattern = mp.bug.getBugPattern();
Iterator<DetectorFactory> fit = DetectorFactoryCollection.instance().factoryIterator();
while (fit.hasNext()) {
DetectorFactory df2 = fit.next();
if (!df2.isReportingDetector()) {
continue;
}
Set<BugPattern> patterns = df2.getReportedBugPatterns();
if (patterns.contains(pattern)) {
String pluginId = df2.getPlugin().getPluginId();
if (pluginId != null) {
attributes.put(DETECTOR_PLUGIN_ID, pluginId);
break;
}
}
}
}
if (attributes.get(DETECTOR_PLUGIN_ID) == null) {
attributes.clear();
return attributes;
}
IJavaElement javaElt = mp.resource.getCorespondingJavaElement();
if (javaElt != null) {
attributes.put(UNIQUE_JAVA_ID, javaElt.getHandleIdentifier());
// Eclipse markers model doesn't allow to have markers
// attached to the (non-resource) part of the resource (like jar
// entry inside the jar)
// TODO we should add annotations to opened class file editors to
// show (missing)
// markers for single class file inside the jar. Otherwise we will
// show markers
// in the bug explorer view but NOT inside the class file editor
}
return attributes;
}
use of edu.umd.cs.findbugs.DetectorFactory in project spotbugs by spotbugs.
the class PrintBugDescriptions method print.
public void print() throws IOException {
// Ensure bug patterns are loaded
DetectorFactoryCollection factories = DetectorFactoryCollection.instance();
// Find all bug patterns reported by at least one non-disabled detector.
Collection<BugPattern> enabledPatternSet = new HashSet<BugPattern>();
for (Iterator<DetectorFactory> i = factories.factoryIterator(); i.hasNext(); ) {
DetectorFactory factory = i.next();
if (isEnabled(factory)) {
enabledPatternSet.addAll(factory.getReportedBugPatterns());
}
}
prologue();
Iterator<BugPattern> i = DetectorFactoryCollection.instance().bugPatternIterator();
while (i.hasNext()) {
BugPattern bugPattern = i.next();
if (!enabledPatternSet.contains(bugPattern)) {
continue;
}
emit(bugPattern);
}
epilogue();
}
use of edu.umd.cs.findbugs.DetectorFactory in project spotbugs by spotbugs.
the class DetectorConfigurationTab method populateAvailableRulesTable.
/**
* Populate the rule table
*/
private void populateAvailableRulesTable(IProject project) {
List<DetectorFactory> allAvailableList = new ArrayList<>();
factoriesToBugAbbrev = new HashMap<>();
Iterator<DetectorFactory> iterator = DetectorFactoryCollection.instance().factoryIterator();
while (iterator.hasNext()) {
DetectorFactory factory = iterator.next();
// Only configure non-hidden factories
if (factory.isHidden() && !isHiddenVisible()) {
continue;
}
allAvailableList.add(factory);
addBugsAbbreviation(factory);
}
availableFactoriesTableViewer.setInput(allAvailableList);
TableItem[] itemList = availableFactoriesTableViewer.getTable().getItems();
UserPreferences userPreferences = getCurrentProps();
for (int i = 0; i < itemList.length; i++) {
DetectorFactory rule = (DetectorFactory) itemList[i].getData();
// set enabled if defined in configuration
if (userPreferences.isDetectorEnabled(rule)) {
itemList[i].setChecked(true);
}
}
}
use of edu.umd.cs.findbugs.DetectorFactory in project spotbugs by spotbugs.
the class UserPreferences method enableAllDetectors.
/**
* Enable or disable all known Detectors.
*
* @param enable
* true if all detectors should be enabled, false if they should
* all be disabled
*/
public void enableAllDetectors(boolean enable) {
detectorEnablementMap.clear();
Collection<Plugin> allPlugins = Plugin.getAllPlugins();
for (Plugin plugin : allPlugins) {
for (DetectorFactory factory : plugin.getDetectorFactories()) {
detectorEnablementMap.put(factory.getShortName(), enable);
}
}
}
Aggregations