001 /* 002 * Copyright (C) 2006-2007 the original author or authors. 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.codehaus.gmaven.plugin; 018 019 import org.codehaus.gmaven.feature.Component; 020 import org.codehaus.gmaven.feature.Configuration; 021 import org.codehaus.gmaven.feature.Feature; 022 023 /** 024 * Support for Mojo implementations which delegate to a feature component. 025 * 026 * @version $Id: ComponentMojoSupport.java 9 2009-07-16 09:22:08Z user57 $ 027 * @author <a href="mailto:jason@planet57.com">Jason Dillon</a> 028 */ 029 public abstract class ComponentMojoSupport 030 extends ProviderMojoSupport 031 { 032 private final String key; 033 034 protected ComponentMojoSupport(final String key) { 035 this.key = key; 036 } 037 038 private Feature cachedFeature; 039 040 protected synchronized Feature feature() throws Exception { 041 if (cachedFeature == null) { 042 cachedFeature = feature(key); 043 } 044 045 return cachedFeature; 046 } 047 048 protected synchronized Feature feature(final String key) throws Exception { 049 return provider().feature(key); 050 } 051 052 protected void doExecute() throws Exception { 053 Feature feature = feature(); 054 055 Configuration context = new Configuration(); 056 configure(context); 057 058 Component component = feature.create(context); 059 060 process(component); 061 } 062 063 protected void configure(final Configuration context) throws Exception { 064 // Nothing by default 065 } 066 067 protected abstract void process(Component component) throws Exception; 068 069 }