Index: D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleStopMojo.java =================================================================== --- D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleStopMojo.java (revision 0) +++ D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleStopMojo.java (revision 0) @@ -0,0 +1,53 @@ +/* + * ======================================================================== + * + * Copyright 2005-2006 Vincent Massol. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== + */ + +package org.codehaus.cargo.maven2; + +import org.codehaus.cargo.container.Container; +import org.codehaus.cargo.container.deployable.Deployable; +import org.apache.maven.plugin.MojoExecutionException; + +/** + * Stop deployable application in container using Cargo + * + * @version + * @goal stop-module + * @requiresDependencyResolution compile + * + */ + +public class ModuleStopMojo extends AbstractModuleMojo +{ + + public void execute() throws MojoExecutionException + { + super.execute(); + moduleAction(); + } + + protected void singleDeployableAction(org.codehaus.cargo.container.deployer.Deployer deployer, + org.codehaus.cargo.container.deployable.Deployable deployable) + { + getLog().debug("Stopping [" + deployable.getFile() + "] deployable ..."); + + deployer.stop(deployable); + + } +} Index: D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleDeployMojo.java =================================================================== --- D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleDeployMojo.java (revision 0) +++ D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleDeployMojo.java (revision 0) @@ -0,0 +1,138 @@ +/* + * ======================================================================== + * + * Copyright 2005 Vincent Massol. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== + */ +package org.codehaus.cargo.maven2; + +import java.net.URL; + +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.cargo.container.Container; +import org.codehaus.cargo.container.deployable.Deployable; +import org.codehaus.cargo.container.deployer.DeployableMonitor; +import org.codehaus.cargo.container.deployer.DeployableMonitorListener; +import org.codehaus.cargo.container.deployer.URLDeployableMonitor; + +/** + * Deploy a deployable to a container using Cargo. + * + * @version $Id: DeployMojo.java 789 2006-01-01 16:37:51Z vmassol $ + * @goal deploy + * @requiresDependencyResolution compile + */ +public class ModuleDeployMojo extends AbstractDeployerMojo +{ + public class DeployerListener implements DeployableMonitorListener + { + private Deployable deployable; + + public DeployerListener(Deployable deployable) + { + this.deployable = deployable; + } + + /* + * @see org.codehaus.cargo.container.deployer.DeployableMonitorListener#deployed() + */ + public void deployed() + { + getLog().debug("Watchdog finds [" + this.deployable.getFile().getPath() + + "] deployed."); + } + + /* + * @see org.codehaus.cargo.container.deployer.DeployableMonitorListener#undeployed() + */ + public void undeployed() + { + getLog().debug("Watchdog finds [" + this.deployable.getFile().getPath() + + "] not deployed yet."); + } + } + + /** + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() throws MojoExecutionException + { + super.execute(); + deploy(); + } + + private void deploy() throws MojoExecutionException + { + Container container = createContainer(); + org.codehaus.cargo.container.deployer.Deployer deployer = createDeployer(container); + + getLog().debug("Deploying into [" + container.getName() + "]..."); + + // Deploy all deployables defined in the deployer config element (if any) + if (getDeployerElement() != null) + { + for (int i = 0; i < getDeployerElement().getDeployables().length; i++) + { + Deployable deployable = getDeployerElement().getDeployables()[i].createDeployable( + container.getId(), getCargoProject()); + URL pingURL = getDeployerElement().getDeployables()[i].getPingURL(); + deploySingleDeployable(deployer, deployable, pingURL); + } + } + + if ((getCargoProject().getPackaging() != null) && getCargoProject().isJ2EEPackaging()) + { + // Deploy the auto-deployable if it has not already been deployed + if ((getDeployerElement() == null) + || (getDeployerElement().getDeployables() == null) + || !containsAutoDeployable(getDeployerElement().getDeployables())) + { + // The ping URL is always null here because if the user has specified a ping URL then + // the auto deployable has already been deployed as it's been explicitely specified + // by the user... + deploySingleDeployable(deployer, createAutoDeployDeployable(container), null); + } + } + } + + private void deploySingleDeployable(org.codehaus.cargo.container.deployer.Deployer deployer, + org.codehaus.cargo.container.deployable.Deployable deployable, URL pingURL) + { + + + getLog().debug("Deploying [" + deployable.getFile() + "]" + + ((pingURL == null) ? "..." : " using ping URL [" + pingURL + "]")); + + + if (pingURL != null) + { + deployer.deploy(deployable, createDeployableMonitor(pingURL, deployable)); + } + else + { + deployer.deploy(deployable); + } + + } + + private DeployableMonitor createDeployableMonitor(URL pingURL, Deployable deployable) + { + DeployableMonitor monitor = new URLDeployableMonitor(pingURL); + DeployerListener listener = new DeployerListener(deployable); + monitor.registerListener(listener); + return monitor; + } +} Index: D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleStartMojo.java =================================================================== --- D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleStartMojo.java (revision 0) +++ D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleStartMojo.java (revision 0) @@ -0,0 +1,53 @@ +/* + * ======================================================================== + * + * Copyright 2005-2006 Vincent Massol. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== + */ + +package org.codehaus.cargo.maven2; + +import org.codehaus.cargo.container.Container; +import org.codehaus.cargo.container.deployable.Deployable; +import org.apache.maven.plugin.MojoExecutionException; + +/** + * Stop deployable application in container using Cargo + * + * @version + * @goal start-module + * @requiresDependencyResolution compile + * + */ + +public class ModuleStartMojo extends AbstractModuleMojo +{ + + public void execute() throws MojoExecutionException + { + super.execute(); + moduleAction(); + } + + protected void singleDeployableAction(org.codehaus.cargo.container.deployer.Deployer deployer, + org.codehaus.cargo.container.deployable.Deployable deployable) + { + getLog().debug("Starting [" + deployable.getFile() + "] deployable ..."); + + deployer.start(deployable); + + } +} Index: D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleUndeployMojo.java =================================================================== --- D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleUndeployMojo.java (revision 0) +++ D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/ModuleUndeployMojo.java (revision 0) @@ -0,0 +1,51 @@ +/* + * ======================================================================== + * + * Copyright 2005 Vincent Massol. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== + */ +package org.codehaus.cargo.maven2; + +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.cargo.container.Container; +import org.codehaus.cargo.container.deployable.Deployable; + +/** + * Undeploy a deployable from a container using Cargo. + * + * @version $Id: UndeployMojo.java 803 2006-01-13 19:54:08Z vmassol $ + * @goal undeploy + * @requiresDependencyResolution compile + */ +public class ModuleUndeployMojo extends AbstractModuleMojo +{ + /** + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() throws MojoExecutionException + { + super.execute(); + moduleAction(); + } + + protected void singleDeployableAction(org.codehaus.cargo.container.deployer.Deployer deployer, + org.codehaus.cargo.container.deployable.Deployable deployable) + { + getLog().debug("Undeploying [" + deployable.getFile() + "]..."); + + deployer.undeploy(deployable); + } +} Index: D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/AbstractModuleMojo.java =================================================================== --- D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/AbstractModuleMojo.java (revision 0) +++ D:/workspace/cargo-svn/extensions/maven2/src/main/java/org/codehaus/cargo/maven2/AbstractModuleMojo.java (revision 0) @@ -0,0 +1,69 @@ +/* + * ======================================================================== + * + * Copyright 2005-2006 Vincent Massol. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== + */ + +package org.codehaus.cargo.maven2; + +import org.codehaus.cargo.container.Container; +import org.codehaus.cargo.container.deployable.Deployable; +import org.apache.maven.plugin.MojoExecutionException; + +/** + * Common code used for starting/stopping module in container + * + * @version + * + */ + +public abstract class AbstractModuleMojo extends AbstractDeployerMojo +{ + + protected void moduleAction() throws MojoExecutionException + { + Container container = createContainer(); + + org.codehaus.cargo.container.deployer.Deployer deployer = createDeployer(container); + getLog().debug("Deployable in [" + container.getName() + "] container ..."); + + // Do action on all deployables defined in the deployer config element (if any) + if (getDeployerElement() != null) + { + for (int i = 0; i < getDeployerElement().getDeployables().length; i++) + { + Deployable deployable = getDeployerElement().getDeployables()[i].createDeployable( + container.getId(), getCargoProject()); + deployable. + singleDeployableAction(deployer, deployable); + } + } + if ((getCargoProject().getPackaging() != null) && getCargoProject().isJ2EEPackaging()) + { + if ((getDeployerElement() == null) + || (getDeployerElement().getDeployables() == null) + || !containsAutoDeployable(getDeployerElement().getDeployables())) + { + singleDeployableAction(deployer, createAutoDeployDeployable(container)); + } + } + } + + protected abstract void singleDeployableAction(org.codehaus.cargo.container.deployer.Deployer deployer, + org.codehaus.cargo.container.deployable.Deployable deployable); + +}