Package org.codehaus.cargo.maven3
Class AbstractCargoMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.codehaus.cargo.maven3.AbstractCommonMojo
-
- org.codehaus.cargo.maven3.AbstractCargoMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractDaemonMojo,AbstractDeployerMojo,ConfigureMojo,ContainerInstallMojo,ContainerStartMojo,ContainerStopMojo,PackageMojo
public abstract class AbstractCargoMojo extends AbstractCommonMojo
Common code used by Cargo MOJOs requiring<container>and<configuration>elements and supporting the notion of Auto-deployable.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONTEXT_KEY_CLASSLOADERThe key suffix under which the classloader of the container instance is stored in the plugin context.static StringCONTEXT_KEY_CONTAINERThe key under which the container instance is stored in the plugin context.
-
Constructor Summary
Constructors Constructor Description AbstractCargoMojo()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ArtifactInstallercalculateArtifact(String url)Calculate the Maven artifact for a URL.static StringcalculateContainerArtifactId(String containerId)Calculates the container artifact ID for a given container ID.protected DeployablecreateAutoDeployDeployable(Container container)Create the autodeploy deployable (if the current project is a Java EE deployable)protected ConfigurationcreateConfiguration()Creates aConfigurationinstance.protected ContainercreateContainer()protected voidcreateDefaultContainerElementIfNecessary()Creates a container element if required.protected voidcreateDefaultInstallerElementIfNecessary()Creates a installer element if required.protected LoggercreateLogger()Create a logger.protected ContainercreateNewContainer()Creates a brand newContainerinstance.protected abstract voiddoExecute()Executes the plugin.voidexecute()protected CargoProjectgetCargoProject()protected ConfigurationgetConfigurationElement()See the Cargo Maven 3 plugin reference guide for more details.protected ContainergetContainerElement()See the Cargo Maven 3 plugin reference guide for more details.protected DaemongetDaemon()protected Deployable[]getDeployablesElement()See the Cargo Maven 3 plugin reference guide for more details.protected DeployergetDeployerElement()See the Cargo Maven 3 plugin reference guide for more details.booleanisIgnoreFailures()protected voidsetCargoProject(CargoProject cargoProject)protected voidsetConfigurationElement(Configuration configurationElement)See the Cargo Maven 3 plugin reference guide for more details.protected voidsetContainerElement(Container containerElement)See the Cargo Maven 3 plugin reference guide for more details.protected voidsetDeployablesElement(Deployable[] deployablesElement)See the Cargo Maven 3 plugin reference guide for more details.protected voidsetDeployerElement(Deployer deployerElement)See the Cargo Maven 3 plugin reference guide for more details.voidsetIgnoreFailures(boolean ignoreFailures)protected voidwaitDeployableMonitor(Container container, boolean starting)Waits until all deployables with a deployable monitor are deployed / undeployed.-
Methods inherited from class org.codehaus.cargo.maven3.AbstractCommonMojo
getProject
-
-
-
-
Field Detail
-
CONTEXT_KEY_CONTAINER
public static final 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.
-
CONTEXT_KEY_CLASSLOADER
public static final String CONTEXT_KEY_CLASSLOADER
The key suffix under which the classloader of the container instance is stored in the plugin context. We store it so that it's possible to get back the same classloader even if this mojo is called in a different Maven execution context. This is required for starting and stopping multiple containers as each container initialization requires different classloader.- See Also:
- Constant Field Values
-
-
Method Detail
-
calculateContainerArtifactId
public static String calculateContainerArtifactId(String containerId)
Calculates the container artifact ID for a given container ID. Note that all containers identifier are in the formcontainerArtifactId + the version number + x; for examplejboss42xis from container artifact IDcargo-core-container-jboss.- Parameters:
containerId- Container ID, for examplejboss42x.- Returns:
- Container artifact ID, for example
cargo-core-container-jboss.
-
calculateArtifact
public static ArtifactInstaller calculateArtifact(String url)
Calculate the Maven artifact for a URL.- Parameters:
url- Maven URL.- Returns:
- Maven artifact installer for given URL.
-
getDeployerElement
protected Deployer getDeployerElement()
See the Cargo Maven 3 plugin reference guide for more details.- Returns:
- the user configuration of a Cargo
Deployer. - See Also:
setDeployerElement(Deployer)
-
setDeployerElement
protected void setDeployerElement(Deployer deployerElement)
See the Cargo Maven 3 plugin reference guide for more details.- Parameters:
deployerElement- theDeployerconfiguration defined by the user- See Also:
getDeployerElement()
-
getDaemon
protected Daemon getDaemon()
- Returns:
- The daemon configuration
-
getDeployablesElement
protected Deployable[] getDeployablesElement()
See the Cargo Maven 3 plugin reference guide for more details.- Returns:
- the user configuration of the list of
Deployable. - See Also:
setDeployablesElement(Deployable[])
-
setDeployablesElement
protected void setDeployablesElement(Deployable[] deployablesElement)
See the Cargo Maven 3 plugin reference guide for more details.- Parameters:
deployablesElement- the list ofDeployable.- See Also:
getDeployablesElement()
-
getConfigurationElement
protected Configuration getConfigurationElement()
See the Cargo Maven 3 plugin reference guide for more details.- Returns:
- the user configuration of a Cargo
Configuration. - See Also:
setConfigurationElement(Configuration)
-
setConfigurationElement
protected void setConfigurationElement(Configuration configurationElement)
See the Cargo Maven 3 plugin reference guide for more details.- Parameters:
configurationElement- theConfigurationconfiguration defined by the user- See Also:
getConfigurationElement()
-
getContainerElement
protected Container getContainerElement()
See the Cargo Maven 3 plugin reference guide for more details.- Returns:
- the user configuration of a Cargo
Container. - See Also:
setConfigurationElement(Configuration)
-
setContainerElement
protected void setContainerElement(Container containerElement)
See the Cargo Maven 3 plugin reference guide for more details.- Parameters:
containerElement- theContainerconfiguration defined by the user- See Also:
getContainerElement()
-
setCargoProject
protected void setCargoProject(CargoProject cargoProject)
- Parameters:
cargoProject- Cargo project
-
getCargoProject
protected CargoProject getCargoProject()
- Returns:
- Cargo project
-
isIgnoreFailures
public boolean isIgnoreFailures()
- Returns:
- the ignoreFailures
-
setIgnoreFailures
public void setIgnoreFailures(boolean ignoreFailures)
- Parameters:
ignoreFailures- the ignoreFailures to set
-
execute
public final void execute() throws org.apache.maven.plugin.MojoExecutionExceptionNote: This method is final so that extending classes cannot extend it. Instead they should implement the
doExecute()method.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
doExecute
protected abstract void doExecute() throws org.apache.maven.plugin.MojoExecutionExceptionExecutes 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 callsuper.execute()thus leading to unpredictible results.- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of error
-
createConfiguration
protected Configuration createConfiguration() throws org.apache.maven.plugin.MojoExecutionException
Creates aConfigurationinstance. 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
Configurationinstance - Throws:
org.apache.maven.plugin.MojoExecutionException- in case of error
-
createContainer
protected Container createContainer() throws org.apache.maven.plugin.MojoExecutionException
- Returns:
- a
Containerinstance 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 Container createNewContainer() throws org.apache.maven.plugin.MojoExecutionException
Creates a brand newContainerinstance. 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 increateDefaultContainerElementIfNecessary()) if the project calling this plugin has a WAR packaging. If the packaging is different then an exception is raised.- Returns:
- a valid
Containerinstance - Throws:
org.apache.maven.plugin.MojoExecutionException- in case of error or if a default container could not be created
-
createDefaultContainerElementIfNecessary
protected void createDefaultContainerElementIfNecessary() throws org.apache.maven.plugin.MojoExecutionExceptionCreates a container element if required.- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of error or if a default container could not be created
-
createDefaultInstallerElementIfNecessary
protected void createDefaultInstallerElementIfNecessary() throws IOExceptionCreates a installer element if required.- Throws:
IOException- If the properties file cannot be loaded.
-
createAutoDeployDeployable
protected Deployable createAutoDeployDeployable(Container container) throws org.apache.maven.plugin.MojoExecutionException
Create the autodeploy deployable (if the current project is a Java EE deployable)- Parameters:
container- Container.- Returns:
- The autodeploy deployable.
- Throws:
org.apache.maven.plugin.MojoExecutionException- If deployable creation fails.
-
createLogger
protected 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 3 logging subsystem.- Returns:
- the logger to use for logging this plugin's activity
-
waitDeployableMonitor
protected void waitDeployableMonitor(Container container, boolean starting)
Waits until all deployables with a deployable monitor are deployed / undeployed.- Parameters:
container- Container where is deployable deployed.starting-trueif container is starting (i.e., wait for deployment),falseotherwise.
-
-