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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AnalysisOptionsprivate List<ClassDescriptor> private BugReporterprivate IClassFactoryprivate List<IClassObserver> private IClassPathprivate IClassScreenerprivate Stringstatic final booleanprivate DetectorFactoryCollectionprivate ErrorCountingBugReporterprivate ExecutionPlanprivate static final booleanprivate static final org.slf4j.Loggerstatic final booleanstatic final booleanprivate FindBugsProgressprivate Projectstatic final Stringstatic final Stringprivate intprivate Collection<ClassDescriptor> private static final booleanprivate final ExecutorServiceprivate static final boolean -
Constructor Summary
ConstructorsConstructorDescriptionConstructor that usesCurrentThreadExecutorServiceto keep backward compatibility with SpotBugs 3.1.FindBugs2(ExecutorService service) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClassObserver(IClassObserver classObserver) Add an IClassObserver.voidSet filter of bug instances to include or exclude.private voidAnalyze the classes in the application codebase.private voidBuild the classpath from project codebases and system codebases.private voidstatic voidprotected voidProtected to allow Eclipse plugin remember some cache data for later reusevoidclose()private voidConfigure analysis feature settings.protected voidconfigureFilters(UserPreferences userPreferences) protected IAnalysisCacheCreate the analysis cache object and register it for current execution thread.static voidcreateAnalysisContext(Project project, List<ClassDescriptor> appClassList, String sourceInfoFileName) Create the AnalysisContext that will serve as the BCEL-compatibility layer over the AnalysisCache.private voidCreate the classpath object.private voidCreate an execution plan.voiddispose()To avoid cyclic cross-references and allow GC after engine is no longer needed.booleanReturn whether or not training output should be emitted after analysis completes.voidenableTrainingInput(String trainingInputDir) Set whether or not training input should be used to make the analysis more precise.voidenableTrainingOutput(String trainingOutputDir) Set whether or not training output should be emitted.voidexcludeBaselineBugs(String baselineBugs) Provide baseline of bugs not to reportvoidexecute()Execute the analysis.voidintGet the number of bug instances that were reported during analysis.Get the BugReporter.Get the name of the most recent class to be analyzed.intGet the number of errors that occurred during analysis.intGet 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.private voidlogRecoverableException(ClassDescriptor classDescriptor, Detector2 detector, Throwable e) Report an exception that occurred while analyzing a class with a detector.static voidprivate voidnotifyClassObservers(ClassDescriptor classDescriptor) Notify all IClassObservers that we are visiting given class.static voidregisterBuiltInAnalysisEngines(IAnalysisCache analysisCache) Register the "built-in" analysis engines with given IAnalysisCache.static voidregisterPluginAnalysisEngines(DetectorFactoryCollection detectorFactoryCollection, IAnalysisCache analysisCache) Register all of the analysis engines defined in the plugins contained in a DetectorFactoryCollection with an IAnalysisCache.voidsetAbridgedMessages(boolean xmlWithAbridgedMessages) voidsetAnalysisFeatureSettings(AnalysisFeatureSetting[] settingList) Set analysis feature settings.static voidsetAppClassList(List<ClassDescriptor> appClassList) voidsetApplySuppression(boolean applySuppression) voidsetBugReporter(BugReporter bugReporter) Set the BugReporter.voidsetBugReporterDecorators(Set<String> explicitlyEnabled, Set<String> explicitlyDisabled) voidsetClassScreener(IClassScreener classScreener) Set the ClassScreener.voidsetDetectorFactoryCollection(DetectorFactoryCollection detectorFactoryCollection) Set the detector factory collection to be used by this FindBugs2 engine.voidsetMergeSimilarWarnings(boolean mergeSimilarWarnings) voidsetNoClassOk(boolean noClassOk) Set whether or not to generate an empty output file if there were no class files specified.voidsetProgressCallback(FindBugsProgress progressCallback) Set the progress callback that will be used to keep track of the progress of the analysis.voidsetProject(Project project) Set the Project.voidsetProjectName(String name) voidsetRankThreshold(int rankThreshold) voidsetRelaxedReportingMode(boolean relaxedReportingMode) Set relaxed reporting mode.voidsetReleaseName(String releaseName) voidsetScanNestedArchives(boolean scanNestedArchives) Set whether or not nested archives should be scanned.voidsetSourceInfoFile(String sourceInfoFile) Set the filename of the source info file containing line numbers for fields and classes.voidsetUserPreferences(UserPreferences userPreferences) Set the UserPreferences representing which Detectors should be used.sortByCallGraph(Collection<ClassDescriptor> classList, TopologicalSort.OutEdges<ClassDescriptor> outEdges) booleanReturn whether or not we should make use of training data.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
LIST_ORDER
private static final boolean LIST_ORDER -
VERBOSE
private static final boolean VERBOSE -
DEBUG
public static final boolean DEBUG -
PROGRESS
public static final boolean PROGRESS -
SCREEN_FIRST_PASS_CLASSES
private static final boolean SCREEN_FIRST_PASS_CLASSES -
MULTI_THREAD
public static final boolean MULTI_THREAD -
PROP_FINDBUGS_HOST_APP
- See Also:
-
PROP_FINDBUGS_HOST_APP_VERSION
- See Also:
-
rankThreshold
private int rankThreshold -
classObserverList
-
bugReporter
-
errorCountingBugReporter
-
project
-
classFactory
-
classPath
-
appClassList
-
referencedClassSet
-
detectorFactoryCollection
-
executionPlan
-
currentClassName
-
progressReporter
-
classScreener
-
analysisOptions
-
service
-
explicitlyEnabledBugReporterDecorators
-
explicitlyDisabledBugReporterDecorators
-
-
Constructor Details
-
FindBugs2
public FindBugs2()Constructor that usesCurrentThreadExecutorServiceto keep backward compatibility with SpotBugs 3.1.- Since:
- 3.1
-
FindBugs2
- Parameters:
service- The non-nullExecutorServiceinstance to execute analysis. Caller is responsible for shutting it down.- 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:
setDetectorFactoryCollectionin 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:
executein interfaceIFindBugsEngine- Throws:
IOExceptionInterruptedException
-
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 no longer needed. (used by Eclipse plugin)
Caller probably need to shutdown the
ExecutorServiceinstance provided at constructor. -
getBugReporter
Description copied from interface:IFindBugsEngineGet the BugReporter.- Specified by:
getBugReporterin interfaceIFindBugsEngine- Returns:
- the BugReporter
-
getProject
Description copied from interface:IFindBugsEngineGet the Project.- Specified by:
getProjectin interfaceIFindBugsEngine- Returns:
- the Project
-
addClassObserver
Description copied from interface:IFindBugsEngineAdd an IClassObserver.- Specified by:
addClassObserverin interfaceIFindBugsEngine- Parameters:
classObserver- the IClassObserver
-
addFilter
Description copied from interface:IFindBugsEngineSet filter of bug instances to include or exclude.- Specified by:
addFilterin 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:
IOExceptionFilterException
-
excludeBaselineBugs
public void excludeBaselineBugs(String baselineBugs) throws IOException, org.dom4j.DocumentException Description copied from interface:IFindBugsEngineProvide baseline of bugs not to report- Specified by:
excludeBaselineBugsin interfaceIFindBugsEngine- Parameters:
baselineBugs- the name of the xml bug baseline file- Throws:
org.dom4j.DocumentExceptionIOException
-
enableTrainingInput
Description copied from interface:IFindBugsEngineSet whether or not training input should be used to make the analysis more precise.- Specified by:
enableTrainingInputin interfaceIFindBugsEngine- Parameters:
trainingInputDir- directory to load training input from
-
enableTrainingOutput
Description copied from interface:IFindBugsEngineSet whether or not training output should be emitted.- Specified by:
enableTrainingOutputin interfaceIFindBugsEngine- Parameters:
trainingOutputDir- directory to save training output in
-
getBugCount
public int getBugCount()Description copied from interface:IFindBugsEngineGet the number of bug instances that were reported during analysis.- Specified by:
getBugCountin interfaceIFindBugsEngine
-
getCurrentClass
Description copied from interface:IFindBugsEngineGet 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:
getCurrentClassin interfaceIFindBugsEngine
-
getErrorCount
public int getErrorCount()Description copied from interface:IFindBugsEngineGet the number of errors that occurred during analysis.- Specified by:
getErrorCountin interfaceIFindBugsEngine
-
getMissingClassCount
public int getMissingClassCount()Description copied from interface:IFindBugsEngineGet the number of time missing classes were reported during analysis.- Specified by:
getMissingClassCountin interfaceIFindBugsEngine
-
getReleaseName
- Specified by:
getReleaseNamein interfaceIFindBugsEngine- Returns:
- Returns the releaseName.
-
getProjectName
- Specified by:
getProjectNamein interfaceIFindBugsEngine- Returns:
- Returns the projectName.
-
setProjectName
- Specified by:
setProjectNamein interfaceIFindBugsEngine- Parameters:
name- The project name to set.
-
setAnalysisFeatureSettings
Description copied from interface:IFindBugsEngineSet analysis feature settings.- Specified by:
setAnalysisFeatureSettingsin interfaceIFindBugsEngine- Parameters:
settingList- list of analysis feature settings
-
setBugReporter
Description copied from interface:IFindBugsEngineSet the BugReporter.- Specified by:
setBugReporterin interfaceIFindBugsEngine- Parameters:
bugReporter- The BugReporter to set
-
setClassScreener
Description copied from interface:IFindBugsEngineSet the ClassScreener. This object chooses which individual classes to analyze. By default, all classes are analyzed.- Specified by:
setClassScreenerin interfaceIFindBugsEngine- Parameters:
classScreener- the ClassScreener to use
-
setProgressCallback
Description copied from interface:IFindBugsEngineSet the progress callback that will be used to keep track of the progress of the analysis.- Specified by:
setProgressCallbackin interfaceIFindBugsEngine- Parameters:
progressCallback- the progress callback
-
setProject
Description copied from interface:IFindBugsEngineSet the Project.- Specified by:
setProjectin interfaceIFindBugsEngine- Parameters:
project- The Project to set
-
setRelaxedReportingMode
public void setRelaxedReportingMode(boolean relaxedReportingMode) Description copied from interface:IFindBugsEngineSet relaxed reporting mode.- Specified by:
setRelaxedReportingModein interfaceIFindBugsEngine- Parameters:
relaxedReportingMode- true if relaxed reporting mode should be enabled, false if not
-
setReleaseName
- Specified by:
setReleaseNamein interfaceIFindBugsEngine- Parameters:
releaseName- The releaseName to set.
-
setSourceInfoFile
Description copied from interface:IFindBugsEngineSet the filename of the source info file containing line numbers for fields and classes.- Specified by:
setSourceInfoFilein interfaceIFindBugsEngine- Parameters:
sourceInfoFile- the source info filename
-
setUserPreferences
Description copied from interface:IFindBugsEngineSet the UserPreferences representing which Detectors should be used. If UserPreferences are not set explicitly, the default set of Detectors will be used.- Specified by:
setUserPreferencesin interfaceIFindBugsEngine- Parameters:
userPreferences- the UserPreferences
-
configureFilters
-
emitTrainingOutput
public boolean emitTrainingOutput()Description copied from interface:IFindBugsEngineReturn whether or not training output should be emitted after analysis completes.- Specified by:
emitTrainingOutputin interfaceIFindBugsEngine- Returns:
- true if training output should be emitted, false if not
-
getUserPreferences
Description copied from interface:IFindBugsEngineGet the UserPreferences.- Specified by:
getUserPreferencesin interfaceIFindBugsEngine- Returns:
- the UserPreferences
-
createClassPath
private void createClassPath()Create the classpath object. -
getTrainingInputDir
Description copied from interface:IFindBugsEngineGet the training input database directory.- Specified by:
getTrainingInputDirin interfaceIFindBugsEngine- Returns:
- the training input database directory
-
getTrainingOutputDir
Description copied from interface:IFindBugsEngineGet the training output directory.- Specified by:
getTrainingOutputDirin interfaceIFindBugsEngine- Returns:
- the training output directory
-
useTrainingInput
public boolean useTrainingInput()Description copied from interface:IFindBugsEngineReturn whether or not we should make use of training data.- Specified by:
useTrainingInputin interfaceIFindBugsEngine- Returns:
- true if training data should be used, false if not
-
setScanNestedArchives
public void setScanNestedArchives(boolean scanNestedArchives) Description copied from interface:IFindBugsEngineSet whether or not nested archives should be scanned.- Specified by:
setScanNestedArchivesin interfaceIFindBugsEngine- Parameters:
scanNestedArchives- true if nested archives should be scanned, false if not
-
setNoClassOk
public void setNoClassOk(boolean noClassOk) Description copied from interface:IFindBugsEngineSet whether or not to generate an empty output file if there were no class files specified.- Specified by:
setNoClassOkin 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
-
buildClassPath
Build the classpath from project codebases and system codebases.- Throws:
InterruptedException- if the analysis thread is interruptedIOException- if an I/O error occursCheckedAnalysisException
-
buildReferencedClassSet
- Throws:
InterruptedException
-
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
-
configureAnalysisFeatures
private void configureAnalysisFeatures()Configure analysis feature settings. -
createExecutionPlan
Create an execution plan.- Throws:
OrderingConstraintException- if the detector ordering constraints are inconsistent
-
analyzeApplication
Analyze the classes in the application codebase.- Throws:
InterruptedException
-
notifyClassObservers
Notify all IClassObservers that we are visiting given class.- Parameters:
classDescriptor- the class being visited
-
logRecoverableException
private void logRecoverableException(ClassDescriptor classDescriptor, Detector2 detector, Throwable e) Report an exception that occurred while analyzing a class with a detector.- Parameters:
classDescriptor- class being analyzeddetector- detector doing the analysise- the exception
-
main
-
setAbridgedMessages
public void setAbridgedMessages(boolean xmlWithAbridgedMessages) - Specified by:
setAbridgedMessagesin interfaceIFindBugsEngine- Parameters:
xmlWithAbridgedMessages-
-
setMergeSimilarWarnings
public void setMergeSimilarWarnings(boolean mergeSimilarWarnings) - Specified by:
setMergeSimilarWarningsin interfaceIFindBugsEngine
-
setApplySuppression
public void setApplySuppression(boolean applySuppression) - Specified by:
setApplySuppressionin interfaceIFindBugsEngine
-
setRankThreshold
public void setRankThreshold(int rankThreshold) - Specified by:
setRankThresholdin interfaceIFindBugsEngine
-
finishSettings
public void finishSettings()- Specified by:
finishSettingsin interfaceIFindBugsEngine
-
setBugReporterDecorators
- Specified by:
setBugReporterDecoratorsin interfaceIFindBugsEngine
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-