Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Section
titleWriting a custom Provider

A custom provider should extend extend 

System Link
filesrc/main/java/de/smartics/maven/plugin/buildmetadata/data/AbstractMetaDataProvider.java
system-idsvn
system-typesvn
labelde.smartics.maven.plugin.buildmetadata.data.AbstractMetaDataProvider
and are required to implement
System Link
filesrc/main/java/de/smartics/maven/plugin/buildmetadata/data/MetaDataProvider.java
system-idsvn
system-typesvn
labelde.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.

Code Block
languagejava
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.

Code Block Placeholder
code-languageHTML and XML
<plugin>
  <groupId>${project-group-id}</groupId>
  <artifactId>${project-artifact-id}</artifactId>
  <version>${project-version}</version>
  <scope>provided</scope>
</plugin>

...