Package edu.umd.cs.findbugs
Class FindBugs2
java.lang.Object
edu.umd.cs.findbugs.FindBugs2
- All Implemented Interfaces:
IFindBugsEngine
,AutoCloseable
FindBugs driver class. Orchestrates the analysis of a project, collection of
results, etc.
- Author:
- David Hovemeyer
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructor that usesCurrentThreadExecutorService
to keep backward compatibility with SpotBugs 3.1.FindBugs2
(ExecutorService service) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClassObserver
(IClassObserver classObserver) Add an IClassObserver.void
Set filter of bug instances to include or exclude.static void
protected void
Protected to allow Eclipse plugin remember some cache data for later reusevoid
close()
protected void
configureFilters
(UserPreferences userPreferences) protected IAnalysisCache
Create the analysis cache object and register it for current execution thread.static void
createAnalysisContext
(Project project, List<ClassDescriptor> appClassList, String sourceInfoFileName) Create the AnalysisContext that will serve as the BCEL-compatibility layer over the AnalysisCache.void
dispose()
To avoid cyclic cross-references and allow GC after engine is not more needed.boolean
Return whether or not training output should be emitted after analysis completes.void
enableTrainingInput
(String trainingInputDir) Set whether or not training input should be used to make the analysis more precise.void
enableTrainingOutput
(String trainingOutputDir) Set whether or not training output should be emitted.void
excludeBaselineBugs
(String baselineBugs) Provide baseline of bugs not to reportvoid
execute()
Execute the analysis.void
int
Get the number of bug instances that were reported during analysis.Get the BugReporter.Get the name of the most recent class to be analyzed.int
Get the number of errors that occurred during analysis.int
Get the number of time missing classes were reported during analysis.Get the Project.Get the training input database directory.Get the training output directory.Get the UserPreferences.static void
static void
registerBuiltInAnalysisEngines
(IAnalysisCache analysisCache) Register the "built-in" analysis engines with given IAnalysisCache.static void
registerPluginAnalysisEngines
(DetectorFactoryCollection detectorFactoryCollection, IAnalysisCache analysisCache) Register all of the analysis engines defined in the plugins contained in a DetectorFactoryCollection with an IAnalysisCache.void
setAbridgedMessages
(boolean xmlWithAbridgedMessages) void
setAnalysisFeatureSettings
(AnalysisFeatureSetting[] settingList) Set analysis feature settings.static void
setAppClassList
(List<ClassDescriptor> appClassList) void
setApplySuppression
(boolean applySuppression) void
setBugReporter
(BugReporter bugReporter) Set the BugReporter.void
setBugReporterDecorators
(Set<String> explicitlyEnabled, Set<String> explicitlyDisabled) void
setClassScreener
(IClassScreener classScreener) Set the ClassScreener.void
setDetectorFactoryCollection
(DetectorFactoryCollection detectorFactoryCollection) Set the detector factory collection to be used by this FindBugs2 engine.void
setMergeSimilarWarnings
(boolean mergeSimilarWarnings) void
setNoClassOk
(boolean noClassOk) Set whether or not to generate an empty output file if there were no class files specified.void
setProgressCallback
(FindBugsProgress progressCallback) Set the progress callback that will be used to keep track of the progress of the analysis.void
setProject
(Project project) Set the Project.void
setProjectName
(String name) void
setRankThreshold
(int rankThreshold) void
setRelaxedReportingMode
(boolean relaxedReportingMode) Set relaxed reporting mode.void
setReleaseName
(String releaseName) void
setScanNestedArchives
(boolean scanNestedArchives) Set whether or not nested archives should be scanned.void
setSourceInfoFile
(String sourceInfoFile) Set the filename of the source info file containing line numbers for fields and classes.void
setUserPreferences
(UserPreferences userPreferences) Set the UserPreferences representing which Detectors should be used.sortByCallGraph
(Collection<ClassDescriptor> classList, TopologicalSort.OutEdges<ClassDescriptor> outEdges) boolean
Return whether or not we should make use of training data.
-
Field Details
-
DEBUG
public static final boolean DEBUG -
PROGRESS
public static final boolean PROGRESS -
MULTI_THREAD
public static final boolean MULTI_THREAD -
PROP_FINDBUGS_HOST_APP
- See Also:
-
PROP_FINDBUGS_HOST_APP_VERSION
- See Also:
-
-
Constructor Details
-
FindBugs2
public FindBugs2()Constructor that usesCurrentThreadExecutorService
to keep backward compatibility with SpotBugs 3.1.- Since:
- 3.1
-
FindBugs2
- Parameters:
service
- The non-nullExecutorService
instance to execute analysis. Caller is responsible to shutdown it.- Since:
- 4.0
-
-
Method Details
-
setDetectorFactoryCollection
Set the detector factory collection to be used by this FindBugs2 engine. This method should be called before the execute() method is called.- Specified by:
setDetectorFactoryCollection
in interfaceIFindBugsEngine
- Parameters:
detectorFactoryCollection
- The detectorFactoryCollection to set.
-
execute
Execute the analysis. For obscure reasons, CheckedAnalysisExceptions are re-thrown as IOExceptions. However, these can only happen during the setup phase where we scan codebases for classes.- Specified by:
execute
in interfaceIFindBugsEngine
- Throws:
IOException
InterruptedException
-
clearCaches
protected void clearCaches()Protected to allow Eclipse plugin remember some cache data for later reuse -
dispose
public void dispose()To avoid cyclic cross-references and allow GC after engine is not more needed. (used by Eclipse plugin)
Caller probably need to shutdown the
ExecutorService
instance provided at constructor. -
getBugReporter
Description copied from interface:IFindBugsEngine
Get the BugReporter.- Specified by:
getBugReporter
in interfaceIFindBugsEngine
- Returns:
- the BugReporter
-
getProject
Description copied from interface:IFindBugsEngine
Get the Project.- Specified by:
getProject
in interfaceIFindBugsEngine
- Returns:
- the Project
-
addClassObserver
Description copied from interface:IFindBugsEngine
Add an IClassObserver.- Specified by:
addClassObserver
in interfaceIFindBugsEngine
- Parameters:
classObserver
- the IClassObserver
-
addFilter
Description copied from interface:IFindBugsEngine
Set filter of bug instances to include or exclude.- Specified by:
addFilter
in interfaceIFindBugsEngine
- Parameters:
filterFileName
- the name of the filter fileinclude
- true if the filter specifies bug instances to include, false if it specifies bug instances to exclude- Throws:
IOException
FilterException
-
excludeBaselineBugs
public void excludeBaselineBugs(String baselineBugs) throws IOException, org.dom4j.DocumentException Description copied from interface:IFindBugsEngine
Provide baseline of bugs not to report- Specified by:
excludeBaselineBugs
in interfaceIFindBugsEngine
- Parameters:
baselineBugs
- the name of the xml bug baseline file- Throws:
org.dom4j.DocumentException
IOException
-
enableTrainingInput
Description copied from interface:IFindBugsEngine
Set whether or not training input should be used to make the analysis more precise.- Specified by:
enableTrainingInput
in interfaceIFindBugsEngine
- Parameters:
trainingInputDir
- directory to load training input from
-
enableTrainingOutput
Description copied from interface:IFindBugsEngine
Set whether or not training output should be emitted.- Specified by:
enableTrainingOutput
in interfaceIFindBugsEngine
- Parameters:
trainingOutputDir
- directory to save training output in
-
getBugCount
public int getBugCount()Description copied from interface:IFindBugsEngine
Get the number of bug instances that were reported during analysis.- Specified by:
getBugCount
in interfaceIFindBugsEngine
-
getCurrentClass
Description copied from interface:IFindBugsEngine
Get the name of the most recent class to be analyzed. This is useful for diagnosing an unexpected exception. Returns null if no class has been analyzed.- Specified by:
getCurrentClass
in interfaceIFindBugsEngine
-
getErrorCount
public int getErrorCount()Description copied from interface:IFindBugsEngine
Get the number of errors that occurred during analysis.- Specified by:
getErrorCount
in interfaceIFindBugsEngine
-
getMissingClassCount
public int getMissingClassCount()Description copied from interface:IFindBugsEngine
Get the number of time missing classes were reported during analysis.- Specified by:
getMissingClassCount
in interfaceIFindBugsEngine
-
getReleaseName
- Specified by:
getReleaseName
in interfaceIFindBugsEngine
- Returns:
- Returns the releaseName.
-
getProjectName
- Specified by:
getProjectName
in interfaceIFindBugsEngine
- Returns:
- Returns the projectName.
-
setProjectName
- Specified by:
setProjectName
in interfaceIFindBugsEngine
- Parameters:
name
- The project name to set.
-
setAnalysisFeatureSettings
Description copied from interface:IFindBugsEngine
Set analysis feature settings.- Specified by:
setAnalysisFeatureSettings
in interfaceIFindBugsEngine
- Parameters:
settingList
- list of analysis feature settings
-
setBugReporter
Description copied from interface:IFindBugsEngine
Set the BugReporter.- Specified by:
setBugReporter
in interfaceIFindBugsEngine
- Parameters:
bugReporter
- The BugReporter to set
-
setClassScreener
Description copied from interface:IFindBugsEngine
Set the ClassScreener. This object chooses which individual classes to analyze. By default, all classes are analyzed.- Specified by:
setClassScreener
in interfaceIFindBugsEngine
- Parameters:
classScreener
- the ClassScreener to use
-
setProgressCallback
Description copied from interface:IFindBugsEngine
Set the progress callback that will be used to keep track of the progress of the analysis.- Specified by:
setProgressCallback
in interfaceIFindBugsEngine
- Parameters:
progressCallback
- the progress callback
-
setProject
Description copied from interface:IFindBugsEngine
Set the Project.- Specified by:
setProject
in interfaceIFindBugsEngine
- Parameters:
project
- The Project to set
-
setRelaxedReportingMode
public void setRelaxedReportingMode(boolean relaxedReportingMode) Description copied from interface:IFindBugsEngine
Set relaxed reporting mode.- Specified by:
setRelaxedReportingMode
in interfaceIFindBugsEngine
- Parameters:
relaxedReportingMode
- true if relaxed reporting mode should be enabled, false if not
-
setReleaseName
- Specified by:
setReleaseName
in interfaceIFindBugsEngine
- Parameters:
releaseName
- The releaseName to set.
-
setSourceInfoFile
Description copied from interface:IFindBugsEngine
Set the filename of the source info file containing line numbers for fields and classes.- Specified by:
setSourceInfoFile
in interfaceIFindBugsEngine
- Parameters:
sourceInfoFile
- the source info filename
-
setUserPreferences
Description copied from interface:IFindBugsEngine
Set the UserPreferences representing which Detectors should be used. If UserPreferences are not set explicitly, the default set of Detectors will be used.- Specified by:
setUserPreferences
in interfaceIFindBugsEngine
- Parameters:
userPreferences
- the UserPreferences
-
configureFilters
-
emitTrainingOutput
public boolean emitTrainingOutput()Description copied from interface:IFindBugsEngine
Return whether or not training output should be emitted after analysis completes.- Specified by:
emitTrainingOutput
in interfaceIFindBugsEngine
- Returns:
- true if training output should be emitted, false if not
-
getUserPreferences
Description copied from interface:IFindBugsEngine
Get the UserPreferences.- Specified by:
getUserPreferences
in interfaceIFindBugsEngine
- Returns:
- the UserPreferences
-
getTrainingInputDir
Description copied from interface:IFindBugsEngine
Get the training input database directory.- Specified by:
getTrainingInputDir
in interfaceIFindBugsEngine
- Returns:
- the training input database directory
-
getTrainingOutputDir
Description copied from interface:IFindBugsEngine
Get the training output directory.- Specified by:
getTrainingOutputDir
in interfaceIFindBugsEngine
- Returns:
- the training output directory
-
useTrainingInput
public boolean useTrainingInput()Description copied from interface:IFindBugsEngine
Return whether or not we should make use of training data.- Specified by:
useTrainingInput
in interfaceIFindBugsEngine
- Returns:
- true if training data should be used, false if not
-
setScanNestedArchives
public void setScanNestedArchives(boolean scanNestedArchives) Description copied from interface:IFindBugsEngine
Set whether or not nested archives should be scanned.- Specified by:
setScanNestedArchives
in interfaceIFindBugsEngine
- Parameters:
scanNestedArchives
- true if nested archives should be scanned, false if not
-
setNoClassOk
public void setNoClassOk(boolean noClassOk) Description copied from interface:IFindBugsEngine
Set whether or not to generate an empty output file if there were no class files specified.- Specified by:
setNoClassOk
in interfaceIFindBugsEngine
- Parameters:
noClassOk
- true if FindBugs should generate empty output file
-
createAnalysisCache
Create the analysis cache object and register it for current execution thread.This method is protected to allow clients override it and possibly reuse some previous analysis data (for Eclipse interactive re-build)
- Throws:
IOException
- if error occurs registering analysis engines in a plugin
-
registerBuiltInAnalysisEngines
Register the "built-in" analysis engines with given IAnalysisCache.- Parameters:
analysisCache
- an IAnalysisCache
-
registerPluginAnalysisEngines
public static void registerPluginAnalysisEngines(DetectorFactoryCollection detectorFactoryCollection, IAnalysisCache analysisCache) throws IOException Register all of the analysis engines defined in the plugins contained in a DetectorFactoryCollection with an IAnalysisCache.- Parameters:
detectorFactoryCollection
- a DetectorFactoryCollectionanalysisCache
- an IAnalysisCache- Throws:
IOException
-
sortByCallGraph
public List<ClassDescriptor> sortByCallGraph(Collection<ClassDescriptor> classList, TopologicalSort.OutEdges<ClassDescriptor> outEdges) -
clearAnalysisContext
public static void clearAnalysisContext() -
createAnalysisContext
public static void createAnalysisContext(Project project, List<ClassDescriptor> appClassList, @CheckForNull String sourceInfoFileName) throws IOException Create the AnalysisContext that will serve as the BCEL-compatibility layer over the AnalysisCache.- Parameters:
project
- The projectappClassList
- list of ClassDescriptors identifying application classessourceInfoFileName
- name of source info file (null if none)- Throws:
IOException
-
setAppClassList
-
main
- Throws:
Exception
-
setAbridgedMessages
public void setAbridgedMessages(boolean xmlWithAbridgedMessages) - Specified by:
setAbridgedMessages
in interfaceIFindBugsEngine
-
setMergeSimilarWarnings
public void setMergeSimilarWarnings(boolean mergeSimilarWarnings) - Specified by:
setMergeSimilarWarnings
in interfaceIFindBugsEngine
-
setApplySuppression
public void setApplySuppression(boolean applySuppression) - Specified by:
setApplySuppression
in interfaceIFindBugsEngine
-
setRankThreshold
public void setRankThreshold(int rankThreshold) - Specified by:
setRankThreshold
in interfaceIFindBugsEngine
-
finishSettings
public void finishSettings()- Specified by:
finishSettings
in interfaceIFindBugsEngine
-
setBugReporterDecorators
- Specified by:
setBugReporterDecorators
in interfaceIFindBugsEngine
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-