Fork me on GitHub

Counting Tags

This example is meant to show you how the Taglist Maven Plugin works, when it finds and counts tags in your code.

Let us configure the plugin in the pom.xml file like this:

<project>
  ...
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>taglist-maven-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <encoding>UTF-8</encoding>
          <sourceFileLocale>en</sourceFileLocale>
          <emptyComments>false</emptyComments>
          <tagListOptions>
            <tagClasses>
              <tagClass>
                <displayName>Documentation Work</displayName>
                <tags>
                  <tag>
                    <matchString>DOCUMENT_ME</matchString>
                    <matchType>exact</matchType>
                  </tag>
                  <tag>
                    <matchString>NOT_YET_DOCUMENTED</matchString>
                    <matchType>exact</matchType>
                  </tag>
                </tags>
              </tagClass>
              <tagClass>
                <displayName>Code Work</displayName>
                <tags>
                  <tag>
                    <matchString>FIXME</matchString>
                    <matchType>exact</matchType>
                  </tag>
                  <tag>
                    <matchString>&lt;todo</matchString>
                    <matchType>exact</matchType>
                  </tag>
                  <tag>
                    <matchString>TODO</matchString>
                    <matchType>ignoreCase</matchType>
                  </tag>
                </tags>
              </tagClass>
            </tagClasses>
          </tagListOptions>
        </configuration>
      </plugin>
      ...
    </plugins>
  </reporting>
  ...
</project>

The Java file we are analyzing is this one:

package taglist;

/**
 * NOT_YET_DOCUMENTED
 */
public class Issue
{
  /**
   * A method.
   * FIXME Describe what this method does
   *
   * @param i DOCUMENT_ME
   * @return Something useful
   */
  public double method(int i)
  {
    // <todo> must be implemented
    return 0;
  }

  /**
   * This method counts FIXME tags in the text.
   */
  private int countFixmeTags(String text)
  {
    // @todo Implement this later
  }
}

We'll go through the lines in the code and explain what happens and why.

Line 4: This line will not be counted, because emptyComments is set to false and it is empty - it isn't followed by a desciptive text.

Line 10: This line will be counted.

Line 12: This line will not be counted, because it is located at the end of the line with other text before it.

Line 17: This line will be counted.

Line 22: This line will not be counted, because it appears in the middle of the line with other text before it.

Line 26: This line will not be counted, because the text @todo is not one of the configured tags.