KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > mavenplugins > geronimo > module > StartStopUndeployMojoSupport


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */

19
20 package org.apache.geronimo.mavenplugins.geronimo.module;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.ArrayList JavaDoc;
25
26 import org.apache.geronimo.mavenplugins.geronimo.ModuleConfig;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29
30 /**
31  * Support for start/stop/undeploy mojos.
32  *
33  * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
34  */

35 public abstract class StartStopUndeployMojoSupport
36     extends ModuleMojoSupport
37 {
38     //
39
// TODO: Add support to take a set of ModuleConfig's and operate on them
40
//
41

42     /**
43      * The id of the module to be started in the format of <tt>groupId/artifactId/version/type</tt>.
44      *
45      * @parameter expression="${moduleId}
46      */

47     protected String JavaDoc moduleId = null;
48
49     protected void init() throws MojoExecutionException, MojoFailureException {
50         super.init();
51
52         if (moduleId != null) {
53             log.info("Using non-artifact based module id: " + moduleId);
54
55             // Add the single module to the list
56
//
57
// FIXME Should be able to handle multiple moduleIds
58
//
59
ModuleConfig moduleConfig = createModuleConfigFromId(moduleId);
60             if (modules == null) {
61                 modules = new ModuleConfig[] {
62                     moduleConfig
63                 };
64             }
65             else {
66                 List JavaDoc list = Arrays.asList(modules);
67                 ArrayList JavaDoc aList = new ArrayList JavaDoc(list);
68                 aList.add(moduleConfig);
69                 modules = (ModuleConfig[]) aList.toArray(new ModuleConfig[list.size()]);
70             }
71         }
72         else if (modules == null || modules.length == 0) {
73             throw new MojoExecutionException("At least one module configuration (or moduleId) must be specified");
74         }
75     }
76
77     private ModuleConfig createModuleConfigFromId(String JavaDoc moduleId) throws MojoExecutionException {
78         assert moduleId != null;
79
80         ModuleConfig moduleConfig = new ModuleConfig();
81         moduleId = moduleId.replace('\\', '/');
82         String JavaDoc[] splitStr = moduleId.split("/");
83         if (splitStr.length != 4) {
84             throw new MojoExecutionException("Invalid moduleId: " + moduleId);
85         }
86         moduleConfig.setGroupId(splitStr[0]);
87         moduleConfig.setArtifactId(splitStr[1]);
88         moduleConfig.setVersion(splitStr[2]);
89         moduleConfig.setType(splitStr[3]);
90          
91         return moduleConfig;
92     }
93 }
94
Popular Tags