org.sonar.api.batch.maven
Class MavenPlugin

java.lang.Object
  extended by org.sonar.api.batch.maven.MavenPlugin

public class MavenPlugin
extends Object

A class to handle maven plugins

Since:
1.10

Constructor Summary
MavenPlugin(org.apache.maven.model.Plugin plugin)
          Creates a MavenPlugin based on a Plugin
MavenPlugin(String groupId, String artifactId, String version)
          Creates a Maven plugin based on artifact + group + version
 
Method Summary
 MavenPlugin addParameter(String key, String value)
          Adds a parameter to the maven plugin
 String getParameter(String key)
          Gets a parameter of the plugin based on its key
 String[] getParameters(String key)
          Gets a list of parameters of the plugin from a param key
 org.apache.maven.model.Plugin getPlugin()
           
static MavenPlugin getPlugin(org.apache.maven.project.MavenProject pom, String groupId, String artifactId)
          Returns a plugin from a pom based on its group id and artifact id

 boolean hasConfiguration()
           
static MavenPlugin registerPlugin(org.apache.maven.project.MavenProject pom, String groupId, String artifactId, String version, boolean overrideVersion)
          Registers a plugin in a project pom

 void removeParameter(String key)
          Remove a parameter from the maven plugin based on its key
 void removeParameters()
          Removes all parameters from the maven plugin
 MavenPlugin setParameter(String key, String value)
          Sets a parameter for the maven plugin.
 void setParameter(String key, String value, boolean override)
          Sets a parameter to the maven plugin.
 MavenPlugin setVersion(String version)
          Sets the maven plugin version
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MavenPlugin

public MavenPlugin(org.apache.maven.model.Plugin plugin)
Creates a MavenPlugin based on a Plugin

Parameters:
plugin - the plugin

MavenPlugin

public MavenPlugin(String groupId,
                   String artifactId,
                   String version)
Creates a Maven plugin based on artifact + group + version

Parameters:
groupId - the group id
artifactId - the artifact id
version - the version
Method Detail

setVersion

public MavenPlugin setVersion(String version)
Sets the maven plugin version

Parameters:
version - the version
Returns:
this

getPlugin

public org.apache.maven.model.Plugin getPlugin()
Returns:
the underlying plugin

getParameter

public String getParameter(String key)
Gets a parameter of the plugin based on its key

Parameters:
key - the param key
Returns:
the parameter if exist, null otherwise

getParameters

public String[] getParameters(String key)
Gets a list of parameters of the plugin from a param key

Parameters:
key - param key with option-index snippet: e.g. item[0], item[1]. If no index snippet is passed, then 0 is default (index <=> index[0])
Returns:
an array of parameters if any, an empty array otherwise

setParameter

public MavenPlugin setParameter(String key,
                                String value)
Sets a parameter for the maven plugin. This will overrides an existing parameter.

Parameters:
key - the param key
value - the param value
Returns:
this

setParameter

public void setParameter(String key,
                         String value,
                         boolean override)
Sets a parameter to the maven plugin. Overrides existing parameter only id specified.

Parameters:
key - the param key
value - the param value
override - whether to override existing parameter

removeParameters

public void removeParameters()
Removes all parameters from the maven plugin


addParameter

public MavenPlugin addParameter(String key,
                                String value)
Adds a parameter to the maven plugin

Parameters:
key - the param key with option-index snippet: e.g. item[0], item[1]. If no index snippet is passed, then 0 is default (index <=> index[0])
value - the param value
Returns:
this

removeParameter

public void removeParameter(String key)
Remove a parameter from the maven plugin based on its key

Parameters:
key - param key with option-index snippet: e.g. item[0], item[1]. If no index snippet is passed, then 0 is default (index <=> index[0])

hasConfiguration

public boolean hasConfiguration()
Returns:
whether the maven plugin has got configuration

registerPlugin

public static MavenPlugin registerPlugin(org.apache.maven.project.MavenProject pom,
                                         String groupId,
                                         String artifactId,
                                         String version,
                                         boolean overrideVersion)
Registers a plugin in a project pom

Adds the plugin if it does not exist or amend its version if it does exist and specified

Parameters:
pom - the project pom
groupId - the plugin group id
artifactId - the plugin artifact id
version - the plugin version
overrideVersion - whether to override the version if the plugin is already registered
Returns:
the registered plugin

getPlugin

public static MavenPlugin getPlugin(org.apache.maven.project.MavenProject pom,
                                    String groupId,
                                    String artifactId)
Returns a plugin from a pom based on its group id and artifact id

It searches in the build section, then the reporting section and finally the pluginManagement section

Parameters:
pom - the project pom
groupId - the plugin group id
artifactId - the plugin artifact id
Returns:
the plugin if it exists, null otherwise

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009-2011 SonarSource. All Rights Reserved.