From b2e44336151665cd52778bb3278487872f02c067 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 15 Apr 2005 04:52:31 +0000 Subject: [PATCH] utilise the container for populating all mojo configuration, including expressions git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163947 13f79535-47bb-0310-9956-ffa450edef68 --- maven-core/pom.xml | 2 +- .../maven/plugin/DefaultPluginManager.java | 229 ++++++++++-------- .../PluginParameterExpressionEvaluator.java | 64 ++--- .../resources/META-INF/plexus/components.xml | 6 + ...luginParameterExpressionEvaluatorTest.java | 22 +- .../plugin/descriptor/MojoDescriptor.java | 13 + .../descriptor/PluginDescriptorBuilder.java | 8 + .../generator/PluginDescriptorGenerator.java | 73 +++++- .../PluginDescriptorGeneratorTest.java | 2 - .../org/apache/maven/plugin/ejb/EjbMojo.java | 2 +- .../org/apache/maven/test/SurefirePlugin.java | 13 +- .../org/apache/maven/plugin/war/WarMojo.java | 21 +- 12 files changed, 296 insertions(+), 159 deletions(-) diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 8b9135b45d..bf44718894 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -62,7 +62,7 @@ plexus plexus-container-default - 1.0-alpha-2 + 1.0-alpha-3-SNAPSHOT org.apache.maven.wagon diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index dd53e7b2c9..978641a804 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -42,12 +42,13 @@ import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ComponentConfigurator; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; @@ -392,19 +393,31 @@ public class DefaultPluginManager configuration = new XmlPlexusConfiguration( dom ); } - if ( newMojoTechnique ) - { - Map map = getPluginConfigurationFromExpressions( mojoDescriptor, configuration, session ); + configuration = mergeConfiguration( configuration, mojoDescriptor.getConfiguration() ); - populatePluginFields( plugin, configuration, map ); + PluginParameterExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session ); + try + { + if ( newMojoTechnique ) + { + Map map = getPluginConfigurationFromExpressions( mojoDescriptor, configuration, session, + expressionEvaluator ); + + populatePluginFields( plugin, configuration, map, expressionEvaluator ); + } + else + { + getLogger().warn( "WARNING: The mojo " + mojoDescriptor.getId() + " is using the OLD API" ); + + Map map = getPluginConfigurationFromExpressions( mojoDescriptor, configuration, session, + expressionEvaluator ); + + request = createPluginRequest( configuration, map ); + } } - else + catch ( ExpressionEvaluationException e ) { - getLogger().warn( "WARNING: The mojo " + mojoDescriptor.getId() + " is using the OLD API" ); - - Map map = getPluginConfigurationFromExpressions( mojoDescriptor, configuration, session ); - - request = createPluginRequest( configuration, map ); + throw new PluginExecutionException( "Unable to configure plugin", e ); } // !! This is ripe for refactoring to an aspect. @@ -436,7 +449,8 @@ public class DefaultPluginManager } catch ( PluginConfigurationException e ) { - throw new PluginExecutionException( "Error configuring plugin for execution.", e ); + String msg = "Error configuring plugin for execution of ."; + throw new PluginExecutionException( msg, e ); } catch ( ComponentLookupException e ) { @@ -446,8 +460,6 @@ public class DefaultPluginManager { try { - releaseComponents( mojoDescriptor, request ); - container.release( plugin ); } catch ( Exception e ) @@ -458,6 +470,48 @@ public class DefaultPluginManager } } + private PlexusConfiguration mergeConfiguration( PlexusConfiguration dominant, PlexusConfiguration configuration ) + { + // TODO: share with mergeXpp3Dom + PlexusConfiguration[] children = configuration.getChildren(); + for ( int i = 0; i < children.length; i++ ) + { + PlexusConfiguration child = children[i]; + PlexusConfiguration childDom = (XmlPlexusConfiguration) dominant.getChild( child.getName(), false ); + if ( childDom != null ) + { + mergeConfiguration( childDom, child ); + } + else + { + dominant.addChild( copyConfiguration( child ) ); + } + } + return dominant; + } + + public static PlexusConfiguration copyConfiguration( PlexusConfiguration src ) + { + // TODO: shouldn't be necessary + XmlPlexusConfiguration dom = new XmlPlexusConfiguration( src.getName() ); + dom.setValue( src.getValue( null ) ); + + String[] attributeNames = src.getAttributeNames(); + for ( int i = 0; i < attributeNames.length; i++ ) + { + String attributeName = attributeNames[i]; + dom.setAttribute( attributeName, src.getAttribute( attributeName, null ) ); + } + + PlexusConfiguration[] children = src.getChildren(); + for ( int i = 0; i < children.length; i++ ) + { + dom.addChild( copyConfiguration( children[i] ) ); + } + + return dom; + } + /** * @deprecated */ @@ -482,61 +536,36 @@ public class DefaultPluginManager return newMojoTechnique; } - // TODO: don't throw Exception - private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request ) - throws Exception - { - if ( request != null && request.getParameters() != null ) - { - for ( Iterator iterator = goal.getParameters().iterator(); iterator.hasNext(); ) - { - Parameter parameter = (Parameter) iterator.next(); - - String key = parameter.getName(); - - String expression = parameter.getExpression(); - - if ( expression != null && expression.startsWith( "#component" ) ) - { - Object component = request.getParameter( key ); - - container.release( component ); - } - } - } - } - // ---------------------------------------------------------------------- // Mojo Parameter Handling // ---------------------------------------------------------------------- + /** + * @param configuration + * @param map + * @return + * @deprecated + */ private static PluginExecutionRequest createPluginRequest( PlexusConfiguration configuration, Map map ) - throws PluginConfigurationException { - try + Map parameters = new HashMap(); + PlexusConfiguration[] children = configuration.getChildren(); + for ( int i = 0; i < children.length; i++ ) { - Map parameters = new HashMap(); - PlexusConfiguration[] children = configuration.getChildren(); - for ( int i = 0; i < children.length; i++ ) - { - PlexusConfiguration child = children[i]; - parameters.put( child.getName(), child.getValue() ); - } - map = CollectionUtils.mergeMaps( map, parameters ); - } - catch ( PlexusConfigurationException e ) - { - throw new PluginConfigurationException( "Unable to construct map from plugin configuration", e ); + PlexusConfiguration child = children[i]; + parameters.put( child.getName(), child.getValue( null ) ); } + map = CollectionUtils.mergeMaps( map, parameters ); return new PluginExecutionRequest( map ); } - private void populatePluginFields( Plugin plugin, PlexusConfiguration configuration, Map map ) + private void populatePluginFields( Plugin plugin, PlexusConfiguration configuration, Map map, + ExpressionEvaluator expressionEvaluator ) throws PluginConfigurationException { try { - configurator.configureComponent( plugin, configuration ); + configurator.configureComponent( plugin, configuration, expressionEvaluator ); } catch ( ComponentConfigurationException e ) { @@ -544,7 +573,7 @@ public class DefaultPluginManager } // Configuration does not store objects, so the non-String fields are configured here - // TODO: we don't have converters, so "primitives" that -are- strings are not configured properly (eg String -> File from an expression) + // TODO: remove - this is for plugins built with alpha-1 for ( Iterator i = map.keySet().iterator(); i.hasNext(); ) { String key = (String) i.next(); @@ -602,9 +631,12 @@ public class DefaultPluginManager } } + /** + * @deprecated + */ private Map getPluginConfigurationFromExpressions( MojoDescriptor goal, PlexusConfiguration configuration, - MavenSession session ) - throws PluginConfigurationException + MavenSession session, ExpressionEvaluator expressionEvaluator ) + throws ExpressionEvaluationException, PluginConfigurationException { List parameters = goal.getParameters(); @@ -616,49 +648,52 @@ public class DefaultPluginManager String key = parameter.getName(); + String expression; if ( configuration.getChild( key, false ) == null ) { - String expression = parameter.getExpression(); - - Object value = PluginParameterExpressionEvaluator.evaluate( expression, session ); - - getLogger().debug( "Evaluated mojo parameter expression: \'" + expression + "\' to: " + value ); - - if ( value == null ) - { - if ( parameter.getDefaultValue() != null ) - { - value = PluginParameterExpressionEvaluator.evaluate( parameter.getDefaultValue(), session ); - } - } - - // ---------------------------------------------------------------------- - // We will perform a basic check here for parameters values that are - // required. Required parameters can't be null so we throw an - // Exception in the case where they are. We probably want some - // pluggable - // mechanism here but this will catch the most obvious of - // misconfigurations. - // ---------------------------------------------------------------------- - - if ( value == null && parameter.isRequired() ) - { - throw new PluginConfigurationException( createPluginParameterRequiredMessage( goal, parameter ) ); - } - - String type = parameter.getType(); - - // TODO: Not sure how we might find files that are nested in other objects... perhaps - // we add a "needs translation" to the mojo so such types can be translated (implementing some interface) and - // address their own file objects - if ( type != null && ( type.equals( "File" ) || type.equals( "java.io.File" ) ) ) - { - value = pathTranslator.alignToBaseDirectory( (String) value, - session.getProject().getFile().getParentFile() ); - } - - map.put( key, value ); + expression = parameter.getExpression(); } + else + { + expression = configuration.getChild( key, false ).getValue( null ); + } + + Object value = expressionEvaluator.evaluate( expression ); + + getLogger().debug( "Evaluated mojo parameter expression: \'" + expression + "\' to: " + value ); + + if ( value == null ) + { + if ( parameter.getDefaultValue() != null ) + { + value = expressionEvaluator.evaluate( parameter.getDefaultValue() ); + } + } + + // ---------------------------------------------------------------------- + // We will perform a basic check here for parameters values that are + // required. Required parameters can't be null so we throw an + // Exception in the case where they are. We probably want some + // pluggable + // mechanism here but this will catch the most obvious of + // misconfigurations. + // ---------------------------------------------------------------------- + + if ( value == null && parameter.isRequired() ) + { + throw new PluginConfigurationException( createPluginParameterRequiredMessage( goal, parameter ) ); + } + + String type = parameter.getType(); + + // TODO: remove - done via plexus configuration, but need to inject the base directory into it + if ( type != null && ( type.equals( "File" ) || type.equals( "java.io.File" ) ) ) + { + value = pathTranslator.alignToBaseDirectory( (String) value, + session.getProject().getFile().getParentFile() ); + } + + map.put( key, value ); } return map; } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java index b8ce53fddd..b2dfa9c85c 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java @@ -1,35 +1,44 @@ package org.apache.maven.plugin; -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. +/* + * Copyright 2001-2005 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 + * 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 + * 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. - * ==================================================================== + * 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.execution.MavenSession; -import org.apache.maven.project.MavenProject; import org.apache.maven.util.introspection.ReflectionValueExtractor; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * @author Jason van Zyl * @version $Id$ + * @todo belong in MavenSession, so it only gets created once? */ public class PluginParameterExpressionEvaluator + implements ExpressionEvaluator { - public static Object evaluate( String expression, MavenSession context ) - throws PluginConfigurationException + private final MavenSession context; + + public PluginParameterExpressionEvaluator( MavenSession context ) + { + this.context = context; + } + + public Object evaluate( String expression ) + throws ExpressionEvaluationException { Object value = null; @@ -51,7 +60,7 @@ public class PluginParameterExpressionEvaluator } catch ( ComponentLookupException e ) { - throw new PluginConfigurationException( "Cannot lookup component: " + role + ".", e ); + throw new ExpressionEvaluationException( "Cannot lookup component: " + role + ".", e ); } } else if ( expression.equals( "#localRepository" ) ) @@ -61,7 +70,7 @@ public class PluginParameterExpressionEvaluator else if ( expression.equals( "#maven.final.name" ) ) { // TODO: remove this alias - value = context.getProject().getModel().getBuild().getFinalName(); + value = context.getProject().getBuild().getFinalName(); } else if ( expression.equals( "#project" ) ) { @@ -75,18 +84,20 @@ public class PluginParameterExpressionEvaluator if ( pathSeparator > 0 ) { - value = getValue( expression.substring( 1, pathSeparator ), context.getProject() ) + - expression.substring( pathSeparator ); + String pathExpression = expression.substring( 1, pathSeparator ); + value = ReflectionValueExtractor.evaluate( pathExpression, context.getProject() ); + value = value + expression.substring( pathSeparator ); } else { - value = getValue( expression.substring( 1 ), context.getProject() ); + value = ReflectionValueExtractor.evaluate( expression.substring( 1 ), context.getProject() ); } } catch ( Exception e ) { - throw new PluginConfigurationException( "Error evaluating plugin parameter expression: " + expression, - e ); + // TODO: don't catch exception + throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression, + e ); } } else if ( "#settings".equals( expression ) ) @@ -128,12 +139,12 @@ public class PluginParameterExpressionEvaluator if ( sharpSeparator > 0 ) { - val = val.substring( 0, sharpSeparator ) + evaluate( val.substring( sharpSeparator ), context ); + val = val.substring( 0, sharpSeparator ) + evaluate( val.substring( sharpSeparator ) ); value = val; } else if ( sharpSeparator > 0 ) { - value = evaluate( val.substring( sharpSeparator ), context ); + value = evaluate( val.substring( sharpSeparator ) ); } } @@ -154,10 +165,5 @@ public class PluginParameterExpressionEvaluator return value; } - private static Object getValue( String expression, MavenProject project ) - throws Exception - { - return ReflectionValueExtractor.evaluate( expression, project ); - } } diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index b25a020555..add7456b9b 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -232,6 +232,12 @@ + + + org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator + org.apache.maven. + + diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 4fddd0d116..71fd1973b9 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -11,6 +11,7 @@ import org.apache.maven.monitor.logging.DefaultLog; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.MavenSettings; import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import java.io.File; import java.util.Collections; @@ -25,7 +26,8 @@ public class PluginParameterExpressionEvaluatorTest { private MavenProject project; - protected void setUp() throws Exception + protected void setUp() + throws Exception { super.setUp(); @@ -34,7 +36,8 @@ public class PluginParameterExpressionEvaluatorTest project = getProject( f ); } - public void testValueExtractionWithAPomValueContainingAPath() throws Exception + public void testValueExtractionWithAPomValueContainingAPath() + throws Exception { String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath(); @@ -59,7 +62,8 @@ public class PluginParameterExpressionEvaluatorTest new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ), Collections.EMPTY_LIST ); - Object value = PluginParameterExpressionEvaluator.evaluate( "#project.build.directory/classes", session ); + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session ); + Object value = expressionEvaluator.evaluate( "#project.build.directory/classes" ); String actual = new File( value.toString() ).getCanonicalPath(); @@ -69,7 +73,8 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( expected, actual ); } - public void testParameterThatIsAComponent() throws Exception + public void testParameterThatIsAComponent() + throws Exception { String role = "#component.org.apache.maven.project.MavenProjectBuilder"; @@ -85,12 +90,14 @@ public class PluginParameterExpressionEvaluatorTest new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ), Collections.EMPTY_LIST ); - Object value = PluginParameterExpressionEvaluator.evaluate( role, session ); + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session ); + Object value = expressionEvaluator.evaluate( role ); assertNotNull( value ); } - public void testLocalRepositoryExtraction() throws Exception + public void testLocalRepositoryExtraction() + throws Exception { ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); @@ -104,7 +111,8 @@ public class PluginParameterExpressionEvaluatorTest new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ), Collections.EMPTY_LIST ); - Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", session ); + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session ); + Object value = expressionEvaluator.evaluate( "#localRepository" ); assertEquals( "local", ( (ArtifactRepository) value ).getId() ); } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java index d942d52053..13dd2628e9 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java @@ -17,6 +17,7 @@ package org.apache.maven.plugin.descriptor; */ import org.codehaus.plexus.component.repository.ComponentRequirement; +import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.ArrayList; import java.util.HashMap; @@ -68,6 +69,8 @@ public class MojoDescriptor private String language = DEFAULT_LANGUAGE; + private PlexusConfiguration configuration; + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -230,4 +233,14 @@ public class MojoDescriptor { getRequirements().add( cr ); } + + public void setConfiguration( PlexusConfiguration configuration ) + { + this.configuration = configuration; + } + + public PlexusConfiguration getConfiguration() + { + return configuration; + } } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index f0db7f629c..b5ce30ca3f 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -147,8 +147,10 @@ public class PluginDescriptorBuilder parameter.setDescription( d.getChild( "description" ).getValue() ); + // TODO: remove parameter.setExpression( d.getChild( "expression" ).getValue() ); + // TODO: remove parameter.setDefaultValue( d.getChild( "default" ).getValue() ); parameters.add( parameter ); @@ -158,6 +160,12 @@ public class PluginDescriptorBuilder // TODO: this should not need to be handed off... + // ---------------------------------------------------------------------- + // Configuration + // ---------------------------------------------------------------------- + + mojo.setConfiguration( c.getChild( "configuration" ) ); + // ---------------------------------------------------------------------- // Requirements // ---------------------------------------------------------------------- diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index f7c9475129..235f622ed7 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -27,8 +27,10 @@ import java.io.File; import java.io.FileWriter; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -162,6 +164,7 @@ public class PluginDescriptorGenerator w.startElement( "parameters" ); Collection requirements = new ArrayList(); + Map configuration = new HashMap( parameters.size() ); for ( int j = 0; j < parameters.size(); j++ ) { Parameter parameter = (Parameter) parameters.get( j ); @@ -174,6 +177,7 @@ public class PluginDescriptorGenerator element( w, "validator", parameter.getValidator() ); + String value = null; if ( parameter.getExpression().startsWith( "#component" ) ) { requirements.add( parameter ); @@ -182,18 +186,54 @@ public class PluginDescriptorGenerator { element( w, "required", Boolean.toString( parameter.isRequired() ) ); - element( w, "expression", parameter.getExpression() ); + value = parameter.getExpression(); } element( w, "description", parameter.getDescription() ); - element( w, "default", parameter.getDefaultValue() ); + if ( value == null || value.length() == 0 ) + { + value = parameter.getDefaultValue(); + } + + if ( value != null && value.length() > 0 ) + { + configuration.put( parameter, value ); + } w.endElement(); } w.endElement(); + // ---------------------------------------------------------------------- + // Coinfiguration + // ---------------------------------------------------------------------- + + if ( !configuration.isEmpty() ) + { + w.startElement( "configuration" ); + + for ( Iterator i = configuration.keySet().iterator(); i.hasNext(); ) + { + Parameter parameter = (Parameter) i.next(); + + w.startElement( parameter.getName() ); + + String type = convertType( parameter.getType() ); + if ( type != null ) + { + w.addAttribute( "implementation", type ); + } + + w.writeText( (String) configuration.get( parameter ) ); + + w.endElement(); + } + + w.endElement(); + } + // ---------------------------------------------------------------------- // Requirements // ---------------------------------------------------------------------- @@ -225,6 +265,35 @@ public class PluginDescriptorGenerator w.endElement(); } + /** + * @param type + * @return + * @deprecated - should force proper class specification + */ + private static String convertType( String type ) + { + if ( "String".equals( type ) ) + { + return "java.lang.String"; + } + else if ( "File".equals( type ) ) + { + return "java.io.File"; + } + else if ( "List".equals( type ) ) + { + return "java.util.List"; + } + else if ( "".equals( type ) ) + { + return null; + } + else + { + return type; + } + } + public void element( XMLWriter w, String name, String value ) { w.startElement( name ); diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java index f6363b6d8d..4cfcbb68e8 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java @@ -106,8 +106,6 @@ public class PluginDescriptorGeneratorTest private void checkParameter( Parameter parameter ) { - assertEquals( "value", parameter.getDefaultValue() ); - assertEquals( "#project.build.directory", parameter.getExpression() ); assertEquals( "dir", parameter.getName() ); assertEquals( "String", parameter.getType() ); assertTrue( parameter.isRequired() ); diff --git a/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java b/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java index 5d27429e48..415c53e0df 100644 --- a/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java +++ b/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java @@ -46,7 +46,7 @@ import java.io.File; * type="String" * required="false" * validator="" - * expression="#maven.ejb.generateclient" + * expression="" * default="false" * description="" * @parameter name="outputDirectory" diff --git a/maven-plugins/maven-surefire-plugin/src/main/java/org/apache/maven/test/SurefirePlugin.java b/maven-plugins/maven-surefire-plugin/src/main/java/org/apache/maven/test/SurefirePlugin.java index 330ebf3972..7f2db99561 100644 --- a/maven-plugins/maven-surefire-plugin/src/main/java/org/apache/maven/test/SurefirePlugin.java +++ b/maven-plugins/maven-surefire-plugin/src/main/java/org/apache/maven/test/SurefirePlugin.java @@ -53,19 +53,19 @@ import java.util.StringTokenizer; * expression="#project.build.testOutputDirectory" * description="" * @parameter name="includes" - * type="String" + * type="java.util.List" * required="false" * validator="" * description="" * expression="" * @parameter name="excludes" - * type="String" + * type="java.util.List" * required="false" * validator="" * description="" * expression="" * @parameter name="classpathElements" - * type="String[]" + * type="java.util.List" * required="true" * validator="" * expression="#project.testClasspathElements" @@ -82,7 +82,12 @@ import java.util.StringTokenizer; * validator="" * expression="#test" * description="Specify this parameter if you want to use the test regex notation to select tests to run." - * @parameter name="localRepository" type="ArtifactRepository" required="true" validator="" expression="#localRepository" description="" + * @parameter name="localRepository" + * type="org.apache.maven.artifact.repository.ArtifactRepository" + * required="true" + * validator="" + * expression="#localRepository" + * description="" * @todo make version of junit and surefire configurable * @todo make report to be produced configurable */ diff --git a/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java b/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java index c690dea5aa..3658f51fdf 100644 --- a/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java +++ b/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java @@ -54,21 +54,20 @@ import java.util.Set; * type="String" * required="true" * validator="" - * expression="#maven.war.src" - * default="#basedir/src/main/webapp" + * expression="#basedir/src/main/webapp" * description="" * @parameter name="warSourceIncludes" * type="String" * required="false" * validator="" - * expression="#maven.war.src.includes" + * expression="" * default="**" * description="" * @parameter name="warSourceExcludes" * type="String" * required="false" * validator="" - * expression="#maven.war.src.excludes" + * expression="" * description="" * @parameter name="webXml" * type="String" @@ -80,14 +79,13 @@ import java.util.Set; * type="String" * required="true" * validator="" - * expression="#maven.war.webapp.dir" - * default="#project.build.directory/#project.build.finalName" + * expression="#project.build.directory/#project.build.finalName" * description="" * @parameter name="mode" * type="String" * required="true" * validator="" - * expression="#maven.war.mode" + * expression="" * default="war" * description="" * @parameter name="classesDirectory" @@ -100,13 +98,6 @@ import java.util.Set; * type="String" * required="true" * validator="" - * expression="#maven.war.build.dir" - * default="#project.build.directory" - * description="" - * @parameter name="basedir" - * type="String" - * required="true" - * validator="" * expression="#project.build.directory" * description="" * @parameter name="project" @@ -129,8 +120,6 @@ public class WarMojo private MavenProject project; - private String basedir; - /** * @todo File */