Class ChecksAndFilesSuppressionFileGeneratorAuditListener

java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.ChecksAndFilesSuppressionFileGeneratorAuditListener
All Implemented Interfaces:
AuditListener, Configurable, Contextualizable, EventListener

Generates suppressions.xml file, based on violations occurred. See issue #5983
  • Field Details

  • Constructor Details

  • Method Details

    • fileStarted

      public void fileStarted(AuditEvent event)
      Description copied from interface: AuditListener
      Notify that audit is about to start on a specific file.
      Specified by:
      fileStarted in interface AuditListener
      Parameters:
      event - the event details
    • fileFinished

      public void fileFinished(AuditEvent event)
      Description copied from interface: AuditListener
      Notify that audit is finished on a specific file.
      Specified by:
      fileFinished in interface AuditListener
      Parameters:
      event - the event details
    • auditStarted

      public void auditStarted(AuditEvent event)
      Description copied from interface: AuditListener
      Notify that the audit is about to start.
      Specified by:
      auditStarted in interface AuditListener
      Parameters:
      event - the event details
    • auditFinished

      public void auditFinished(AuditEvent event)
      Description copied from interface: AuditListener
      Notify that the audit is finished.
      Specified by:
      auditFinished in interface AuditListener
      Parameters:
      event - the event details
    • addError

      public void addError(AuditEvent event)
      Description copied from interface: AuditListener
      Notify that an audit error was discovered on a specific file.
      Specified by:
      addError in interface AuditListener
      Parameters:
      event - the event details
    • isFileAndCheckNamePresent

      private boolean isFileAndCheckNamePresent(Path fileName, String checkName)
      Checks whether the check name is already associated with the given file in the FilesAndChecksCollector map.
      Parameters:
      fileName - The path of the file where the violation occurred.
      checkName - The name of the check that triggered the violation.
      Returns:
      true if the collector already contains the check name for the file, false otherwise.
    • isFileAndModuleIdPresent

      private boolean isFileAndModuleIdPresent(Path fileName, String moduleIdName)
      Checks the FilesAndModuleIdCollector map to see if the module ID has already been recorded for the specified file.
      Parameters:
      fileName - The path of the file where the violation occurred.
      moduleIdName - The module ID associated with the check name which trigger violation.
      Returns:
      true if the module ID is not yet recorded for the file, false otherwise.
    • addException

      public void addException(AuditEvent event, Throwable throwable)
      Description copied from interface: AuditListener
      Notify that an exception happened while performing audit.
      Specified by:
      addException in interface AuditListener
      Parameters:
      event - the event details
      throwable - details of the exception
    • suppressXmlWriter

      private void suppressXmlWriter(Path fileName, String checkName, String moduleIdName)
      Prints XML suppression with check/id and file name.
      Parameters:
      fileName - The file path associated with the check or module ID.
      checkName - The check name to write if moduleIdName is null.
      moduleIdName - The module ID name to write if null, checkName is used instead.
    • addCheckOrModuleId

      private void addCheckOrModuleId(Path fileName, String checkName, String moduleIdName)
      Adds either the check name or module ID to the corresponding collector map for the specified file path.
      Parameters:
      fileName - The path of the file associated with the check or module ID.
      checkName - The name of the check to add if moduleIdName is null.
      moduleIdName - The name of the module ID to add if null, checkName is used instead.
    • addToCollector

      private static void addToCollector(Map<Path,Set<String>> collector, Path fileName, String value)
      Adds a value (either a check name or module ID) to the set associated with the given file in the specified collector map.
      Parameters:
      collector - The map that collects values (check names or module IDs) for each file.
      fileName - The file path for which the value should be recorded.
      value - the check name or module ID to add to the set for the specified file.
    • printXmlHeader

      private void printXmlHeader()
      Prints XML header if only it was not printed before.
    • finishLocalSetup

      protected void finishLocalSetup()
      Description copied from class: AbstractAutomaticBean
      Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.

      The default implementation does nothing.

      Specified by:
      finishLocalSetup in class AbstractAutomaticBean