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.List; 024 import java.util.ArrayList; 025 026 import org.apache.geronimo.mavenplugins.geronimo.ModuleConfig; 027 import org.apache.maven.plugin.MojoExecutionException; 028 import org.apache.maven.plugin.MojoFailureException; 029 030 /** 031 * Support for start/stop/undeploy mojos. 032 * 033 * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $ 034 */ 035 public abstract class StartStopUndeployMojoSupport 036 extends ModuleMojoSupport 037 { 038 // 039 // TODO: Add support to take a set of ModuleConfig's and operate on them 040 // 041 042 /** 043 * The id of the module to be started in the format of <tt>groupId/artifactId/version/type</tt>. 044 * 045 * @parameter expression="${moduleId} 046 */ 047 protected String moduleId = null; 048 049 protected void init() throws MojoExecutionException, MojoFailureException { 050 super.init(); 051 052 if (moduleId != null) { 053 log.info("Using non-artifact based module id: " + moduleId); 054 055 // Add the single module to the list 056 // 057 // FIXME Should be able to handle multiple moduleIds 058 // 059 ModuleConfig moduleConfig = createModuleConfigFromId(moduleId); 060 if (modules == null) { 061 modules = new ModuleConfig[] { 062 moduleConfig 063 }; 064 } 065 else { 066 List list = Arrays.asList(modules); 067 ArrayList aList = new ArrayList(list); 068 aList.add(moduleConfig); 069 modules = (ModuleConfig[]) aList.toArray(new ModuleConfig[list.size()]); 070 } 071 } 072 else if (modules == null || modules.length == 0) { 073 throw new MojoExecutionException("At least one module configuration (or moduleId) must be specified"); 074 } 075 } 076 077 private ModuleConfig createModuleConfigFromId(String moduleId) throws MojoExecutionException { 078 assert moduleId != null; 079 080 ModuleConfig moduleConfig = new ModuleConfig(); 081 moduleId = moduleId.replace('\\', '/'); 082 String[] splitStr = moduleId.split("/"); 083 if (splitStr.length != 4) { 084 throw new MojoExecutionException("Invalid moduleId: " + moduleId); 085 } 086 moduleConfig.setGroupId(splitStr[0]); 087 moduleConfig.setArtifactId(splitStr[1]); 088 moduleConfig.setVersion(splitStr[2]); 089 moduleConfig.setType(splitStr[3]); 090 091 return moduleConfig; 092 } 093 }