Package edu.umd.cs.findbugs.config
Class UserPreferences
- java.lang.Object
-
- edu.umd.cs.findbugs.config.UserPreferences
-
- All Implemented Interfaces:
java.lang.Cloneable
public class UserPreferences extends java.lang.Object implements java.lang.CloneableUser Preferences outside of any one Project. This consists of a class to manage the findbugs.prop file found in the user.home.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>adjustPriorityprivate static charBOOL_SEPARATORSeparator string for values composed from a string and booleanprivate java.util.Map<java.lang.String,java.lang.Boolean>customPluginsprivate static java.lang.StringDETECTOR_THRESHOLD_KEYprivate java.util.Map<java.lang.String,java.lang.Boolean>detectorEnablementMapprivate java.lang.Stringeffortstatic java.lang.StringEFFORT_DEFAULTprivate static java.lang.StringEFFORT_KEYstatic java.lang.StringEFFORT_MAXstatic java.lang.StringEFFORT_MINprivate java.util.Map<java.lang.String,java.lang.Boolean>excludeBugsFilesprivate java.util.Map<java.lang.String,java.lang.Boolean>excludeFilterFilesprivate static java.lang.StringFILTER_SETTINGS_KEYprivate static java.lang.StringFILTER_SETTINGS2_KEYprivate ProjectFilterSettingsfilterSettingsprivate java.util.Map<java.lang.String,java.lang.Boolean>includeFilterFilesprivate static java.lang.StringKEY_ADJUST_PRIORITYstatic java.lang.StringKEY_EXCLUDE_BUGSKey prefix for custom filters, full key consists of a prefix + filter index starting with 0static java.lang.StringKEY_EXCLUDE_FILTERKey prefix for custom filters, full key consists of a prefix + filter index starting with 0static java.lang.StringKEY_INCLUDE_FILTERKey prefix for custom filters, full key consists of a prefix + filter index starting with 0private static java.lang.StringKEY_MERGE_SIMILAR_WARNINGSstatic java.lang.StringKEY_PLUGINKey prefix for custom plugins, full key consists of a prefix + plugin index starting with 0private static intMAX_RECENT_FILESprivate booleanmergeSimilarWarningsprivate static java.lang.StringPREF_FILE_NAMEprivate java.util.LinkedList<java.lang.String>recentProjectsListprivate static java.lang.StringRUN_AT_FULL_BUILDprivate booleanrunAtFullBuild
-
Constructor Summary
Constructors Modifier Constructor Description privateUserPreferences()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UserPreferencesclone()static UserPreferencescreateDefaultUserPreferences()Create default UserPreferences.voidenableAllDetectors(boolean enable)Enable or disable all known Detectors.voidenableDetector(DetectorFactory factory, boolean enable)Set the enabled/disabled status of given Detector.booleanequals(java.lang.Object obj)java.util.Map<java.lang.String,java.lang.String>getAdjustPriority()AnalysisFeatureSetting[]getAnalysisFeatureSettings()Returns the effort level as an array of feature settings as expected by FindBugs.java.util.Map<java.lang.String,java.lang.Boolean>getCustomPlugins()Additional plugins which could be used byIFindBugsEngine(if enabled), or which shouldn't be used (if disabled).java.util.Set<java.lang.String>getCustomPlugins(boolean enabled)Additional plugins which could be used or shouldn't be used (depending on given argument) byIFindBugsEngine.java.lang.StringgetEffort()java.util.Map<java.lang.String,java.lang.Boolean>getExcludeBugsFiles()java.util.Map<java.lang.String,java.lang.Boolean>getExcludeFilterFiles()ProjectFilterSettingsgetFilterSettings()Get ProjectFilterSettings.java.util.Map<java.lang.String,java.lang.Boolean>getIncludeFilterFiles()booleangetMergeSimilarWarnings()java.util.List<java.lang.String>getRecentProjects()Get List of recent project filenames.intgetUserDetectorThreshold()Get the detector threshold (min severity to report a warning).inthashCode()booleanisDetectorEnabled(DetectorFactory factory)Get the enabled/disabled status of given Detector.booleanisRunAtFullBuild()Get the enabled/disabled status of runAtFullBuildstatic java.util.Map<java.lang.String,java.lang.String>parseAdjustPriorities(java.lang.String str)Parses the -adjustPriority parameter into a map: detector / bug pattern -> priority changevoidread()Read persistent global UserPreferences from file in the user's home directory.voidread(java.io.InputStream in)Read user preferences from given input stream.private static java.util.Map<java.lang.String,java.lang.Boolean>readProperties(java.util.Properties props, java.lang.String keyPrefix)Helper method to read array of strings out of the properties file, using a Findbugs style format.voidremoveProject(java.lang.String projectName)Remove project filename from the recently-used project list.private static java.lang.StringresolveRelativePath(java.lang.String maybeRelativePath, java.nio.file.Path prefsDir)voidresolveRelativePaths(java.lang.String preferencesPath)Resolve relative paths stored in the user preferences.private static java.util.Map<java.lang.String,java.lang.Boolean>resolveRelativePaths(java.nio.file.Path prefsDir, java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Boolean>> oldMap)voidsetAdjustPriority(java.util.Map<java.lang.String,java.lang.String> adjustPriority)voidsetCustomPlugins(java.util.Map<java.lang.String,java.lang.Boolean> customPlugins)Additional plugins which could be used byIFindBugsEngine(if enabled), or which shouldn't be used (if disabled).voidsetEffort(java.lang.String effort)voidsetExcludeBugsFiles(java.util.Map<java.lang.String,java.lang.Boolean> excludeBugsFiles)voidsetExcludeFilterFiles(java.util.Map<java.lang.String,java.lang.Boolean> excludeFilterFiles)voidsetIncludeFilterFiles(java.util.Map<java.lang.String,java.lang.Boolean> includeFilterFiles)voidsetMergeSimilarWarnings(boolean mergeSimilarWarnings)voidsetProjectFilterSettings(ProjectFilterSettings filterSettings)Set the ProjectFilterSettings.voidsetRunAtFullBuild(boolean enable)Set the enabled/disabled status of running findbugs automatically for full builds.voidsetUserDetectorThreshold(int threshold)Set the detector threshold (min severity to report a warning).voidsetUserDetectorThreshold(java.lang.String threshold)Set the detector threshold (min severity to report a warning).voiduseProject(java.lang.String projectName)Add given project filename to the front of the recently-used project list.voidwrite()Write persistent global UserPreferences to file in user's home directory.voidwrite(java.io.OutputStream out)Write UserPreferences to given OutputStream.private static voidwriteProperties(java.util.Properties props, java.lang.String keyPrefix, java.util.Map<java.lang.String,java.lang.Boolean> filters)Helper method to write array of strings out of the properties file, using a Findbugs style format.
-
-
-
Field Detail
-
BOOL_SEPARATOR
private static final char BOOL_SEPARATOR
Separator string for values composed from a string and boolean- See Also:
- Constant Field Values
-
EFFORT_MIN
public static final java.lang.String EFFORT_MIN
- See Also:
- Constant Field Values
-
EFFORT_DEFAULT
public static final java.lang.String EFFORT_DEFAULT
- See Also:
- Constant Field Values
-
EFFORT_MAX
public static final java.lang.String EFFORT_MAX
- See Also:
- Constant Field Values
-
KEY_PLUGIN
public static final java.lang.String KEY_PLUGIN
Key prefix for custom plugins, full key consists of a prefix + plugin index starting with 0- See Also:
- Constant Field Values
-
PREF_FILE_NAME
private static final java.lang.String PREF_FILE_NAME
- See Also:
- Constant Field Values
-
MAX_RECENT_FILES
private static final int MAX_RECENT_FILES
- See Also:
- Constant Field Values
-
DETECTOR_THRESHOLD_KEY
private static final java.lang.String DETECTOR_THRESHOLD_KEY
- See Also:
- Constant Field Values
-
FILTER_SETTINGS_KEY
private static final java.lang.String FILTER_SETTINGS_KEY
- See Also:
- Constant Field Values
-
FILTER_SETTINGS2_KEY
private static final java.lang.String FILTER_SETTINGS2_KEY
- See Also:
- Constant Field Values
-
RUN_AT_FULL_BUILD
private static final java.lang.String RUN_AT_FULL_BUILD
- See Also:
- Constant Field Values
-
EFFORT_KEY
private static final java.lang.String EFFORT_KEY
- See Also:
- Constant Field Values
-
KEY_INCLUDE_FILTER
public static final java.lang.String KEY_INCLUDE_FILTER
Key prefix for custom filters, full key consists of a prefix + filter index starting with 0- See Also:
- Constant Field Values
-
KEY_EXCLUDE_FILTER
public static final java.lang.String KEY_EXCLUDE_FILTER
Key prefix for custom filters, full key consists of a prefix + filter index starting with 0- See Also:
- Constant Field Values
-
KEY_EXCLUDE_BUGS
public static final java.lang.String KEY_EXCLUDE_BUGS
Key prefix for custom filters, full key consists of a prefix + filter index starting with 0- See Also:
- Constant Field Values
-
KEY_MERGE_SIMILAR_WARNINGS
private static final java.lang.String KEY_MERGE_SIMILAR_WARNINGS
- See Also:
- Constant Field Values
-
KEY_ADJUST_PRIORITY
private static final java.lang.String KEY_ADJUST_PRIORITY
- See Also:
- Constant Field Values
-
recentProjectsList
private java.util.LinkedList<java.lang.String> recentProjectsList
-
detectorEnablementMap
private java.util.Map<java.lang.String,java.lang.Boolean> detectorEnablementMap
-
filterSettings
private ProjectFilterSettings filterSettings
-
runAtFullBuild
private boolean runAtFullBuild
-
effort
private java.lang.String effort
-
includeFilterFiles
private java.util.Map<java.lang.String,java.lang.Boolean> includeFilterFiles
-
excludeFilterFiles
private java.util.Map<java.lang.String,java.lang.Boolean> excludeFilterFiles
-
excludeBugsFiles
private java.util.Map<java.lang.String,java.lang.Boolean> excludeBugsFiles
-
customPlugins
private java.util.Map<java.lang.String,java.lang.Boolean> customPlugins
-
mergeSimilarWarnings
private boolean mergeSimilarWarnings
-
adjustPriority
private java.util.Map<java.lang.String,java.lang.String> adjustPriority
-
-
Method Detail
-
createDefaultUserPreferences
public static UserPreferences createDefaultUserPreferences()
Create default UserPreferences.- Returns:
- default UserPreferences
-
read
public void read()
Read persistent global UserPreferences from file in the user's home directory.
-
read
public void read(@WillClose java.io.InputStream in) throws java.io.IOExceptionRead user preferences from given input stream. The InputStream is guaranteed to be closed by this method.- Parameters:
in- the InputStream- Throws:
java.io.IOException
-
parseAdjustPriorities
public static java.util.Map<java.lang.String,java.lang.String> parseAdjustPriorities(java.lang.String str)
Parses the -adjustPriority parameter into a map: detector / bug pattern -> priority change- Parameters:
str- the string to parse- Returns:
- the parsed map
-
write
public void write()
Write persistent global UserPreferences to file in user's home directory.
-
write
public void write(@WillClose java.io.OutputStream out) throws java.io.IOExceptionWrite UserPreferences to given OutputStream. The OutputStream is guaranteed to be closed by this method.- Parameters:
out- the OutputStream- Throws:
java.io.IOException
-
getRecentProjects
public java.util.List<java.lang.String> getRecentProjects()
Get List of recent project filenames.- Returns:
- List of recent project filenames
-
useProject
public void useProject(java.lang.String projectName)
Add given project filename to the front of the recently-used project list.- Parameters:
projectName- project filename
-
removeProject
public void removeProject(java.lang.String projectName)
Remove project filename from the recently-used project list.- Parameters:
projectName- project filename
-
enableDetector
public void enableDetector(DetectorFactory factory, boolean enable)
Set the enabled/disabled status of given Detector.- Parameters:
factory- the DetectorFactory for the Detector to be enabled/disabledenable- true if the Detector should be enabled, false if it should be Disabled
-
isDetectorEnabled
public boolean isDetectorEnabled(DetectorFactory factory)
Get the enabled/disabled status of given Detector.- Parameters:
factory- the DetectorFactory of the Detector- Returns:
- true if the Detector is enabled, false if not
-
enableAllDetectors
public void enableAllDetectors(boolean enable)
Enable or disable all known Detectors.- Parameters:
enable- true if all detectors should be enabled, false if they should all be disabled
-
setProjectFilterSettings
public void setProjectFilterSettings(ProjectFilterSettings filterSettings)
Set the ProjectFilterSettings.- Parameters:
filterSettings- the ProjectFilterSettings
-
getFilterSettings
public ProjectFilterSettings getFilterSettings()
Get ProjectFilterSettings.- Returns:
- the ProjectFilterSettings
-
getUserDetectorThreshold
public int getUserDetectorThreshold()
Get the detector threshold (min severity to report a warning).- Returns:
- the detector threshold
-
setUserDetectorThreshold
public void setUserDetectorThreshold(int threshold)
Set the detector threshold (min severity to report a warning).- Parameters:
threshold- the detector threshold
-
setRunAtFullBuild
public void setRunAtFullBuild(boolean enable)
Set the enabled/disabled status of running findbugs automatically for full builds.- Parameters:
enable- true if running FindBugs at full builds should be enabled, false if it should be Disabled
-
isRunAtFullBuild
public boolean isRunAtFullBuild()
Get the enabled/disabled status of runAtFullBuild- Returns:
- true if the running for full builds is enabled, false if not
-
setUserDetectorThreshold
public void setUserDetectorThreshold(java.lang.String threshold)
Set the detector threshold (min severity to report a warning).- Parameters:
threshold- the detector threshold
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clone
public UserPreferences clone()
- Overrides:
clonein classjava.lang.Object
-
getEffort
public java.lang.String getEffort()
-
setEffort
public void setEffort(java.lang.String effort)
-
getIncludeFilterFiles
public java.util.Map<java.lang.String,java.lang.Boolean> getIncludeFilterFiles()
-
setIncludeFilterFiles
public void setIncludeFilterFiles(java.util.Map<java.lang.String,java.lang.Boolean> includeFilterFiles)
-
getExcludeBugsFiles
public java.util.Map<java.lang.String,java.lang.Boolean> getExcludeBugsFiles()
-
setExcludeBugsFiles
public void setExcludeBugsFiles(java.util.Map<java.lang.String,java.lang.Boolean> excludeBugsFiles)
-
setExcludeFilterFiles
public void setExcludeFilterFiles(java.util.Map<java.lang.String,java.lang.Boolean> excludeFilterFiles)
-
getExcludeFilterFiles
public java.util.Map<java.lang.String,java.lang.Boolean> getExcludeFilterFiles()
-
setCustomPlugins
public void setCustomPlugins(java.util.Map<java.lang.String,java.lang.Boolean> customPlugins)
Additional plugins which could be used byIFindBugsEngine(if enabled), or which shouldn't be used (if disabled). If a plugin is not included in the set, it's enablement depends on it's default settings.- Parameters:
customPlugins- map with additional third party plugin locations (as absolute paths), never null, but might be empty- See Also:
Plugin.isCorePlugin(),Plugin.isGloballyEnabled()
-
getCustomPlugins
public java.util.Map<java.lang.String,java.lang.Boolean> getCustomPlugins()
Additional plugins which could be used byIFindBugsEngine(if enabled), or which shouldn't be used (if disabled). If a plugin is not included in the set, it's enablement depends on it's default settings.- Returns:
- map with additional third party plugins, might be empty, never null. The keys are either absolute plugin paths or plugin id's. Special case: if the path consists of one path segment then it represents the plugin id for a plugin to be disabled. A value of a particular key can be null (same as disabled)
- See Also:
Plugin.isCorePlugin(),Plugin.isGloballyEnabled()
-
getCustomPlugins
public java.util.Set<java.lang.String> getCustomPlugins(boolean enabled)
Additional plugins which could be used or shouldn't be used (depending on given argument) byIFindBugsEngine. If a plugin is not included in the set, it's enablement depends on it's default settings.- Returns:
- set with additional third party plugins, might be empty, never null. The elements are either absolute plugin paths or plugin id's. Special case: if the path consists of one path segment then it represents the plugin id for a plugin to be disabled.
- See Also:
Plugin.isCorePlugin(),Plugin.isGloballyEnabled()
-
readProperties
private static java.util.Map<java.lang.String,java.lang.Boolean> readProperties(java.util.Properties props, java.lang.String keyPrefix)Helper method to read array of strings out of the properties file, using a Findbugs style format.- Parameters:
props- The properties file to read the array from.keyPrefix- The key prefix of the array.- Returns:
- The array of Strings, or an empty array if no values exist.
-
writeProperties
private static void writeProperties(java.util.Properties props, java.lang.String keyPrefix, java.util.Map<java.lang.String,java.lang.Boolean> filters)Helper method to write array of strings out of the properties file, using a Findbugs style format.- Parameters:
props- The properties file to write the array to.keyPrefix- The key prefix of the array.filters- The filters array to write to the properties.
-
getAnalysisFeatureSettings
public AnalysisFeatureSetting[] getAnalysisFeatureSettings()
Returns the effort level as an array of feature settings as expected by FindBugs.- Returns:
- The array of feature settings corresponding to the current effort setting.
-
getMergeSimilarWarnings
public boolean getMergeSimilarWarnings()
- Returns:
- true if similar warnings should be merged, false otherwise
-
setMergeSimilarWarnings
public void setMergeSimilarWarnings(boolean mergeSimilarWarnings)
- Parameters:
mergeSimilarWarnings- true if similar warnings should be merged, false otherwise
-
resolveRelativePaths
public void resolveRelativePaths(java.lang.String preferencesPath)
Resolve relative paths stored in the user preferences. If the preferences contain relative filter paths, modifies the paths to be absolute. For that, the directory of given file will be used first, and if that does not match, the parent directory will be used to resolve relative paths. If none of the paths match existing files, preferences will stay unchanged.- Parameters:
preferencesPath- the path to the user preferences file, used to resolve relative paths
-
resolveRelativePaths
private static java.util.Map<java.lang.String,java.lang.Boolean> resolveRelativePaths(java.nio.file.Path prefsDir, java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Boolean>> oldMap)
-
resolveRelativePath
private static java.lang.String resolveRelativePath(java.lang.String maybeRelativePath, java.nio.file.Path prefsDir)
-
getAdjustPriority
public java.util.Map<java.lang.String,java.lang.String> getAdjustPriority()
- Returns:
- Returns the adjustPriority.
-
setAdjustPriority
public void setAdjustPriority(java.util.Map<java.lang.String,java.lang.String> adjustPriority)
- Parameters:
adjustPriority- The adjustPriority to set.
-
-