From 552b22c77a4a4a02253e6ecbddb7459c9135bee3 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Fri, 1 Oct 2004 18:00:09 +0000 Subject: [PATCH] o the first phase of merging plugin configuration as defined in the POM with defaults and user defined values. After a chat with emmanuel we decided that we would allow for plugin wide configuration and mojo/goal specific configuration with the more specific mojo/goal configuration winning in the event a parameter is defined in both places. Currently only plugin wide parameters are being considered: I still need to update the model for mojo/goal specific parameters and then update the parameter merging code. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163181 13f79535-47bb-0310-9956-ffa450edef68 --- .../goal/phase/GoalAttainmentPhase.java | 71 ++++++++++++++----- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java index f07fb569f1..d49a826a47 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java @@ -26,7 +26,9 @@ import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginConfigurationException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.util.CollectionUtils; import java.util.HashMap; import java.util.Iterator; @@ -121,21 +123,58 @@ public class GoalAttainmentPhase Object value = OgnlProjectValueExtractor.evaluate( expression, context ); - // ---------------------------------------------------------------------- - // 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 ) ); - } - map.put( key, value ); } + + map = mergeProjectDefinedPluginConfiguration( context.getProject(), goal.getId(), map ); + } + + for ( int i = 0; i < parameters.size(); i++ ) + { + Parameter parameter = (Parameter) parameters.get( i ); + + String key = parameter.getName(); + + Object value = map.get( key ); + + // ---------------------------------------------------------------------- + // 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 ) ); + } + } + + return map; + } + + private Map mergeProjectDefinedPluginConfiguration( MavenProject project, String goalId, Map map ) + { + // ---------------------------------------------------------------------- + // I would like to be able to lookup the Plugin object using a key but + // we have a limitation in modello that will be remedied shortly. So + // for now I have to iterate through and see what we have. + // ---------------------------------------------------------------------- + + if ( project.getPlugins() != null ) + { + String pluginId = goalId.substring( 0, goalId.indexOf( ":" ) ); + + for ( Iterator iterator = project.getPlugins().iterator(); iterator.hasNext(); ) + { + org.apache.maven.model.Plugin plugin = (org.apache.maven.model.Plugin) iterator.next(); + + if ( pluginId.equals( plugin.getId() ) ) + { + return CollectionUtils.mergeMaps( plugin.getConfiguration(), map ); + } + } } return map; @@ -146,9 +185,9 @@ public class GoalAttainmentPhase StringBuffer message = new StringBuffer(); message.append( "The '" + parameter.getName() ). - append( "' parameter is required for the execution of the " ). - append( mojo.getId() ). - append( " mojo and cannot be null." ); + append( "' parameter is required for the execution of the " ). + append( mojo.getId() ). + append( " mojo and cannot be null." ); return message.toString(); }