View Javadoc

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;
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      // TODO: Add support to take a set of ModuleConfig's and operate on them
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              // Add the single module to the list
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  }