don't fail if there is a default value and the parameter is set to required.

Reformat according to intelliJ settings.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@165266 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-29 06:06:14 +00:00
parent a59b1e1d8c
commit 36f970b652
1 changed files with 73 additions and 92 deletions

View File

@ -228,8 +228,8 @@ public class DefaultPluginManager
if ( StringUtils.isEmpty( pluginConfig.getVersion() ) ) if ( StringUtils.isEmpty( pluginConfig.getVersion() ) )
{ {
// The model/project builder should have validated this already // The model/project builder should have validated this already
String message = "The maven plugin with groupId: '" + groupId + "' and artifactId: '" + artifactId String message = "The maven plugin with groupId: '" + groupId + "' and artifactId: '" + artifactId +
+ "' which was configured for use in this project does not have a version associated with it."; "' which was configured for use in this project does not have a version associated with it.";
throw new IllegalStateException( message ); throw new IllegalStateException( message );
} }
else else
@ -247,14 +247,13 @@ public class DefaultPluginManager
} }
catch ( ArtifactEnabledContainerException e ) catch ( ArtifactEnabledContainerException e )
{ {
throw new PluginManagerException( throw new PluginManagerException( "Error occurred in the artifact container attempting to download plugin " +
"Error occurred in the artifact container attempting to download plugin " groupId + ":" + artifactId, e );
+ groupId + ":" + artifactId, e );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) &&
&& version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) ) version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
{ {
throw new PluginNotFoundException( groupId, artifactId, version, e ); throw new PluginNotFoundException( groupId, artifactId, version, e );
} }
@ -265,8 +264,8 @@ public class DefaultPluginManager
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":" throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":" +
+ artifactId, e ); artifactId, e );
} }
} }
} }
@ -285,8 +284,10 @@ public class DefaultPluginManager
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder ); MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact, artifactResolver, session ( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact, artifactResolver,
.getPluginRepositories(), session.getLocalRepository(), metadataSource, artifactFilter ); session.getPluginRepositories(),
session.getLocalRepository(), metadataSource,
artifactFilter );
} }
finally finally
{ {
@ -333,8 +334,8 @@ public class DefaultPluginManager
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE ); artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE ); mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder, mojoDescriptor resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder,
.getRequiresDependencyResolution() ); mojoDescriptor.getRequiresDependencyResolution() );
downloadDependencies( session, artifactResolver ); downloadDependencies( session, artifactResolver );
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
@ -396,23 +397,23 @@ public class DefaultPluginManager
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator ); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator );
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, mojoDescriptor PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
.getConfiguration() ); mojoDescriptor.getConfiguration() );
try try
{ {
if ( newMojoTechnique ) if ( newMojoTechnique )
{ {
Map map = getPluginConfigurationFromExpressions( mojoDescriptor, mergedConfiguration, Map map = getPluginConfigurationFromExpressions( plugin, mojoDescriptor, mergedConfiguration,
expressionEvaluator ); expressionEvaluator );
populatePluginFields( plugin, pomConfiguration, map, expressionEvaluator ); populatePluginFields( plugin, pomConfiguration, expressionEvaluator );
} }
else else
{ {
getLogger().warn( "WARNING: The mojo " + mojoDescriptor.getId() + " is using the OLD API" ); getLogger().warn( "WARNING: The mojo " + mojoDescriptor.getId() + " is using the OLD API" );
Map map = getPluginConfigurationFromExpressions( mojoDescriptor, mergedConfiguration, Map map = getPluginConfigurationFromExpressions( plugin, mojoDescriptor, mergedConfiguration,
expressionEvaluator ); expressionEvaluator );
request = createPluginRequest( pomConfiguration, map ); request = createPluginRequest( pomConfiguration, map );
@ -488,11 +489,11 @@ public class DefaultPluginManager
} }
// Make sure the parameter is either editable/configurable, or else is NOT specified in the POM // Make sure the parameter is either editable/configurable, or else is NOT specified in the POM
if ( !editable if ( !editable && ( pomConfiguration.getChild( lookupKey, false ) != null ||
&& ( pomConfiguration.getChild( lookupKey, false ) != null || pomConfiguration.getChild( key, false ) != null ) ) pomConfiguration.getChild( key, false ) != null ) )
{ {
StringBuffer errorMessage = new StringBuffer().append( "ERROR: Cannot override read-only parameter: " ) StringBuffer errorMessage = new StringBuffer().append( "ERROR: Cannot override read-only parameter: " ).append(
.append( key ); key );
if ( !lookupKey.equals( key ) ) if ( !lookupKey.equals( key ) )
{ {
@ -595,7 +596,7 @@ public class DefaultPluginManager
return new MojoExecutionRequest( map ); return new MojoExecutionRequest( map );
} }
private void populatePluginFields( Mojo plugin, PlexusConfiguration configuration, Map map, private void populatePluginFields( Mojo plugin, PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator ) ExpressionEvaluator expressionEvaluator )
throws PluginConfigurationException throws PluginConfigurationException
{ {
@ -607,49 +608,6 @@ public class DefaultPluginManager
{ {
throw new PluginConfigurationException( "Unable to parse the created DOM for plugin configuration", e ); throw new PluginConfigurationException( "Unable to parse the created DOM for plugin configuration", e );
} }
// Configuration does not store objects, so the non-String fields are configured here
// TODO: remove - this is for plugins built with alpha-1
for ( Iterator i = map.keySet().iterator(); i.hasNext(); )
{
String key = (String) i.next();
if ( configuration.getChild( key, false ) != null )
{
continue;
}
Object value = map.get( key );
if ( value != null )
{
Class clazz = plugin.getClass();
try
{
Field f = findPluginField( clazz, key );
boolean accessible = f.isAccessible();
if ( !accessible )
{
f.setAccessible( true );
}
f.set( plugin, value );
if ( !accessible )
{
f.setAccessible( false );
}
}
catch ( NoSuchFieldException e )
{
throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'", e );
}
catch ( IllegalAccessException e )
{
throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'", e );
}
}
}
} }
private Field findPluginField( Class clazz, String key ) private Field findPluginField( Class clazz, String key )
@ -676,7 +634,8 @@ public class DefaultPluginManager
/** /**
* @deprecated [JC] in favor of what? * @deprecated [JC] in favor of what?
*/ */
private Map getPluginConfigurationFromExpressions( MojoDescriptor goal, PlexusConfiguration mergedConfiguration, private Map getPluginConfigurationFromExpressions( Mojo plugin, MojoDescriptor goal,
PlexusConfiguration mergedConfiguration,
ExpressionEvaluator expressionEvaluator ) ExpressionEvaluator expressionEvaluator )
throws ExpressionEvaluationException, PluginConfigurationException throws ExpressionEvaluationException, PluginConfigurationException
{ {
@ -724,8 +683,8 @@ public class DefaultPluginManager
{ {
PlexusConfiguration goalConfiguration = goal.getConfiguration(); PlexusConfiguration goalConfiguration = goal.getConfiguration();
if ( !expression.equals( goalConfiguration.getChild( lookupKey, false ).getValue( null ) ) if ( !expression.equals( goalConfiguration.getChild( lookupKey, false ).getValue( null ) ) &&
&& !expression.equals( goalConfiguration.getChild( key, false ).getValue( null ) ) ) !expression.equals( goalConfiguration.getChild( key, false ).getValue( null ) ) )
{ {
StringBuffer message = new StringBuffer().append( "DEPRECATED: " ).append( key ); StringBuffer message = new StringBuffer().append( "DEPRECATED: " ).append( key );
@ -744,11 +703,38 @@ public class DefaultPluginManager
getLogger().debug( "Evaluated mojo parameter expression: \'" + expression + "\' to: " + value ); getLogger().debug( "Evaluated mojo parameter expression: \'" + expression + "\' to: " + value );
// TODO: remove. If there is a default value, required should have been removed by the descriptor generator
if ( value == null ) if ( value == null )
{ {
if ( parameter.getDefaultValue() != null ) Object defaultValue;
try
{ {
value = expressionEvaluator.evaluate( parameter.getDefaultValue() ); Field pluginField = findPluginField( plugin.getClass(), parameter.getName() );
boolean accessible = pluginField.isAccessible();
if ( !accessible )
{
pluginField.setAccessible( true );
}
defaultValue = pluginField.get( plugin );
if ( !accessible )
{
pluginField.setAccessible( false );
}
}
catch ( IllegalAccessException e )
{
String message = "Error finding field for parameter '" + parameter.getName() + "'";
throw new PluginConfigurationException( message, e );
}
catch ( NoSuchFieldException e )
{
String message = "Error finding field for parameter '" + parameter.getName() + "'";
throw new PluginConfigurationException( message, e );
}
if ( defaultValue != null )
{
// TODO: allow expressions?
value = defaultValue;
} }
} }
@ -763,7 +749,8 @@ public class DefaultPluginManager
if ( value == null && parameter.isRequired() ) if ( value == null && parameter.isRequired() )
{ {
throw new PluginConfigurationException( createPluginParameterRequiredMessage( goal, parameter, expression ) ); throw new PluginConfigurationException(
createPluginParameterRequiredMessage( goal, parameter, expression ) );
} }
map.put( key, value ); map.put( key, value );
@ -771,7 +758,8 @@ public class DefaultPluginManager
return map; return map;
} }
public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter, String expression ) public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter,
String expression )
{ {
StringBuffer message = new StringBuffer(); StringBuffer message = new StringBuffer();
@ -798,20 +786,11 @@ public class DefaultPluginManager
{ {
// TODO: configure this from bootstrap or scan lib // TODO: configure this from bootstrap or scan lib
// TODO: Note: maven-plugin just re-added until all plugins are switched over... // TODO: Note: maven-plugin just re-added until all plugins are switched over...
artifactFilter = new ExclusionSetFilter( new String[] { artifactFilter = new ExclusionSetFilter( new String[]{"maven-core", "maven-artifact", "maven-model",
"maven-core", "maven-settings", "maven-monitor", "maven-plugin-api",
"maven-artifact", "maven-plugin-descriptor", "plexus-container-default",
"maven-model", "maven-project", "plexus-container-artifact",
"maven-settings", "wagon-provider-api", "classworlds", "maven-plugin"} );
"maven-monitor",
"maven-plugin-api",
"maven-plugin-descriptor",
"plexus-container-default",
"maven-project",
"plexus-container-artifact",
"wagon-provider-api",
"classworlds",
"maven-plugin" } );
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -830,8 +809,10 @@ public class DefaultPluginManager
boolean systemOnline = !context.getSettings().getActiveProfile().isOffline(); boolean systemOnline = !context.getSettings().getActiveProfile().isOffline();
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), context ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
.getRemoteRepositories(), context.getLocalRepository(), sourceReader, filter ); context.getRemoteRepositories(),
context.getLocalRepository(),
sourceReader, filter );
project.addArtifacts( result.getArtifacts().values(), artifactFactory ); project.addArtifacts( result.getArtifacts().values(), artifactFactory );
} }