KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > mavenplugin > DistributeModule


1 /**
2  *
3  * Copyright 2004 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.deployment.mavenplugin;
19
20 import java.io.File JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.net.MalformedURLException JavaDoc;
23
24 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
25 import javax.enterprise.deploy.spi.Target JavaDoc;
26 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
27
28 /**
29  *
30  *
31  * @version $Rev: 54151 $ $Date: 2004-10-08 22:34:35 -0700 (Fri, 08 Oct 2004) $
32  *
33  * */

34 public class DistributeModule extends AbstractModuleCommand {
35
36     private String JavaDoc module;
37     private String JavaDoc plan;
38
39     public String JavaDoc getModule() {
40         return module;
41     }
42
43     public void setModule(String JavaDoc module) {
44         this.module = module;
45     }
46
47     public String JavaDoc getPlan() {
48         return plan;
49     }
50
51     public void setPlan(String JavaDoc plan) {
52         this.plan = plan;
53     }
54
55     public void execute() throws Exception JavaDoc {
56         DeploymentManager JavaDoc manager = getDeploymentManager();
57
58         Target JavaDoc[] targets = manager.getTargets();
59         File JavaDoc moduleFile = (getModule() == null)? null: getFile(getModule());
60         File JavaDoc planFile = (getPlan() == null)? null: getFile((getPlan()));
61         ProgressObject JavaDoc progress = manager.distribute(targets, moduleFile, planFile);
62         DeploymentClient.waitFor(progress);
63     }
64
65     private File JavaDoc getFile(String JavaDoc location) throws MalformedURLException JavaDoc {
66         try {
67             File JavaDoc f = new File JavaDoc(location).getCanonicalFile();
68             if (!f.exists() || !f.canRead()) {
69                 throw new MalformedURLException JavaDoc("Invalid location: " + location);
70             }
71             return f;
72         } catch (IOException JavaDoc e) {
73             throw (MalformedURLException JavaDoc) new MalformedURLException JavaDoc("Invalid location: " + location).initCause(e);
74         }
75             
76     }
77
78 }
79
Popular Tags