1 /**
2 *
3 * Copyright 2004-2006 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.plugins.deployment;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.enterprise.deploy.spi.DeploymentManager;
24 import javax.enterprise.deploy.spi.Target;
25 import javax.enterprise.deploy.spi.TargetModuleID;
26 import javax.enterprise.deploy.spi.status.ProgressObject;
27
28 import org.apache.geronimo.plugins.util.DeploymentClient;
29 import org.apache.maven.plugin.MojoExecutionException;
30
31
32
33
34
35 /**
36 * ???
37 *
38 * @goal undeploy
39 *
40 * @version $Rev: 437248 $ $Date: 2006-08-26 16:39:49 -0700 (Sat, 26 Aug 2006) $
41 */
42 public class UndeployModuleMojo extends AbstractModuleMojo {
43
44 protected void doExecute() throws Exception {
45 DeploymentManager manager = getDeploymentManager();
46
47 Target[] targets = manager.getTargets();
48 TargetModuleID moduleIds[] = manager.getNonRunningModules(null, targets);
49 List toUndeploy = new ArrayList(moduleIds.length);
50
51 for (int i = 0; i < moduleIds.length; i++) {
52 TargetModuleID moduleId = moduleIds[i];
53 if (this.id.equals(moduleId.getModuleID())) {
54 toUndeploy.add(moduleId);
55 }
56 }
57
58 if (toUndeploy.size() == 0) {
59 throw new MojoExecutionException("Module is running or not deployed: " + this.id);
60 }
61
62 moduleIds = (TargetModuleID[]) toUndeploy.toArray(new TargetModuleID[toUndeploy.size()]);
63 ProgressObject progress = manager.undeploy(moduleIds);
64 DeploymentClient.waitFor(progress);
65 }
66 }