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);
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations