jvanzyl 2004/05/07 17:50:36 Modified: maven-core/src/main/java/org/apache/maven/plugin/manager DefaultPluginManagerManager.java maven-core/src/main/resources/org/apache/maven plexus.xml Added: maven-core/src/main/java/org/apache/maven/plugin PluginConfigurationException.java maven-core/src/main/java/org/apache/maven/plugin/manager OgnlProjectValueExtractor.java PlexusPluginManager.java maven-core/src/main/java/org/apache/maven/plugin/manager/executor FieldPluginExecutor.java IntegratedPluginExecutor.java PluginExecutor.java SetterPluginExecutor.java Removed: maven-core/src/main/java/org/apache/maven/plugin/plexus OgnlProjectValueExtractor.java PlexusPluginManager.java PluginConfigurationException.java maven-core/src/main/java/org/apache/maven/plugin/plexus/executor FieldPluginExecutor.java IntegratedPluginExecutor.java PluginExecutor.java SetterPluginExecutor.java maven-core/src/test/java/org/apache/maven/plugin PluginConfiguratorTest.java Log: o folding everything into a plugin manager which will be dealt with by plexus. Revision Changes Path 1.1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/PluginConfigurationException.java Index: PluginConfigurationException.java =================================================================== package org.apache.maven.plugin; /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * * @version $Id: PluginConfigurationException.java,v 1.1 2004/05/08 00:50:35 jvanzyl Exp $ */ public class PluginConfigurationException extends Exception { public PluginConfigurationException( String message ) { super( message ); } public PluginConfigurationException( String message, Throwable cause ) { super( message, cause ); } } 1.14 +0 -1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/DefaultPluginManagerManager.java Index: DefaultPluginManagerManager.java =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/DefaultPluginManagerManager.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- DefaultPluginManagerManager.java 7 May 2004 23:46:51 -0000 1.13 +++ DefaultPluginManagerManager.java 8 May 2004 00:50:35 -0000 1.14 @@ -19,7 +19,6 @@ import org.apache.maven.lifecycle.MavenLifecycleContext; import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionResponse; -import org.apache.maven.plugin.plexus.OgnlProjectValueExtractor; import org.apache.maven.plugin.descriptor.GoalDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; 1.1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/OgnlProjectValueExtractor.java Index: OgnlProjectValueExtractor.java =================================================================== package org.apache.maven.plugin.manager; /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import ognl.Ognl; import ognl.OgnlException; import org.apache.maven.project.MavenProject; /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * * @version $Id: OgnlProjectValueExtractor.java,v 1.1 2004/05/08 00:50:35 jvanzyl Exp $ */ public class OgnlProjectValueExtractor { public static Object evaluate( String expression, MavenProject project ) { Object value = null; if ( expression.equals( "#project" ) ) { value = project; } else if ( expression.startsWith( "#project" ) ) { try { value = Ognl.getValue( expression.substring( 9 ), project ); } catch ( OgnlException e ) { // do nothing } } else if ( expression.startsWith( "#" ) ) { expression = expression.substring( 1 ); value = project.getProperty( expression ); } // If we strike out we'll just use the expression which allows // people to use hardcoded values if they wish. if ( value == null ) { value = expression; } return value; } } 1.1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/PlexusPluginManager.java Index: PlexusPluginManager.java =================================================================== package org.apache.maven.plugin.manager; /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.plugin.Plugin; import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.manager.AbstractPluginManager; import org.apache.maven.plugin.manager.executor.PluginExecutor; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; /** * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @version $Id: PlexusPluginManager.java,v 1.1 2004/05/08 00:50:35 jvanzyl Exp $ */ public class PlexusPluginManager extends AbstractPluginManager implements Contextualizable { private PlexusContainer container; public void loadPlugin( String name ) throws Exception { } public String getId() { return "plexus"; } public void attainGoal( PluginExecutionRequest request, PluginExecutionResponse response ) { try { Object plugin = container.lookup( Plugin.ROLE, (String) request.getContextValue( "id" ) ); request.setPlugin( plugin ); PluginExecutor pluginExecutor = (PluginExecutor) container.lookup( PluginExecutor.ROLE, (String) request.getContextValue( "mode" ) ); pluginExecutor.execute( request, response ); } catch ( ComponentLookupException e ) { response.setException( e ); } } // ---------------------------------------------------------------------- // Lifecylce Management // ---------------------------------------------------------------------- public void contextualize( Context context ) throws ContextException { container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); } } 1.1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/executor/FieldPluginExecutor.java Index: FieldPluginExecutor.java =================================================================== package org.apache.maven.plugin.manager.executor; /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginConfigurationException; import org.apache.maven.plugin.PluginConfigurationException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Iterator; import java.util.Map; /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * * @version $Id: FieldPluginExecutor.java,v 1.1 2004/05/08 00:50:35 jvanzyl Exp $ */ public class FieldPluginExecutor implements PluginExecutor { public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) { Object plugin = request.getPlugin(); if ( request.getParameters() != null ) { try { plugin = configure( plugin, request.getParameters() ); } catch ( PluginConfigurationException e ) { response.setException( e ); return; } } Method m = null; try { m = plugin.getClass().getMethod( "execute", new Class[0] ); m.invoke( plugin, new Object[0] ); } catch ( NoSuchMethodException e ) { response.setException( e ); } catch ( InvocationTargetException e ) { response.setException( e.getTargetException() ); } catch ( Exception e ) { response.setException( e ); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- protected Object configure( Object plugin, Map parameters ) throws PluginConfigurationException { Class pluginClass = plugin.getClass(); for ( Iterator iterator = parameters.keySet().iterator(); iterator.hasNext(); ) { String fieldName = (String) iterator.next(); Object value = parameters.get( fieldName ); try { Field field = getField( pluginClass, fieldName ); field.setAccessible( true ); field.set( plugin, value ); } catch ( Exception e ) { throw new PluginConfigurationException( "Error setting value of field " + fieldName + " with " + value + ".", e ); } } return plugin; } private Field getField( Class clazz, String fieldName ) throws Exception { Field field = null; try { field = clazz.getDeclaredField( fieldName ); } catch ( NoSuchFieldException e ) { if ( clazz.getSuperclass() != Object.class ) { field = getField( clazz.getSuperclass(), fieldName ); } else { throw e; } } catch ( Exception e ) { throw e; } return field; } } 1.1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/executor/IntegratedPluginExecutor.java Index: IntegratedPluginExecutor.java =================================================================== package org.apache.maven.plugin.manager.executor; /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.Plugin; import org.apache.maven.plugin.manager.OgnlProjectValueExtractor; import org.apache.maven.plugin.descriptor.ParameterDescriptor; import java.util.List; import java.util.Map; import java.util.HashMap; /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * * @version $Id: IntegratedPluginExecutor.java,v 1.1 2004/05/08 00:50:35 jvanzyl Exp $ */ public class IntegratedPluginExecutor implements PluginExecutor { public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) { try { ((Plugin) request.getPlugin()).execute( request, response ); } catch ( Exception e ) { response.setException( e ); } } } 1.1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/executor/PluginExecutor.java Index: PluginExecutor.java =================================================================== package org.apache.maven.plugin.manager.executor; /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginExecutionRequest; /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * * @version $Id: PluginExecutor.java,v 1.1 2004/05/08 00:50:35 jvanzyl Exp $ */ public interface PluginExecutor { String ROLE = PluginExecutor.class.getName(); void execute( PluginExecutionRequest request, PluginExecutionResponse response ); } 1.1 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/executor/SetterPluginExecutor.java Index: SetterPluginExecutor.java =================================================================== package org.apache.maven.plugin.manager.executor; /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginConfigurationException; import org.apache.maven.plugin.PluginConfigurationException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Iterator; import java.util.Map; /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * * @version $Id: SetterPluginExecutor.java,v 1.1 2004/05/08 00:50:35 jvanzyl Exp $ */ public class SetterPluginExecutor implements PluginExecutor { public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) { Object plugin = request.getPlugin(); if ( request.getParameters() != null ) { try { plugin = configure( plugin, request.getParameters() ); } catch ( PluginConfigurationException e ) { response.setException( e ); return; } } Method m = null; try { m = plugin.getClass().getMethod( "execute", new Class[0] ); m.invoke( plugin, new Object[0] ); } catch ( NoSuchMethodException e ) { response.setException( e ); } catch ( InvocationTargetException e ) { response.setException( e.getTargetException() ); } catch ( Exception e ) { response.setException( e ); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public Object configure( Object plugin, Map parameters ) throws PluginConfigurationException { Class pluginClass = plugin.getClass(); for ( Iterator iterator = parameters.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); Object value = parameters.get( key); String methodName = "set" + capitalise( key ); try { Method method = pluginClass.getMethod( methodName, new Class[]{value.getClass()} ); method.invoke( plugin, new Object[]{value} ); } catch ( Exception e ) { throw new PluginConfigurationException( "Error setting value with method " + methodName + " with " + value + ".", e ); } } return plugin; } private String capitalise( String str ) { return new StringBuffer( str.length() ) .append( Character.toTitleCase( str.charAt( 0 ) ) ) .append( str.substring( 1 ) ) .toString(); } } 1.10 +7 -12 maven-components/maven-core/src/main/resources/org/apache/maven/plexus.xml Index: plexus.xml =================================================================== RCS file: /home/cvs/maven-components/maven-core/src/main/resources/org/apache/maven/plexus.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- plexus.xml 16 Apr 2004 13:56:09 -0000 1.9 +++ plexus.xml 8 May 2004 00:50:35 -0000 1.10 @@ -29,27 +29,22 @@ <component> <role>org.apache.maven.plugin.manager.PluginManager</role> <role-hint>plexus</role-hint> - <implementation>org.apache.maven.plugin.plexus.PlexusPluginManager</implementation> + <implementation>org.apache.maven.plugin.manager.PlexusPluginManager</implementation> </component> <component> - <role>org.apache.maven.plugin.plexus.executor.PluginExecutor</role> + <role>org.apache.maven.plugin.manager.executor.PluginExecutor</role> <role-hint>field</role-hint> - <implementation>org.apache.maven.plugin.plexus.executor.FieldPluginExecutor</implementation> + <implementation>org.apache.maven.plugin.manager.executor.FieldPluginExecutor</implementation> </component> <component> - <role>org.apache.maven.plugin.plexus.executor.PluginExecutor</role> + <role>org.apache.maven.plugin.manager.executor.PluginExecutor</role> <role-hint>setter</role-hint> - <implementation>org.apache.maven.plugin.plexus.executor.SetterPluginExecutor</implementation> + <implementation>org.apache.maven.plugin.manager.executor.SetterPluginExecutor</implementation> </component> <component> - <role>org.apache.maven.plugin.plexus.executor.PluginExecutor</role> - <role-hint>singleton</role-hint> - <implementation>org.apache.maven.plugin.plexus.executor.SingletonPluginExecutor</implementation> - </component> - <component> - <role>org.apache.maven.plugin.plexus.executor.PluginExecutor</role> + <role>org.apache.maven.plugin.manager.executor.PluginExecutor</role> <role-hint>integrated</role-hint> - <implementation>org.apache.maven.plugin.plexus.executor.IntegratedPluginExecutor</implementation> + <implementation>org.apache.maven.plugin.manager.executor.IntegratedPluginExecutor</implementation> </component> </components> </configuration>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]