1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.geronimo.mavenplugins.geronimo.module;
21
22 import java.util.Arrays;
23 import java.util.ArrayList;
24
25 import org.apache.geronimo.mavenplugins.geronimo.ModuleConfig;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.MojoFailureException;
28
29 /**
30 * Support for start/stop/undeploy mojos.
31 *
32 * @version $Rev: 450613 $ $Date: 2006-09-27 15:45:46 -0700 (Wed, 27 Sep 2006) $
33 */
34 public abstract class StartStopUndeployMojoSupport
35 extends ModuleMojoSupport
36 {
37
38
39
40
41 /**
42 * The id of the module to be started in the format of <tt>groupId/artifactId/version/type</tt>.
43 *
44 * @parameter expression="${moduleId}
45 */
46 protected String moduleId = null;
47
48 protected void init() throws MojoExecutionException, MojoFailureException {
49 super.init();
50
51 if (moduleId != null) {
52 log.info("Using non-artifact based module id: " + moduleId);
53
54
55 ModuleConfig moduleConfig = createModuleConfigFromId(moduleId);
56 if (modules == null) {
57 modules = new ModuleConfig[] {
58 moduleConfig
59 };
60 }
61 else {
62 ArrayList list = (ArrayList) Arrays.asList(modules);
63 list.add(moduleConfig);
64 modules = (ModuleConfig[]) list.toArray(new ModuleConfig[list.size()]);
65 }
66 }
67 else if (modules == null || modules.length == 0) {
68 throw new MojoExecutionException("At least one module configuration (or moduleId) must be specified");
69 }
70 }
71
72 private ModuleConfig createModuleConfigFromId(String moduleId) throws MojoExecutionException {
73 assert moduleId != null;
74
75 ModuleConfig moduleConfig = new ModuleConfig();
76 moduleId = moduleId.replace('\\', '/');
77 String[] splitStr = moduleId.split("/");
78 if (splitStr.length != 4) {
79 throw new MojoExecutionException("Invalid moduleId: " + moduleId);
80 }
81 moduleConfig.setGroupId(splitStr[0]);
82 moduleConfig.setArtifactId(splitStr[1]);
83 moduleConfig.setVersion(splitStr[2]);
84 moduleConfig.setType(splitStr[3]);
85
86 return moduleConfig;
87 }
88 }