001 /* 002 * Copyright 2006 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.geronimo.plugin; 018 019 import org.apache.maven.plugin.AbstractMojo; 020 import org.apache.maven.plugin.MojoExecutionException; 021 import org.apache.maven.plugin.MojoFailureException; 022 import org.apache.maven.plugin.logging.Log; 023 024 /** 025 * Support for Mojo implementations. 026 * 027 * @version $Id: MojoSupport.java 422054 2006-07-14 21:25:59Z jdillon $ 028 */ 029 public abstract class MojoSupport 030 extends AbstractMojo 031 { 032 protected Log log; 033 034 protected void init() { 035 log = getLog(); 036 } 037 038 public void execute() throws MojoExecutionException, MojoFailureException { 039 init(); 040 041 try { 042 doExecute(); 043 } 044 catch (Exception e) { 045 if (e instanceof MojoExecutionException) { 046 throw (MojoExecutionException)e; 047 } 048 else if (e instanceof MojoFailureException) { 049 throw (MojoFailureException)e; 050 } 051 else { 052 throw new MojoExecutionException(e.getMessage(), e); 053 } 054 } 055 } 056 057 protected void doExecute() throws Exception { 058 // Sub-class should override 059 } 060 }