001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.geronimo.mavenplugins.geronimo.module; 021 022 import java.util.Arrays; 023 import java.util.ArrayList; 024 025 import org.apache.geronimo.mavenplugins.geronimo.ModuleConfig; 026 import org.apache.maven.plugin.MojoExecutionException; 027 import org.apache.maven.plugin.MojoFailureException; 028 029 /** 030 * Support for start/stop/undeploy mojos. 031 * 032 * @version $Rev: 450613 $ $Date: 2006-09-27 15:45:46 -0700 (Wed, 27 Sep 2006) $ 033 */ 034 public abstract class StartStopUndeployMojoSupport 035 extends ModuleMojoSupport 036 { 037 // 038 // TODO: Add support to take a set of ModuleConfig's and operate on them 039 // 040 041 /** 042 * The id of the module to be started in the format of <tt>groupId/artifactId/version/type</tt>. 043 * 044 * @parameter expression="${moduleId} 045 */ 046 protected String moduleId = null; 047 048 protected void init() throws MojoExecutionException, MojoFailureException { 049 super.init(); 050 051 if (moduleId != null) { 052 log.info("Using non-artifact based module id: " + moduleId); 053 054 // Add the single module to the list 055 ModuleConfig moduleConfig = createModuleConfigFromId(moduleId); 056 if (modules == null) { 057 modules = new ModuleConfig[] { 058 moduleConfig 059 }; 060 } 061 else { 062 ArrayList list = (ArrayList) Arrays.asList(modules); 063 list.add(moduleConfig); 064 modules = (ModuleConfig[]) list.toArray(new ModuleConfig[list.size()]); 065 } 066 } 067 else if (modules == null || modules.length == 0) { 068 throw new MojoExecutionException("At least one module configuration (or moduleId) must be specified"); 069 } 070 } 071 072 private ModuleConfig createModuleConfigFromId(String moduleId) throws MojoExecutionException { 073 assert moduleId != null; 074 075 ModuleConfig moduleConfig = new ModuleConfig(); 076 moduleId = moduleId.replace('\\', '/'); 077 String[] splitStr = moduleId.split("/"); 078 if (splitStr.length != 4) { 079 throw new MojoExecutionException("Invalid moduleId: " + moduleId); 080 } 081 moduleConfig.setGroupId(splitStr[0]); 082 moduleConfig.setArtifactId(splitStr[1]); 083 moduleConfig.setVersion(splitStr[2]); 084 moduleConfig.setType(splitStr[3]); 085 086 return moduleConfig; 087 } 088 }