Provider SPI

The buildmetadata-plugin allows to add Provider implementations that add specific Build-Information the plugin does not provide by itself. For instance users may want to connect to a remote build number provider or aggregate information found in the project to flag certain conditions.

Custom providers are guaranteed to be run at the end of the build meta data gathering. This allows those providers to access the information generated by the standard providers. This may be helpful if a provider implementation is used to export build information to a backend system.

Writing a custom Provider

A custom provider should extend de.smartics.maven.plugin.buildmetadata.data.AbstractMetaDataProvider and are required to implement de.smartics.maven.plugin.buildmetadata.data.MetaDataProvider. The abstract class provides access to Maven's project, the settings, runtime and SCM information.

The following class implements an example provider that only echos on the console.

public class EchoProvider extends AbstractMetaDataProvider
{
  /**
   * The string to echo.
   */
  private String echo;

  /**
   * The number of times to echo the string.
   */
  private int times;

  /**
   * {@inheritDoc}
   *
   * @see de.smartics.maven.plugin.buildmetadata.data.MetaDataProvider#provideBuildMetaData(java.util.Properties)
   */
  public void provideBuildMetaData(final Properties buildMetaDataProperties)
    throws MojoExecutionException
  {
    if (times > 0)
    {
      for (int i = 0; i < times; i++)
      {
        System.out.println(echo);
      }
    }
  }
}

Add the buildmetadata plugin artifact as a dependency.

<dependencies>
  <dependency>
    <groupId>de.smartics.maven.plugin</groupId>
    <artifactId>maven-buildmetadata-plugin</artifactId>
    <version>1.1.5</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

Using a custom Provider

Register the custom implementation in the configuration element of the plugin like this:

      <plugin>
        <groupId>de.smartics.maven.plugin</groupId>
        <artifactId>maven-buildmetadata-plugin</artifactId>
        <configuration>
          <providers>
            <provider>
              <type>de.smartics.sandbox.provider.EchoProvider</type>
              <properties>
                <echo>Beautiful!</echo>
                <times>3</times>
              </properties>
            </provider>
          </providers>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>de.smartics.sandbox</groupId>
            <artifactId>sandbox-buildmetadata-provider</artifactId>
            <version>0.1.0</version>
          </dependency>
        </dependencies>
      </plugin>

The example shows the echo provider that writes the echo string the given number of times to the console.

The type attribute specifies the implementation to be instantiated. The properties are assigned as Strings or to the given type if it is convertable from a String to this type (like e.g. Integer values).