Class SortedBugCollection

java.lang.Object
edu.umd.cs.findbugs.SortedBugCollection
All Implemented Interfaces:
BugCollection, Iterable<BugInstance>

public class SortedBugCollection extends Object implements BugCollection
An implementation of BugCollection that keeps the BugInstances sorted by class (using the native comparison ordering of BugInstance's compareTo() method as a tie-breaker).
Author:
David Hovemeyer
See Also:
  • Constructor Details

    • SortedBugCollection

      public SortedBugCollection(Project project)
    • SortedBugCollection

      public SortedBugCollection(File f) throws IOException, org.dom4j.DocumentException
      Throws:
      IOException
      org.dom4j.DocumentException
    • SortedBugCollection

      public SortedBugCollection()
      Constructor. Creates an empty object.
    • SortedBugCollection

      public SortedBugCollection(Comparator<BugInstance> comparator)
      Constructor. Creates an empty object.
    • SortedBugCollection

      public SortedBugCollection(ProjectStats projectStats)
      Constructor. Creates an empty object given an existing ProjectStats.
      Parameters:
      projectStats - the ProjectStats
    • SortedBugCollection

      public SortedBugCollection(ProjectStats projectStats, Project project)
    • SortedBugCollection

      public SortedBugCollection(ProjectStats projectStats, Comparator<BugInstance> comparator)
      Constructor. Creates an empty object given an existing ProjectStats.
      Parameters:
      projectStats - the ProjectStats
      comparator - to use for sorting bug instances
    • SortedBugCollection

      public SortedBugCollection(ProjectStats projectStats, Comparator<BugInstance> comparator, Project project)
  • Method Details

    • getTimeStartedLoading

      public long getTimeStartedLoading()
    • getTimeFinishedLoading

      public long getTimeFinishedLoading()
    • getDataSource

      public String getDataSource()
    • getProject

      public Project getProject()
      Specified by:
      getProject in interface BugCollection
    • isApplySuppressions

      public boolean isApplySuppressions()
      Specified by:
      isApplySuppressions in interface BugCollection
    • setApplySuppressions

      public void setApplySuppressions(boolean applySuppressions)
      Specified by:
      setApplySuppressions in interface BugCollection
    • getAnalysisTimestamp

      public long getAnalysisTimestamp()
      Description copied from interface: BugCollection
      Get the timestamp for when the analysis was performed.
      Specified by:
      getAnalysisTimestamp in interface BugCollection
    • setAnalysisTimestamp

      public void setAnalysisTimestamp(long timestamp)
      Description copied from interface: BugCollection
      Set the timestamp for when the analysis was performed.
      Specified by:
      setAnalysisTimestamp in interface BugCollection
      Parameters:
      timestamp - the analysis timestamp.
    • addAll

      public void addAll(Collection<BugInstance> collection)
      Add a Collection of BugInstances to this BugCollection object. This just calls add(BugInstance) for each instance in the input collection.
      Parameters:
      collection - the Collection of BugInstances to add
    • addAll

      public void addAll(Collection<BugInstance> collection, boolean updateActiveTime)
      Add a Collection of BugInstances to this BugCollection object.
      Parameters:
      collection - the Collection of BugInstances to add
      updateActiveTime - true if active time of added BugInstances should be updated to match collection: false if not
    • add

      public boolean add(BugInstance bugInstance)
      Add a BugInstance to this BugCollection. This just calls add(bugInstance, true).
      Specified by:
      add in interface BugCollection
      Parameters:
      bugInstance - the BugInstance
      Returns:
      true if the BugInstance was added, or false if a matching BugInstance was already in the BugCollection
    • addError

      public void addError(String message)
      Add an analysis error.
      Specified by:
      addError in interface BugCollection
      Parameters:
      message - the error message
    • getCurrentAppVersion

      public AppVersion getCurrentAppVersion()
      Get the current AppVersion.
      Specified by:
      getCurrentAppVersion in interface BugCollection
    • readXML

      public void readXML(String fileName) throws IOException, org.dom4j.DocumentException
      Read XML data from given file into this object, populating given Project as a side effect.
      Specified by:
      readXML in interface BugCollection
      Parameters:
      fileName - name of the file to read
      Throws:
      IOException
      org.dom4j.DocumentException
    • readXML

      public void readXML(File file) throws IOException, org.dom4j.DocumentException
      Read XML data from given file into this object, populating given Project as a side effect.
      Parameters:
      file - the file
      Throws:
      IOException
      org.dom4j.DocumentException
    • readXML

      public void readXML(URL u) throws IOException, org.dom4j.DocumentException
      Throws:
      IOException
      org.dom4j.DocumentException
    • readXML

      public void readXML(@WillClose InputStream in, File base) throws IOException, org.dom4j.DocumentException
      Read XML data from given input stream into this object, populating the Project as a side effect. An attempt will be made to close the input stream (even if an exception is thrown).
      Parameters:
      in - the InputStream
      Throws:
      IOException
      org.dom4j.DocumentException
    • readXML

      public void readXML(@WillClose InputStream in) throws IOException, org.dom4j.DocumentException
      Description copied from interface: BugCollection
      Read XML data from given input stream into this object, populating the Project as a side effect. An attempt will be made to close the input stream (even if an exception is thrown).
      Specified by:
      readXML in interface BugCollection
      Parameters:
      in - the InputStream
      Throws:
      IOException
      org.dom4j.DocumentException
    • readXML

      public void readXML(@WillClose Reader reader) throws IOException, org.dom4j.DocumentException
      Description copied from interface: BugCollection
      Read XML data from given reader into this object, populating the Project as a side effect. An attempt will be made to close the reader (even if an exception is thrown).
      Specified by:
      readXML in interface BugCollection
      Parameters:
      reader - the Reader
      Throws:
      IOException
      org.dom4j.DocumentException
    • writeXML

      public void writeXML(OutputStream out) throws IOException
      Description copied from interface: BugCollection
      Write the BugCollection to given output stream as XML using a UTF8 encoding. The output stream will be closed, even if an exception is thrown.
      Specified by:
      writeXML in interface BugCollection
      Parameters:
      out - the OutputStream to write to
      Throws:
      IOException
    • writeXML

      public void writeXML(String fileName) throws IOException
      Write this BugCollection to a file as XML.
      Specified by:
      writeXML in interface BugCollection
      Parameters:
      fileName - the file to write to
      Throws:
      IOException
    • writeXML

      public void writeXML(File file) throws IOException
      Write this BugCollection to a file as XML.
      Parameters:
      file - the file to write to
      Throws:
      IOException
    • toDocument

      public org.dom4j.Document toDocument()
      Convert the BugCollection into a dom4j Document object.
      Specified by:
      toDocument in interface BugCollection
      Returns:
      the Document representing the BugCollection as a dom4j tree
    • writeXML

      public void writeXML(@WillClose Writer out) throws IOException
      Write the BugCollection to given output stream as XML. The output stream will be closed, even if an exception is thrown.
      Specified by:
      writeXML in interface BugCollection
      Parameters:
      out - the OutputStream to write to
      Throws:
      IOException
    • writePrologue

      public void writePrologue(XMLOutput xmlOutput) throws IOException
      Specified by:
      writePrologue in interface BugCollection
      Throws:
      IOException
    • computeBugHashes

      public void computeBugHashes()
    • writeXML

      public void writeXML(@WillClose XMLOutput xmlOutput) throws IOException
      Write the BugCollection to an XMLOutput object. The finish() method of the XMLOutput object is guaranteed to be called.

      To write the SummaryHTML element, set property findbugs.report.SummaryHTML to "true".

      Specified by:
      writeXML in interface BugCollection
      Parameters:
      xmlOutput - the XMLOutput object
      Throws:
      IOException
    • writeEpilogue

      public void writeEpilogue(XMLOutput xmlOutput) throws IOException
      Specified by:
      writeEpilogue in interface BugCollection
      Throws:
      IOException
    • cloneAll

      public static void cloneAll(Collection<BugInstance> dest, Collection<BugInstance> source)
      Clone all of the BugInstance objects in the source Collection and add them to the destination Collection.
      Parameters:
      dest - the destination Collection
      source - the source Collection
    • add

      public boolean add(BugInstance bugInstance, boolean updateActiveTime)
      Description copied from interface: BugCollection
      Add a BugInstance to this BugCollection.
      Specified by:
      add in interface BugCollection
      Parameters:
      bugInstance - the BugInstance
      updateActiveTime - true if the warning's active time should be updated to include the collection's current time
      Returns:
      true if the BugInstance was added, or false if a matching BugInstance was already in the BugCollection
    • remove

      public boolean remove(BugInstance bugInstance)
    • iterator

      public Iterator<BugInstance> iterator()
      Description copied from interface: BugCollection
      Return an Iterator over all the BugInstance objects in the BugCollection.
      Specified by:
      iterator in interface BugCollection
      Specified by:
      iterator in interface Iterable<BugInstance>
    • getCollection

      public Collection<BugInstance> getCollection()
      Description copied from interface: BugCollection
      Return the Collection storing the BugInstance objects.
      Specified by:
      getCollection in interface BugCollection
    • addError

      public void addError(String message, Throwable exception)
    • addError

      public void addError(AnalysisError error)
      Description copied from interface: BugCollection
      Add an analysis error.
      Specified by:
      addError in interface BugCollection
      Parameters:
      error - the AnalysisError object to add
    • clearErrors

      public void clearErrors()
    • addMissingClass

      public void addMissingClass(String className)
      Description copied from interface: BugCollection
      Add a missing class message.
      Specified by:
      addMissingClass in interface BugCollection
      Parameters:
      className - the missing class message
    • getErrors

      public Collection<? extends AnalysisError> getErrors()
    • missingClassIterator

      public Iterator<String> missingClassIterator()
    • contains

      public boolean contains(BugInstance bugInstance)
    • getMatching

      public BugInstance getMatching(BugInstance bugInstance)
    • getSummaryHTML

      public String getSummaryHTML() throws IOException
      Throws:
      IOException
    • getProjectStats

      public ProjectStats getProjectStats()
      Description copied from interface: BugCollection
      Get the project stats.
      Specified by:
      getProjectStats in interface BugCollection
    • lookupFromUniqueId

      @Deprecated public BugInstance lookupFromUniqueId(String uniqueId)
      Deprecated.
      Description copied from interface: BugCollection
      Look up a BugInstance by its unique id.
      Specified by:
      lookupFromUniqueId in interface BugCollection
      Parameters:
      uniqueId - the BugInstance's unique id.
      Returns:
      the BugInstance with the given unique id, or null if there is no such BugInstance This is deprecated; uniqueIDs are not persistent.
    • isMultiversion

      public boolean isMultiversion()
      Returns whether this bug collection contains results from multiple analysis runs, either of different version of the software or from different versions of FindBugs.
      Specified by:
      isMultiversion in interface BugCollection
    • hasDeadBugs

      public boolean hasDeadBugs()
      Specified by:
      hasDeadBugs in interface BugCollection
    • getSequenceNumber

      public long getSequenceNumber()
      Description copied from interface: BugCollection
      Get the sequence number of the BugCollection. This value represents the number of times the user has analyzed a different version of the application and updated the historical bug collection using the UpdateBugCollection class.
      Specified by:
      getSequenceNumber in interface BugCollection
      Returns:
      the sequence number
    • setSequenceNumber

      public void setSequenceNumber(long sequence)
      Description copied from interface: BugCollection
      Set the sequence number of the BugCollection.
      Specified by:
      setSequenceNumber in interface BugCollection
      Parameters:
      sequence - the sequence number
      See Also:
    • duplicate

      public SortedBugCollection duplicate()
    • createEmptyCollectionWithMetadata

      public SortedBugCollection createEmptyCollectionWithMetadata()
      Description copied from interface: BugCollection
      Create a new empty BugCollection with the same metadata as this one.
      Specified by:
      createEmptyCollectionWithMetadata in interface BugCollection
      Returns:
      a new empty BugCollection with the same metadata as this one
    • clearBugInstances

      public void clearBugInstances()
    • clearMissingClasses

      public void clearMissingClasses()
      Specified by:
      clearMissingClasses in interface BugCollection
    • getReleaseName

      public String getReleaseName()
      Description copied from interface: BugCollection
      Get the current release name.
      Specified by:
      getReleaseName in interface BugCollection
      Returns:
      current release name
    • setReleaseName

      public void setReleaseName(String releaseName)
      Description copied from interface: BugCollection
      Set the current release name.
      Specified by:
      setReleaseName in interface BugCollection
      Parameters:
      releaseName - the current release name
    • appVersionIterator

      public Iterator<AppVersion> appVersionIterator()
      Description copied from interface: BugCollection
      Get an Iterator over AppVersions defined in the collection.
      Specified by:
      appVersionIterator in interface BugCollection
    • addAppVersion

      public void addAppVersion(AppVersion appVersion)
      Description copied from interface: BugCollection
      Add an AppVersion representing a version of the analyzed application.
      Specified by:
      addAppVersion in interface BugCollection
      Parameters:
      appVersion - the AppVersion
    • clearAppVersions

      public void clearAppVersions()
      Description copied from interface: BugCollection
      Clear all AppVersions representing previously-analyzed versions of the application.
      Specified by:
      clearAppVersions in interface BugCollection
    • trimAppVersions

      public void trimAppVersions(long numberToRetain)
    • setTimestamp

      public void setTimestamp(long timestamp)
      Description copied from interface: BugCollection
      Get the timestamp for the analyzed code (when it was compiled)
      Specified by:
      setTimestamp in interface BugCollection
      Parameters:
      timestamp - the timestamp.
    • getTimestamp

      public long getTimestamp()
      Description copied from interface: BugCollection
      Get the timestamp for the analyzed code (when it was compiled)
      Specified by:
      getTimestamp in interface BugCollection
    • getClassFeatureSet

      public ClassFeatureSet getClassFeatureSet(String className)
    • setClassFeatureSet

      public void setClassFeatureSet(ClassFeatureSet classFeatureSet)
      Specified by:
      setClassFeatureSet in interface BugCollection
    • classFeatureSetIterator

      public Iterator<ClassFeatureSet> classFeatureSetIterator()
    • clearClassFeatures

      public void clearClassFeatures()
      Specified by:
      clearClassFeatures in interface BugCollection
    • setWithMessages

      public void setWithMessages(boolean withMessages)
      Description copied from interface: BugCollection
      Set whether textual messages should be added to any generated XML
      Specified by:
      setWithMessages in interface BugCollection
    • getWithMessages

      public boolean getWithMessages()
      Description copied from interface: BugCollection
      Return whether textual messages will be added to any generated XML
      Specified by:
      getWithMessages in interface BugCollection
    • getAppVersionFromSequenceNumber

      public AppVersion getAppVersionFromSequenceNumber(long target)
      Description copied from interface: BugCollection
      Gets the AppVersion corresponding to the given sequence number.
      Specified by:
      getAppVersionFromSequenceNumber in interface BugCollection
    • findBug

      public BugInstance findBug(String instanceHash, String bugType, int lineNumber)
      Specified by:
      findBug in interface BugCollection
    • setAnalysisVersion

      public void setAnalysisVersion(String version)
      Description copied from interface: BugCollection
      Set the version of FindBugs used to perform the analysis
      Specified by:
      setAnalysisVersion in interface BugCollection
      Parameters:
      version - the analysis version.
    • getAnalysisVersion

      public String getAnalysisVersion()
    • progessMonitoredInputStream

      public InputStream progessMonitoredInputStream(File f, String msg) throws IOException
      Throws:
      IOException
    • progessMonitoredInputStream

      public InputStream progessMonitoredInputStream(URLConnection c, String msg) throws IOException
      Throws:
      IOException
    • progressMonitoredInputStream

      public InputStream progressMonitoredInputStream(InputStream in, int length, String msg)
    • wrapGzip

      public InputStream wrapGzip(InputStream in, Object source)
    • setMinimalXML

      public void setMinimalXML(boolean minimalXML)
      Description copied from interface: BugCollection
      Set whether we should minimize XML
      Specified by:
      setMinimalXML in interface BugCollection
    • bugsPopulated

      public void bugsPopulated()
      Specified by:
      bugsPopulated in interface BugCollection
    • toString

      public String toString()
      Overrides:
      toString in class Object