Class AllCheckSummaries

java.lang.Object
org.apache.maven.doxia.macro.AbstractMacro
com.puppycrawl.tools.checkstyle.site.AllCheckSummaries
All Implemented Interfaces:
org.apache.maven.doxia.logging.LogEnabled, org.apache.maven.doxia.macro.Macro

@Component(role=org.apache.maven.doxia.macro.Macro.class, hint="allCheckSummaries") public class AllCheckSummaries extends org.apache.maven.doxia.macro.AbstractMacro
Macro to generate table rows for all Checkstyle modules. Includes every Check.java file that has a Javadoc. Uses href path structure based on src/site/xdoc/checks. Usage:
 <macro name="allCheckSummaries"/>
 

Supports optional "package" parameter to filter checks by package. When package parameter is provided, only checks from that package are included. Usage:

 <macro name="allCheckSummaries">
   <param name="package" value="annotation"/>
 </macro>
 
  • Field Details

  • Constructor Details

  • Method Details

    • execute

      public void execute(org.apache.maven.doxia.sink.Sink sink, org.apache.maven.doxia.macro.MacroRequest request) throws org.apache.maven.doxia.macro.MacroExecutionException
      Throws:
      org.apache.maven.doxia.macro.MacroExecutionException
    • processCheckFiles

      private static void processCheckFiles(Map<String,AllCheckSummaries.CheckInfo> infos, Map<String,String> xmlHrefMap, String packageFilter) throws org.apache.maven.doxia.macro.MacroExecutionException
      Scans Java sources and populates info map with modules having Javadoc.
      Parameters:
      infos - map of collected module info
      xmlHrefMap - map of XML-to-HTML hrefs
      packageFilter - optional package to filter by, null for all
      Throws:
      org.apache.maven.doxia.macro.MacroExecutionException - if file walk fails
    • isCheckOrHolderFile

      private static boolean isCheckOrHolderFile(Path path)
      Checks if a path is a Check or Holder Java file.
      Parameters:
      path - the path to check
      Returns:
      true if the path is a Check or Holder file, false otherwise
    • isHolder

      private static boolean isHolder(String moduleName)
      Checks if a module is a holder type.
      Parameters:
      moduleName - the module name
      Returns:
      true if the module is a holder, false otherwise
    • processCheckFile

      private static void processCheckFile(Path path, Map<String,AllCheckSummaries.CheckInfo> infos, Map<String,String> xmlHrefMap, String packageFilter)
      Processes a single check class file and extracts metadata.
      Parameters:
      path - the check class file
      infos - map of results
      xmlHrefMap - map of XML hrefs
      packageFilter - optional package to filter by, null for all
      Throws:
      IllegalArgumentException - if macro execution fails
    • determineModuleInfo

      private static String[] determineModuleInfo(Path path, String moduleName)
      Determines the simple name and package name for a check module.
      Parameters:
      path - the check class file
      moduleName - the full module name
      Returns:
      array with [simpleName, packageName]
    • getDescriptionIfPresent

      @Nullable private static String getDescriptionIfPresent(DetailNode javadoc)
      Returns the module description if present and non-empty.
      Parameters:
      javadoc - the parsed Javadoc node
      Returns:
      the description text, or null if not present
    • buildTableRows

      private static void buildTableRows(Map<String,AllCheckSummaries.CheckInfo> infos, StringBuilder normalRows, StringBuilder holderRows)
      Builds HTML rows for both normal and holder check modules.
      Parameters:
      infos - map of collected module info
      normalRows - builder for normal check rows
      holderRows - builder for holder check rows
    • buildTableRow

      Builds a single table row for a check module.
      Parameters:
      info - check module information
      Returns:
      the HTML table row as a string
    • removeLeadingNewline

      private static void removeLeadingNewline(StringBuilder builder)
      Removes leading newline characters from a StringBuilder.
      Parameters:
      builder - the StringBuilder to process
    • appendHolderSection

      private static void appendHolderSection(org.apache.maven.doxia.sink.Sink sink, StringBuilder holderRows)
      Appends the Holder Checks HTML section.
      Parameters:
      sink - the output sink
      holderRows - the holder rows content
    • appendFilteredHolderSection

      private static void appendFilteredHolderSection(org.apache.maven.doxia.sink.Sink sink, StringBuilder holderRows, String packageName)
      Appends the filtered Holder Checks section for package views.
      Parameters:
      sink - the output sink
      holderRows - the holder rows content
      packageName - the package name
    • getPackageDisplayName

      private static String getPackageDisplayName(String packageName)
      Get display name for package (capitalize first letter).
      Parameters:
      packageName - the package name
      Returns:
      the capitalized package name
    • buildXmlHtmlMap

      private static Map<String,String> buildXmlHtmlMap()
      Builds map of XML file names to HTML documentation paths.
      Returns:
      map of lowercase check names to hrefs
    • isValidXmlFile

      private static boolean isValidXmlFile(Path path)
      Checks if a path is a valid XML file for processing.
      Parameters:
      path - the path to check
      Returns:
      true if the path is a valid XML file, false otherwise
    • addXmlHtmlMapping

      private static void addXmlHtmlMapping(Path path, Map<String,String> map)
      Adds XML-to-HTML mapping entry to map.
      Parameters:
      path - the XML file path
      map - the mapping to update
    • resolveHref

      private static String resolveHref(Map<String,String> xmlMap, String category, String simpleName, @Nullable String packageFilter)
      Resolves the href for a given check module. When packageFilter is null, returns full path: checks/category/filename.html#CheckName When packageFilter is set, returns relative path: filename.html#CheckName
      Parameters:
      xmlMap - map of XML file names to HTML paths
      category - the category of the check
      simpleName - simple name of the check
      packageFilter - optional package filter, null for all checks
      Returns:
      the resolved href for the check
    • extractCategoryFromJavaPath

      private static String extractCategoryFromJavaPath(Path javaPath)
      Extracts category path from a Java file path.
      Parameters:
      javaPath - the Java source file path
      Returns:
      the category path extracted from the Java path
    • sanitizeAnchorUrls

      private static String sanitizeAnchorUrls(String html)
      Sanitizes URLs within anchor tags by removing whitespace from href attributes.
      Parameters:
      html - the HTML string containing anchor tags
      Returns:
      the HTML with sanitized URLs
    • sanitizeAndFirstSentence

      private static String sanitizeAndFirstSentence(String html)
      Sanitizes HTML and extracts first sentence. Preserves anchor tags while removing other HTML formatting. Also cleans whitespace from URLs in href attributes.
      Parameters:
      html - the HTML string to process
      Returns:
      the sanitized first sentence
    • extractFirstSentence

      private static String extractFirstSentence(String text)
      Extracts first sentence from plain text.
      Parameters:
      text - the text to process
      Returns:
      the first sentence extracted from the text
    • wrapSummary

      private static String wrapSummary(String text)
      Wraps long summaries to avoid exceeding line width. Preserves URLs in anchor tags by breaking after the opening tag's closing bracket.
      Parameters:
      text - the text to wrap
      Returns:
      the wrapped text
    • calculateBreakPoint

      private static int calculateBreakPoint(String clean, int cleanIndex, int idealBreak)
      Calculates the appropriate break point for text wrapping. Handles anchor tags specially to avoid breaking URLs.
      Parameters:
      clean - the cleaned text to process
      cleanIndex - current position in text
      idealBreak - ideal break position
      Returns:
      the actual break position
    • shouldBreakAfterAnchorOpen

      private static boolean shouldBreakAfterAnchorOpen(int anchorStart, int anchorOpenEnd, int idealBreak)
      Determines if break should occur after anchor opening tag.
      Parameters:
      anchorStart - start position of anchor tag
      anchorOpenEnd - end position of anchor opening tag
      idealBreak - ideal break position
      Returns:
      true if should break after anchor opening
    • shouldBreakAfterAnchorContent

      private static boolean shouldBreakAfterAnchorContent(int anchorStart, int anchorOpenEnd, int idealBreak, String clean)
      Determines if break should occur after anchor content.
      Parameters:
      anchorStart - start position of anchor tag
      anchorOpenEnd - end position of anchor opening tag
      idealBreak - ideal break position
      clean - the text being processed
      Returns:
      true if should break after anchor content
    • findSafeBreakPoint

      private static int findSafeBreakPoint(String text, int start, int idealBreak)
      Finds a safe break point at a space character.
      Parameters:
      text - the text to search
      start - the start index
      idealBreak - the ideal break position
      Returns:
      the actual break position