View Javadoc

1   /*
2    *  Copyright 2006 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package org.apache.geronimo.plugin;
18  
19  import org.apache.maven.plugin.AbstractMojo;
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.plugin.MojoFailureException;
22  import org.apache.maven.plugin.logging.Log;
23  
24  /**
25   * Support for Mojo implementations.
26   *
27   * @version $Id: MojoSupport.java 422054 2006-07-14 21:25:59Z jdillon $
28   */
29  public abstract class MojoSupport
30      extends AbstractMojo
31  {
32      protected Log log;
33  
34      protected void init() {
35          log = getLog();
36      }
37  
38      public void execute() throws MojoExecutionException, MojoFailureException {
39          init();
40  
41          try {
42              doExecute();
43          }
44          catch (Exception e) {
45              if (e instanceof MojoExecutionException) {
46                  throw (MojoExecutionException)e;
47              }
48              else if (e instanceof MojoFailureException) {
49                  throw (MojoFailureException)e;
50              }
51              else {
52                  throw new MojoExecutionException(e.getMessage(), e);
53              }
54          }
55      }
56  
57      protected void doExecute() throws Exception {
58          // Sub-class should override
59      }
60  }