Search in sources :

Example 1 with UserPreferences

use of edu.umd.cs.findbugs.config.UserPreferences in project wcomponents by BorderTech.

the class DetectorsTest method setUpEngine.

/**
 * Sets up a FB engine to run on the 'findbugsTestCases' project. It enables all the available detectors and reports
 * all the bug categories. Uses a low priority threshold.
 *
 * @param analyzeMe files to analyse
 */
private void setUpEngine(final String... analyzeMe) {
    engine = new FindBugs2();
    Project project = new Project();
    project.setProjectName("wcomponentTestCases");
    engine.setProject(project);
    DetectorFactoryCollection detectorFactoryCollection = DetectorFactoryCollection.instance();
    engine.setDetectorFactoryCollection(detectorFactoryCollection);
    bugReporter = new BugCollectionBugReporter(project);
    bugReporter.setPriorityThreshold(Priorities.LOW_PRIORITY);
    engine.setBugReporter(bugReporter);
    UserPreferences preferences = UserPreferences.createDefaultUserPreferences();
    preferences.enableAllDetectors(false);
    preferences.getFilterSettings().clearAllCategories();
    engine.setUserPreferences(preferences);
    for (String s : analyzeMe) {
        project.addFile(s);
    }
    project.addAuxClasspathEntry("../wcomponents-core/target/classes");
    setUpDetectors(preferences);
}
Also used : UserPreferences(edu.umd.cs.findbugs.config.UserPreferences)

Example 2 with UserPreferences

use of edu.umd.cs.findbugs.config.UserPreferences in project spotbugs by spotbugs.

the class BugContentProvider method createGroups.

/**
 * @param <Identifier>
 *            object type, like String or Integer
 * @param mapper
 *            maps between BugInstance and group
 */
private synchronized <Identifier> Object[] createGroups(BugGroup parent, MarkerMapper<Identifier> mapper) {
    if (mapper == MarkerMapper.NO_MAPPING) {
        return parent.getAllMarkers().toArray(new IMarker[0]);
    }
    Set<IMarker> allMarkers = parent.getAllMarkers();
    GroupType childType = grouping.getChildType(mapper.getType());
    Map<Identifier, Set<IMarker>> groupIds = new HashMap<>();
    UserPreferences prefs = FindbugsPlugin.getCorePreferences(null, false);
    Set<String> disabledPlugins = prefs.getCustomPlugins(false);
    // first, sort all bugs to the sets with same identifier type
    Set<String> errorMessages = new HashSet<>();
    for (IMarker marker : allMarkers) {
        Identifier id = mapper.getIdentifier(marker);
        if (id == null) {
            String pluginId = MarkerUtil.getPluginId(marker);
            if (pluginId.length() == 0 || disabledPlugins.contains(pluginId)) {
                // do not report errors for disabled plugins
                continue;
            }
            try {
                String debugDescription = mapper.getDebugDescription(marker);
                if (errorMessages.contains(debugDescription)) {
                    continue;
                }
                errorMessages.add(debugDescription);
                if (FindbugsPlugin.getDefault().isDebugging()) {
                    FindbugsPlugin.getDefault().logWarning("BugContentProvider.createGroups: failed to find " + debugDescription + " for marker on file " + marker.getResource());
                }
            } catch (CoreException e) {
                FindbugsPlugin.getDefault().logException(e, "Exception on retrieving debug data for: " + mapper.getType());
            }
            continue;
        }
        if (!groupIds.containsKey(id)) {
            groupIds.put(id, new HashSet<IMarker>());
        }
        groupIds.get(id).add(marker);
    }
    // now create groups from the sorted bug sets
    Set<Entry<Identifier, Set<IMarker>>> typesSet = groupIds.entrySet();
    BugGroup[] children = new BugGroup[typesSet.size()];
    boolean lastlevel = grouping.getChildType(mapper.getType()) == GroupType.Marker;
    int i = 0;
    for (Entry<Identifier, Set<IMarker>> entry : typesSet) {
        Identifier groupId = entry.getKey();
        children[i] = new BugGroup(parent, groupId, mapper.getType());
        children[i].setMarkers(entry.getValue());
        i++;
    }
    if (!lastlevel) {
        for (BugGroup bugGroup : children) {
            // recursive call
            createGroups(bugGroup, childType.getMapper());
        }
    }
    return children;
}
Also used : UserPreferences(edu.umd.cs.findbugs.config.UserPreferences) HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) HashMap(java.util.HashMap) Entry(java.util.Map.Entry) CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) HashSet(java.util.HashSet)

Example 3 with UserPreferences

use of edu.umd.cs.findbugs.config.UserPreferences in project spotbugs by spotbugs.

the class FindbugsPlugin method createDefaultEmptyBugCollection.

private static SortedBugCollection createDefaultEmptyBugCollection(IProject project) throws CoreException {
    SortedBugCollection bugCollection = new SortedBugCollection();
    Project fbProject = bugCollection.getProject();
    UserPreferences userPrefs = getUserPreferences(project);
    cacheBugCollectionAndProject(project, bugCollection, fbProject);
    return bugCollection;
}
Also used : UserPreferences(edu.umd.cs.findbugs.config.UserPreferences) IProject(org.eclipse.core.resources.IProject) Project(edu.umd.cs.findbugs.Project) SortedBugCollection(edu.umd.cs.findbugs.SortedBugCollection)

Example 4 with UserPreferences

use of edu.umd.cs.findbugs.config.UserPreferences in project spotbugs by spotbugs.

the class FindbugsPlugin method getWorkspacePreferences.

private static UserPreferences getWorkspacePreferences() {
    // create initially default settings
    UserPreferences userPrefs = FindBugsPreferenceInitializer.createDefaultUserPreferences();
    File prefsFile = WORKSPACE_PREFS_PATH.toFile();
    if (!prefsFile.isFile()) {
        return userPrefs;
    }
    // load custom settings over defaults
    FileInputStream in;
    try {
        in = new FileInputStream(prefsFile);
        userPrefs.read(in);
    } catch (IOException e) {
        FindbugsPlugin.getDefault().logException(e, "Error reading custom SpotBugs preferences for workspace");
    }
    return userPrefs;
}
Also used : UserPreferences(edu.umd.cs.findbugs.config.UserPreferences) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with UserPreferences

use of edu.umd.cs.findbugs.config.UserPreferences in project spotbugs by spotbugs.

the class FindbugsPlugin method getProjectPreferences.

/**
 * Get project own preferences set.
 *
 * @param project
 *            must be non null, exist and be opened
 * @param forceRead
 * @return current project preferences, independently if project preferences
 *         are enabled or disabled for given project.
 */
public static UserPreferences getProjectPreferences(IProject project, boolean forceRead) {
    try {
        UserPreferences prefs = (UserPreferences) project.getSessionProperty(SESSION_PROPERTY_USERPREFS);
        if (prefs == null || forceRead) {
            prefs = readUserPreferences(project);
            if (prefs == null) {
                prefs = getWorkspacePreferences().clone();
            }
            project.setSessionProperty(SESSION_PROPERTY_USERPREFS, prefs);
        }
        return prefs;
    } catch (CoreException e) {
        FindbugsPlugin.getDefault().logException(e, "Error getting SpotBugs preferences for project");
        return getWorkspacePreferences().clone();
    }
}
Also used : UserPreferences(edu.umd.cs.findbugs.config.UserPreferences) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

UserPreferences (edu.umd.cs.findbugs.config.UserPreferences)23 File (java.io.File)6 IOException (java.io.IOException)5 CoreException (org.eclipse.core.runtime.CoreException)5 IFile (org.eclipse.core.resources.IFile)4 Project (edu.umd.cs.findbugs.Project)3 FileInputStream (java.io.FileInputStream)3 HashMap (java.util.HashMap)3 DetectorFactory (edu.umd.cs.findbugs.DetectorFactory)2 FindBugs2 (edu.umd.cs.findbugs.FindBugs2)2 Plugin (edu.umd.cs.findbugs.Plugin)2 SortedBugCollection (edu.umd.cs.findbugs.SortedBugCollection)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 MojoExecution (org.apache.maven.plugin.MojoExecution)2 IPath (org.eclipse.core.runtime.IPath)2