Class PropertiesMacro

  • 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="properties")
    public class PropertiesMacro
    extends org.apache.maven.doxia.macro.AbstractMacro
    A macro that inserts a table of properties for the given checkstyle module.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.regex.Pattern CHECK_PATTERN
      The precompiled pattern for a Check.
      private static java.lang.String CODE_END
      Reflects end of a code segment.
      private static java.lang.String CODE_START
      Reflects start of a code segment.
      private static java.util.regex.Pattern COMMA_SPACE_PATTERN
      The precompiled pattern for a comma followed by a space.
      private static java.lang.String CURLY_BRACKET
      The string '{}'.
      private static java.io.File currentModuleFile
      The file of the current module being processed.
      private static java.lang.String currentModuleName
      The name of the current module being processed.
      static java.lang.String EMPTY
      Constant value for cases when tokens set is empty.
      private static java.lang.String INDENT_LEVEL_10
      A newline with 10 spaces of indentation.
      private static java.lang.String INDENT_LEVEL_12
      A newline with 12 spaces of indentation.
      private static java.lang.String INDENT_LEVEL_14
      A newline with 14 spaces of indentation.
      private static java.lang.String INDENT_LEVEL_16
      A newline with 16 spaces of indentation.
      private static java.lang.String INDENT_LEVEL_18
      A newline with 18 spaces of indentation.
      private static java.lang.String INDENT_LEVEL_20
      A newline with 20 spaces of indentation.
      static java.util.Set<java.lang.String> NON_BASE_TOKEN_PROPERTIES
      Set of properties not inherited from the base token configuration.
      private static java.lang.String PROPERTY_TYPES_XML
      Represents the relative path to the property types XML.
      private static java.lang.String TOKENS_PROPERTY
      This property is used to change the existing properties for javadoc.
      private static java.lang.String URL_F
      Represents the format string for constructing URLs with two placeholders.
      • Fields inherited from interface org.apache.maven.doxia.macro.Macro

        EOL, ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertiesMacro()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void configureGlobalProperties​(java.lang.String modulePath)
      Configures the global properties for the current module.
      void execute​(org.apache.maven.doxia.sink.Sink sink, org.apache.maven.doxia.macro.MacroRequest request)  
      private static java.lang.String getDefaultValue​(java.lang.String propertyName, java.lang.reflect.Field field, java.lang.Object instance)
      Get the default value of the property.
      private static java.util.List<java.lang.String> orderProperties​(java.util.Set<java.lang.String> properties)
      Reorder properties to always have the 'tokens' property last (if present).
      private static void processLinkForTokenTypes​(org.apache.maven.doxia.sink.Sink sink)
      Writes a formatted link for "TokenTypes" to the given sink.
      private static void writeLink​(org.apache.maven.doxia.sink.Sink sink)
      Write a link when all types of token supported.
      private static void writeLinkToToken​(org.apache.maven.doxia.sink.Sink sink, java.lang.String document, java.lang.String tokenName)
      Writes a link to the given token.
      private static void writePropertiesTable​(org.apache.maven.doxia.module.xdoc.XdocSink sink)
      Writes the properties table for the given module.
      private static void writePropertyDefaultValueCell​(org.apache.maven.doxia.sink.Sink sink, java.lang.String propertyName, java.lang.reflect.Field field, java.lang.Object instance)
      Writes a table cell with the property default value.
      private static void writePropertyDescriptionCell​(org.apache.maven.doxia.sink.Sink sink, java.lang.String propertyName, DetailNode propertyJavadoc)
      Writes a table cell with the property description.
      private static void writePropertyNameCell​(org.apache.maven.doxia.sink.Sink sink, java.lang.String propertyName)
      Writes a table cell with the given property name.
      private static void writePropertyRow​(org.apache.maven.doxia.sink.Sink sink, java.lang.String propertyName, DetailNode propertyJavadoc, java.lang.Object instance, DetailNode moduleJavadoc)
      Writes a table row with 5 columns for the given property - name, description, type, default value, since.
      private static void writePropertySinceVersionCell​(org.apache.maven.doxia.sink.Sink sink, java.lang.String propertyName, DetailNode moduleJavadoc, DetailNode propertyJavadoc)
      Writes a table cell with the property since version.
      private static void writePropertyTypeCell​(org.apache.maven.doxia.sink.Sink sink, java.lang.String propertyName, java.lang.reflect.Field field, java.lang.Object instance)
      Writes a table cell with the property type.
      private static void writeTableHeaderCell​(org.apache.maven.doxia.sink.Sink sink, java.lang.String text)
      Writes a table header cell with the given text.
      private static void writeTableHeaderRow​(org.apache.maven.doxia.sink.Sink sink)
      Writes the table header row with 5 columns - name, description, type, default value, since.
      private static void writeTablePropertiesRows​(org.apache.maven.doxia.sink.Sink sink)
      Writes the rows of the table with the 5 columns - name, description, type, default value, since.
      private static void writeTokensList​(org.apache.maven.doxia.sink.Sink sink, java.util.List<java.lang.String> tokens, java.lang.String tokenTypesLink, boolean printDotAtTheEnd)
      Write a list of tokens with links to the tokenTypesLink file.
      • Methods inherited from class org.apache.maven.doxia.macro.AbstractMacro

        enableLogging, getAttributesFromMap, getLog, required
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY

        public static final java.lang.String EMPTY
        Constant value for cases when tokens set is empty.
        See Also:
        Constant Field Values
      • NON_BASE_TOKEN_PROPERTIES

        public static final java.util.Set<java.lang.String> NON_BASE_TOKEN_PROPERTIES
        Set of properties not inherited from the base token configuration.
      • COMMA_SPACE_PATTERN

        private static final java.util.regex.Pattern COMMA_SPACE_PATTERN
        The precompiled pattern for a comma followed by a space.
      • CHECK_PATTERN

        private static final java.util.regex.Pattern CHECK_PATTERN
        The precompiled pattern for a Check.
      • URL_F

        private static final java.lang.String URL_F
        Represents the format string for constructing URLs with two placeholders.
        See Also:
        Constant Field Values
      • INDENT_LEVEL_10

        private static final java.lang.String INDENT_LEVEL_10
        A newline with 10 spaces of indentation.
      • INDENT_LEVEL_12

        private static final java.lang.String INDENT_LEVEL_12
        A newline with 12 spaces of indentation.
      • INDENT_LEVEL_14

        private static final java.lang.String INDENT_LEVEL_14
        A newline with 14 spaces of indentation.
      • INDENT_LEVEL_16

        private static final java.lang.String INDENT_LEVEL_16
        A newline with 16 spaces of indentation.
      • INDENT_LEVEL_18

        private static final java.lang.String INDENT_LEVEL_18
        A newline with 18 spaces of indentation.
      • INDENT_LEVEL_20

        private static final java.lang.String INDENT_LEVEL_20
        A newline with 20 spaces of indentation.
      • TOKENS_PROPERTY

        private static final java.lang.String TOKENS_PROPERTY
        This property is used to change the existing properties for javadoc. Tokens always present at the end of all properties.
        See Also:
        Constant Field Values
      • currentModuleName

        private static java.lang.String currentModuleName
        The name of the current module being processed.
      • currentModuleFile

        private static java.io.File currentModuleFile
        The file of the current module being processed.
    • Method Detail

      • 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
      • configureGlobalProperties

        private static void configureGlobalProperties​(java.lang.String modulePath)
        Configures the global properties for the current module.
        Parameters:
        modulePath - the path of the current module processed.
      • writePropertiesTable

        private static void writePropertiesTable​(org.apache.maven.doxia.module.xdoc.XdocSink sink)
                                          throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes the properties table for the given module. Expects that the module has been processed with the ClassAndPropertiesSettersJavadocScraper before calling this method.
        Parameters:
        sink - the sink to write to.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if an error occurs during writing.
      • writeTableHeaderRow

        private static void writeTableHeaderRow​(org.apache.maven.doxia.sink.Sink sink)
        Writes the table header row with 5 columns - name, description, type, default value, since.
        Parameters:
        sink - sink to write to.
      • writeTableHeaderCell

        private static void writeTableHeaderCell​(org.apache.maven.doxia.sink.Sink sink,
                                                 java.lang.String text)
        Writes a table header cell with the given text.
        Parameters:
        sink - sink to write to.
        text - the text to write.
      • writeTablePropertiesRows

        private static void writeTablePropertiesRows​(org.apache.maven.doxia.sink.Sink sink)
                                              throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes the rows of the table with the 5 columns - name, description, type, default value, since. Each row corresponds to a property of the module.
        Parameters:
        sink - sink to write to.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if an error occurs during writing.
      • orderProperties

        private static java.util.List<java.lang.String> orderProperties​(java.util.Set<java.lang.String> properties)
        Reorder properties to always have the 'tokens' property last (if present).
        Parameters:
        properties - module properties.
        Returns:
        Collection of ordered properties.
      • writePropertyRow

        private static void writePropertyRow​(org.apache.maven.doxia.sink.Sink sink,
                                             java.lang.String propertyName,
                                             DetailNode propertyJavadoc,
                                             java.lang.Object instance,
                                             DetailNode moduleJavadoc)
                                      throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes a table row with 5 columns for the given property - name, description, type, default value, since.
        Parameters:
        sink - sink to write to.
        propertyName - the name of the property.
        propertyJavadoc - the Javadoc of the property.
        instance - the instance of the module.
        moduleJavadoc - the Javadoc of the module.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if an error occurs during writing.
      • writePropertyNameCell

        private static void writePropertyNameCell​(org.apache.maven.doxia.sink.Sink sink,
                                                  java.lang.String propertyName)
        Writes a table cell with the given property name.
        Parameters:
        sink - sink to write to.
        propertyName - the name of the property.
      • writePropertyDescriptionCell

        private static void writePropertyDescriptionCell​(org.apache.maven.doxia.sink.Sink sink,
                                                         java.lang.String propertyName,
                                                         DetailNode propertyJavadoc)
                                                  throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes a table cell with the property description.
        Parameters:
        sink - sink to write to.
        propertyName - the name of the property.
        propertyJavadoc - the Javadoc of the property containing the description.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if an error occurs during retrieval of the description.
      • writePropertyTypeCell

        private static void writePropertyTypeCell​(org.apache.maven.doxia.sink.Sink sink,
                                                  java.lang.String propertyName,
                                                  java.lang.reflect.Field field,
                                                  java.lang.Object instance)
                                           throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes a table cell with the property type.
        Parameters:
        sink - sink to write to.
        propertyName - the name of the property.
        field - the field of the property.
        instance - the instance of the module.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if link to the property_types.html file cannot be constructed.
      • processLinkForTokenTypes

        private static void processLinkForTokenTypes​(org.apache.maven.doxia.sink.Sink sink)
                                              throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes a formatted link for "TokenTypes" to the given sink.
        Parameters:
        sink - The output target where the link is written.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - If an error occurs during the link processing.
      • writeLink

        private static void writeLink​(org.apache.maven.doxia.sink.Sink sink)
                               throws org.apache.maven.doxia.macro.MacroExecutionException
        Write a link when all types of token supported.
        Parameters:
        sink - sink to write to.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if link cannot be constructed.
      • writeTokensList

        private static void writeTokensList​(org.apache.maven.doxia.sink.Sink sink,
                                            java.util.List<java.lang.String> tokens,
                                            java.lang.String tokenTypesLink,
                                            boolean printDotAtTheEnd)
                                     throws org.apache.maven.doxia.macro.MacroExecutionException
        Write a list of tokens with links to the tokenTypesLink file.
        Parameters:
        sink - sink to write to.
        tokens - the list of tokens to write.
        tokenTypesLink - the link to the token types file.
        printDotAtTheEnd - defines if printing period symbols is required.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if link to the tokenTypesLink file cannot be constructed.
      • writeLinkToToken

        private static void writeLinkToToken​(org.apache.maven.doxia.sink.Sink sink,
                                             java.lang.String document,
                                             java.lang.String tokenName)
                                      throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes a link to the given token.
        Parameters:
        sink - sink to write to.
        document - the document to link to.
        tokenName - the name of the token.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if link to the document file cannot be constructed.
      • writePropertyDefaultValueCell

        private static void writePropertyDefaultValueCell​(org.apache.maven.doxia.sink.Sink sink,
                                                          java.lang.String propertyName,
                                                          java.lang.reflect.Field field,
                                                          java.lang.Object instance)
                                                   throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes a table cell with the property default value.
        Parameters:
        sink - sink to write to.
        propertyName - the name of the property.
        field - the field of the property.
        instance - the instance of the module.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if an error occurs during retrieval of the default value.
      • getDefaultValue

        private static java.lang.String getDefaultValue​(java.lang.String propertyName,
                                                        java.lang.reflect.Field field,
                                                        java.lang.Object instance)
                                                 throws org.apache.maven.doxia.macro.MacroExecutionException
        Get the default value of the property.
        Parameters:
        propertyName - the name of the property.
        field - the field of the property.
        instance - the instance of the module.
        Returns:
        the default value of the property.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if an error occurs during retrieval of the default value.
      • writePropertySinceVersionCell

        private static void writePropertySinceVersionCell​(org.apache.maven.doxia.sink.Sink sink,
                                                          java.lang.String propertyName,
                                                          DetailNode moduleJavadoc,
                                                          DetailNode propertyJavadoc)
                                                   throws org.apache.maven.doxia.macro.MacroExecutionException
        Writes a table cell with the property since version.
        Parameters:
        sink - sink to write to.
        propertyName - the name of the property.
        moduleJavadoc - the Javadoc of the module.
        propertyJavadoc - the Javadoc of the property containing the since version.
        Throws:
        org.apache.maven.doxia.macro.MacroExecutionException - if an error occurs during retrieval of the since version.