Search in sources :

Example 1 with DetectorFactory

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>");
        }
    }
}
Also used : DetectorFactory(edu.umd.cs.findbugs.DetectorFactory) FindbugsPlugin(de.tobject.findbugs.FindbugsPlugin) Plugin(edu.umd.cs.findbugs.Plugin)

Example 2 with DetectorFactory

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;
}
Also used : AppVersion(edu.umd.cs.findbugs.AppVersion) IJavaElement(org.eclipse.jdt.core.IJavaElement) HashMap(java.util.HashMap) DetectorFactory(edu.umd.cs.findbugs.DetectorFactory) BugPattern(edu.umd.cs.findbugs.BugPattern) Nonnull(javax.annotation.Nonnull)

Example 3 with DetectorFactory

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();
}
Also used : DetectorFactory(edu.umd.cs.findbugs.DetectorFactory) BugPattern(edu.umd.cs.findbugs.BugPattern) DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) HashSet(java.util.HashSet)

Example 4 with DetectorFactory

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);
        }
    }
}
Also used : UserPreferences(edu.umd.cs.findbugs.config.UserPreferences) TableItem(org.eclipse.swt.widgets.TableItem) DetectorFactory(edu.umd.cs.findbugs.DetectorFactory) ArrayList(java.util.ArrayList)

Example 5 with DetectorFactory

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);
        }
    }
}
Also used : DetectorFactory(edu.umd.cs.findbugs.DetectorFactory) Plugin(edu.umd.cs.findbugs.Plugin)

Aggregations

DetectorFactory (edu.umd.cs.findbugs.DetectorFactory)22 DetectorFactoryCollection (edu.umd.cs.findbugs.DetectorFactoryCollection)5 BugPattern (edu.umd.cs.findbugs.BugPattern)4 TableItem (org.eclipse.swt.widgets.TableItem)4 Plugin (edu.umd.cs.findbugs.Plugin)3 FindbugsPlugin (de.tobject.findbugs.FindbugsPlugin)2 UserPreferences (edu.umd.cs.findbugs.config.UserPreferences)2 ArrayList (java.util.ArrayList)2 AppVersion (edu.umd.cs.findbugs.AppVersion)1 BugInstance (edu.umd.cs.findbugs.BugInstance)1 Detector (edu.umd.cs.findbugs.Detector)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Nonnull (javax.annotation.Nonnull)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1