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>2.4</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:

 1: package taglist;
 2:
 3: /**
 4:  * NOT_YET_DOCUMENTED
 5:  */
 6: public class Issue
 7: {
 8:   /**
 9:    * A method.
10:    * FIXME Describe what this method does
11:    *
12:    * @param i DOCUMENT_ME
13:    * @return Something useful
14:    */
15:   public double method(int i)
16:   {
17:     // <todo> must be implemented
18:     return 0;
19:   }
20:
21:   /**
22:    * This method counts FIXME tags in the text.
23:    */
24:   private int countFixmeTags(String text)
25:   {
26:     // @todo Implement this later
27:   }
28: }

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.