Kirk Rader  1.0-SNAPSHOT
Status Codes Maven Plugin

Maven plugin that supports automated monitoring and reporting

Overview

The us.rader.logging.statuscodes.maven package defines a Maven plugin that invokes us.rader.logging.statuscodes.MonitoredStatusCodeInfoList::toProperties

This generates a resource file that can be used at run time with us.rader.logging.statuscodes.Log::log for simplified, standardized logging suitable to drive automated monitoring and reporting.

Usage

<plugin>
  <groupId>us.rader.examples</groupId>
  <artifactId>status-codes-maven-plugin</artifactId>
  <version>1.0-SNAPSHOT</version>
  <configuration>
    <classes>${project.basedir}/target/classes</classes>
    <resource>${project.basedir}/target/resources/logmessages.properties</resource>
    <aspects>

    </aspects>
    <weaverExclusions>

    </weaverExclusions>
  </configuration>
  <executions>
    <execution>
      <phase>process-classes</phase>
      <goals>
        <goal>extract</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Implementation

This plugin uses an instance of us.rader.logging.statuscodes.MonitoredStatusCodeInfoList to extract status code information from annotations in the Java classes being built. In order to obtain the set of Class<?> instances, it uses an instance of java.net.URLClassLoader whose parent is the class loader that loaded us.rader.logging.statuscodes.maven.StatusCodesMojo and whose list of URL's is obtained by walking the output directory tree containing the class files for the artifact being built combined with the set of project dependencies specified in the POM.

In particular, us.rader.logging.statuscodes.maven.StatusCodesMojo::populateParametersForClassLoader recursively walks the project output directory and populates two sets: the class names to load and the directories to add to the POM dependencies in order to load all the class files. The set of dependencies so obtained are then used to construct an instance of java.net.URLClassLoader. That class loader is then used when iterating through the list of class names.

As a convenience, this plugin will also generate an aop.xml file suitable for use with Tracing With AspectJ. This will have no effect unless the artifact is loaded with the Aspect load-time weaver, in which case you must ensure that the classes in us.rader.examples.tracing.aspect are on the classpath