org.codehaus.cargo.maven2
Class AbstractCargoMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.codehaus.cargo.maven2.AbstractCommonMojo
          extended by org.codehaus.cargo.maven2.AbstractCargoMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
AbstractDeployerMojo, ConfigureMojo, ContainerInstallMojo, ContainerStartMojo, ContainerStopMojo, PackageMojo

public abstract class AbstractCargoMojo
extends AbstractCommonMojo

Common code used by Cargo MOJOs requiring <container> and <configuration> elements and supportig the notion of Auto-deployable.

Version:
$Id: AbstractCargoMojo.java 1257 2006-12-31 18:43:34Z vmassol $

Field Summary
static java.lang.String CONTEXT_KEY_CONTAINER
          The key under which the container instance is stored in the plugin context.
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractCargoMojo()
           
 
Method Summary
protected  boolean containsAutoDeployable(Deployable[] deployableElements)
           
protected  org.codehaus.cargo.container.deployable.Deployable createAutoDeployDeployable(org.codehaus.cargo.container.Container container)
           
protected  org.codehaus.cargo.container.configuration.Configuration createConfiguration()
          Creates a Configuration instance.
protected  org.codehaus.cargo.container.Container createContainer()
           
protected  org.codehaus.cargo.util.log.Logger createLogger()
          Create a logger.
protected  org.codehaus.cargo.container.Container createNewContainer()
          Creates a brand new Container instance.
protected abstract  void doExecute()
          Executes the plugin.
 void execute()
          
protected  CargoProject getCargoProject()
           
protected  Configuration getConfigurationElement()
           
protected  Container getContainerElement()
           
protected  Deployer getDeployerElement()
           
protected  org.codehaus.cargo.util.FileHandler getFileHandler()
           
protected  void loadEmbeddedContainerDependencies()
           
protected  void setCargoProject(CargoProject cargoProject)
           
protected  void setConfigurationElement(Configuration configurationElement)
           
protected  void setContainerElement(Container containerElement)
           
protected  void setDeployerElement(Deployer deployerElement)
           
protected  void setFileHandler(org.codehaus.cargo.util.FileHandler fileHandler)
           
 
Methods inherited from class org.codehaus.cargo.maven2.AbstractCommonMojo
getProject
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_KEY_CONTAINER

public static final java.lang.String CONTEXT_KEY_CONTAINER
The key under which the container instance is stored in the plugin context. We store it so that it's possible to get back the same container instance even if this mojo is called in a different Maven execution context. This is required for stopping embedded containers for example as we need to use the same instance that was started in order to stop them.

Constructor Detail

AbstractCargoMojo

public AbstractCargoMojo()
Method Detail

getFileHandler

protected org.codehaus.cargo.util.FileHandler getFileHandler()
Returns:
the Cargo file utility class

setFileHandler

protected void setFileHandler(org.codehaus.cargo.util.FileHandler fileHandler)
Parameters:
fileHandler - the Cargo file utility class to use. This method is useful for unit testing with Mock objects as it can be passed a test file handler that doesn't perform any real file action.

getDeployerElement

protected Deployer getDeployerElement()
Returns:
the user configuration of a Cargo Deployer. See the Cargo Maven2 plugin reference guide and Deployer for more details.

setDeployerElement

protected void setDeployerElement(Deployer deployerElement)
Parameters:
deployerElement - the Deployer configuration defined by the user
See Also:
getDeployerElement()

getConfigurationElement

protected Configuration getConfigurationElement()
Returns:
the user configuration of a Cargo Configuration. See the Cargo Maven2 plugin reference guide and Configuration for more details.

setConfigurationElement

protected void setConfigurationElement(Configuration configurationElement)
Parameters:
configurationElement - the Configuration configuration defined by the user
See Also:
getConfigurationElement()

getContainerElement

protected Container getContainerElement()
Returns:
the user configuration of a Cargo Container. See the Cargo Maven2 plugin reference guide and Container for more details.

setContainerElement

protected void setContainerElement(Container containerElement)
Parameters:
containerElement - the Container configuration defined by the user
See Also:
getContainerElement()

setCargoProject

protected void setCargoProject(CargoProject cargoProject)
See Also:
CargoProject

getCargoProject

protected CargoProject getCargoProject()
See Also:
CargoProject

execute

public final void execute()
                   throws org.apache.maven.plugin.MojoExecutionException

Note: This method is final so that extending classes cannot extend it. Instead they should implement the doExecute() method.

Throws:
org.apache.maven.plugin.MojoExecutionException
See Also:
Mojo.execute()

doExecute

protected abstract void doExecute()
                           throws org.apache.maven.plugin.MojoExecutionException
Executes the plugin.

This method must be implemented by all Mojos extending this class. The reason for this pattern is because we want the execute() method to always be called so that necessary plugin initialization can be performed. Without this pattern Mojos extending this class could "forget" to call super.execute() thus leading to unpredictible results.

Throws:
org.apache.maven.plugin.MojoExecutionException - in case of error

createConfiguration

protected org.codehaus.cargo.container.configuration.Configuration createConfiguration()
                                                                                throws org.apache.maven.plugin.MojoExecutionException
Creates a Configuration instance. If the user has not specified a configuration element in the POM file then automatically create a standalone configuration if the container's type is local or otherwise create a runtime configuration.

Returns:
a valid Configuration instance
Throws:
org.apache.maven.plugin.MojoExecutionException - in case of error

createContainer

protected org.codehaus.cargo.container.Container createContainer()
                                                          throws org.apache.maven.plugin.MojoExecutionException
Returns:
a Container instance if no container object was stored in the Maven Plugin Context or returns the saved instance otherwise. If a new container instance is created it's also saved in the Maven Plugin Context for later retrieval.
Throws:
org.apache.maven.plugin.MojoExecutionException - in case of error

createNewContainer

protected org.codehaus.cargo.container.Container createNewContainer()
                                                             throws org.apache.maven.plugin.MojoExecutionException
Creates a brand new Container instance. If the user has not specified a container element in the POM file or if the user has not specified the container id then automatically create a default container (as defined in computeContainerId(org.codehaus.cargo.maven2.configuration.Container)) if the project calling this plugin has a WAR packaging. If the packaging is different then an exception is raised.

Returns:
a valid Container instance
Throws:
org.apache.maven.plugin.MojoExecutionException - in case of error or if a default container could not be created

loadEmbeddedContainerDependencies

protected void loadEmbeddedContainerDependencies()
                                          throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

createAutoDeployDeployable

protected org.codehaus.cargo.container.deployable.Deployable createAutoDeployDeployable(org.codehaus.cargo.container.Container container)
                                                                                 throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

containsAutoDeployable

protected boolean containsAutoDeployable(Deployable[] deployableElements)

createLogger

protected org.codehaus.cargo.util.log.Logger createLogger()
Create a logger. If a <log> configuration element has been specified by the user then use it. If none is specified then log to the Maven 2 logging subsystem.

Returns:
the logger to use for logging this plugin's activity


Copyright © 2004-2010 Codehaus. All Rights Reserved.