Class FindBugs2

  • All Implemented Interfaces:
    IFindBugsEngine

    public class FindBugs2
    extends java.lang.Object
    implements IFindBugsEngine
    FindBugs driver class. Orchestrates the analysis of a project, collection of results, etc.
    Author:
    David Hovemeyer
    • Field Detail

      • DEBUG

        public static final boolean DEBUG
      • PROGRESS

        public static final boolean PROGRESS
      • PROP_FINDBUGS_HOST_APP

        public static final java.lang.String PROP_FINDBUGS_HOST_APP
        See Also:
        Constant Field Values
      • PROP_FINDBUGS_HOST_APP_VERSION

        public static final java.lang.String PROP_FINDBUGS_HOST_APP_VERSION
        See Also:
        Constant Field Values
    • Constructor Detail

      • FindBugs2

        public FindBugs2()
        Constructor.
    • Method Detail

      • setDetectorFactoryCollection

        public void setDetectorFactoryCollection​(DetectorFactoryCollection detectorFactoryCollection)
        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 interface IFindBugsEngine
        Parameters:
        detectorFactoryCollection - The detectorFactoryCollection to set.
      • execute

        public void execute()
                     throws java.io.IOException,
                            java.lang.InterruptedException
        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 interface IFindBugsEngine
        Throws:
        java.io.IOException
        java.lang.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)
      • addFilter

        public void addFilter​(java.lang.String filterFileName,
                              boolean include)
                       throws java.io.IOException,
                              FilterException
        Description copied from interface: IFindBugsEngine
        Set filter of bug instances to include or exclude.
        Specified by:
        addFilter in interface IFindBugsEngine
        Parameters:
        filterFileName - the name of the filter file
        include - true if the filter specifies bug instances to include, false if it specifies bug instances to exclude
        Throws:
        java.io.IOException
        FilterException
      • excludeBaselineBugs

        public void excludeBaselineBugs​(java.lang.String baselineBugs)
                                 throws java.io.IOException,
                                        org.dom4j.DocumentException
        Description copied from interface: IFindBugsEngine
        Provide baseline of bugs not to report
        Specified by:
        excludeBaselineBugs in interface IFindBugsEngine
        Parameters:
        baselineBugs - the name of the xml bug baseline file
        Throws:
        org.dom4j.DocumentException
        java.io.IOException
      • enableTrainingInput

        public void enableTrainingInput​(java.lang.String trainingInputDir)
        Description copied from interface: IFindBugsEngine
        Set whether or not training input should be used to make the analysis more precise.
        Specified by:
        enableTrainingInput in interface IFindBugsEngine
        Parameters:
        trainingInputDir - directory to load training input from
      • enableTrainingOutput

        public void enableTrainingOutput​(java.lang.String trainingOutputDir)
        Description copied from interface: IFindBugsEngine
        Set whether or not training output should be emitted.
        Specified by:
        enableTrainingOutput in interface IFindBugsEngine
        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 interface IFindBugsEngine
      • getCurrentClass

        public java.lang.String 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 interface IFindBugsEngine
      • getReleaseName

        public java.lang.String getReleaseName()
        Specified by:
        getReleaseName in interface IFindBugsEngine
        Returns:
        Returns the releaseName.
      • getProjectName

        public java.lang.String getProjectName()
        Specified by:
        getProjectName in interface IFindBugsEngine
        Returns:
        Returns the projectName.
      • setProjectName

        public void setProjectName​(java.lang.String name)
        Specified by:
        setProjectName in interface IFindBugsEngine
        Parameters:
        name - The project name to set.
      • setClassScreener

        public void setClassScreener​(IClassScreener classScreener)
        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 interface IFindBugsEngine
        Parameters:
        classScreener - the ClassScreener to use
      • setProgressCallback

        public void setProgressCallback​(FindBugsProgress progressCallback)
        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 interface IFindBugsEngine
        Parameters:
        progressCallback - the progress callback
      • setRelaxedReportingMode

        public void setRelaxedReportingMode​(boolean relaxedReportingMode)
        Description copied from interface: IFindBugsEngine
        Set relaxed reporting mode.
        Specified by:
        setRelaxedReportingMode in interface IFindBugsEngine
        Parameters:
        relaxedReportingMode - true if relaxed reporting mode should be enabled, false if not
      • setReleaseName

        public void setReleaseName​(java.lang.String releaseName)
        Specified by:
        setReleaseName in interface IFindBugsEngine
        Parameters:
        releaseName - The releaseName to set.
      • setSourceInfoFile

        public void setSourceInfoFile​(java.lang.String sourceInfoFile)
        Description copied from interface: IFindBugsEngine
        Set the filename of the source info file containing line numbers for fields and classes.
        Specified by:
        setSourceInfoFile in interface IFindBugsEngine
        Parameters:
        sourceInfoFile - the source info filename
      • setUserPreferences

        public void setUserPreferences​(UserPreferences userPreferences)
        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 interface IFindBugsEngine
        Parameters:
        userPreferences - the UserPreferences
      • configureFilters

        protected void configureFilters​(UserPreferences userPreferences)
      • 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 interface IFindBugsEngine
        Returns:
        true if training output should be emitted, false if not
      • getTrainingInputDir

        public java.lang.String getTrainingInputDir()
        Description copied from interface: IFindBugsEngine
        Get the training input database directory.
        Specified by:
        getTrainingInputDir in interface IFindBugsEngine
        Returns:
        the training input database directory
      • getTrainingOutputDir

        public java.lang.String getTrainingOutputDir()
        Description copied from interface: IFindBugsEngine
        Get the training output directory.
        Specified by:
        getTrainingOutputDir in interface IFindBugsEngine
        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 interface IFindBugsEngine
        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 interface IFindBugsEngine
        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 interface IFindBugsEngine
        Parameters:
        noClassOk - true if FindBugs should generate empty output file
      • createAnalysisCache

        protected IAnalysisCache createAnalysisCache()
                                              throws java.io.IOException
        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:
        java.io.IOException - if error occurs registering analysis engines in a plugin
      • registerBuiltInAnalysisEngines

        public static void registerBuiltInAnalysisEngines​(IAnalysisCache analysisCache)
        Register the "built-in" analysis engines with given IAnalysisCache.
        Parameters:
        analysisCache - an IAnalysisCache
      • registerPluginAnalysisEngines

        public static void registerPluginAnalysisEngines​(DetectorFactoryCollection detectorFactoryCollection,
                                                         IAnalysisCache analysisCache)
                                                  throws java.io.IOException
        Register all of the analysis engines defined in the plugins contained in a DetectorFactoryCollection with an IAnalysisCache.
        Parameters:
        detectorFactoryCollection - a DetectorFactoryCollection
        analysisCache - an IAnalysisCache
        Throws:
        java.io.IOException
      • clearAnalysisContext

        public static void clearAnalysisContext()
      • createAnalysisContext

        public static void createAnalysisContext​(Project project,
                                                 java.util.List<ClassDescriptor> appClassList,
                                                 @CheckForNull
                                                 java.lang.String sourceInfoFileName)
                                          throws java.io.IOException
        Create the AnalysisContext that will serve as the BCEL-compatibility layer over the AnalysisCache.
        Parameters:
        project - The project
        appClassList - list of ClassDescriptors identifying application classes
        sourceInfoFileName - name of source info file (null if none)
        Throws:
        java.io.IOException
      • setAppClassList

        public static void setAppClassList​(java.util.List<ClassDescriptor> appClassList)
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setBugReporterDecorators

        public void setBugReporterDecorators​(java.util.Set<java.lang.String> explicitlyEnabled,
                                             java.util.Set<java.lang.String> explicitlyDisabled)
        Specified by:
        setBugReporterDecorators in interface IFindBugsEngine