o Revised error handling

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@807736 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-25 18:03:51 +00:00
parent 8b381cdbd6
commit 4b904e1005
5 changed files with 95 additions and 55 deletions

View File

@ -1310,7 +1310,7 @@ public class DefaultLifecycleExecutor
}
}
private void populateDefaultConfigurationForPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
public void populateDefaultConfigurationForPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException
{
if ( plugin.getVersion() == null )
@ -1325,16 +1325,59 @@ public class DefaultLifecycleExecutor
}
}
for( PluginExecution pluginExecution : plugin.getExecutions() )
try
{
for( String goal : pluginExecution.getGoals() )
// NOTE: Retrieve the plugin descriptor regardless whether there are any executions to verify the plugin
PluginDescriptor pluginDescriptor = pluginManager.loadPlugin( plugin, repositoryRequest );
for ( PluginExecution pluginExecution : plugin.getExecutions() )
{
Xpp3Dom dom = getDefaultPluginConfiguration( plugin, goal, repositoryRequest );
pluginExecution.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) pluginExecution.getConfiguration(), dom, Boolean.TRUE ) );
for ( String goal : pluginExecution.getGoals() )
{
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
if ( mojoDescriptor == null )
{
throw new MojoNotFoundException( goal, pluginDescriptor );
}
Xpp3Dom defaultConfiguration = getMojoConfiguration( mojoDescriptor );
Xpp3Dom executionConfiguration =
Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) pluginExecution.getConfiguration(), defaultConfiguration,
Boolean.TRUE );
pluginExecution.setConfiguration( executionConfiguration );
}
}
}
catch ( PluginNotFoundException e )
{
throw new LifecycleExecutionException( "Error getting plugin information for " + plugin.getId() + ": "
+ e.getMessage(), e );
}
catch ( PluginResolutionException e )
{
throw new LifecycleExecutionException( "Error getting plugin information for " + plugin.getId() + ": "
+ e.getMessage(), e );
}
catch ( PluginDescriptorParsingException e )
{
throw new LifecycleExecutionException( "Error getting plugin information for " + plugin.getId() + ": "
+ e.getMessage(), e );
}
catch ( MojoNotFoundException e )
{
throw new LifecycleExecutionException( "Error getting plugin information for " + plugin.getId() + ": "
+ e.getMessage(), e );
}
catch ( InvalidPluginDescriptorException e )
{
throw new LifecycleExecutionException( "Error getting plugin information for " + plugin.getId() + ": "
+ e.getMessage(), e );
}
}
public void populateDefaultConfigurationForPlugins( Collection<Plugin> plugins, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException
{
@ -1343,40 +1386,7 @@ public class DefaultLifecycleExecutor
populateDefaultConfigurationForPlugin( plugin, repositoryRequest );
}
}
private Xpp3Dom getDefaultPluginConfiguration( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException
{
MojoDescriptor mojoDescriptor;
try
{
mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, repositoryRequest );
}
catch ( PluginNotFoundException e )
{
throw new LifecycleExecutionException( "Error getting default plugin information for " + plugin.getId(), e );
}
catch ( PluginResolutionException e )
{
throw new LifecycleExecutionException( "Error getting default plugin information for " + plugin.getId(), e );
}
catch ( PluginDescriptorParsingException e )
{
throw new LifecycleExecutionException( "Error getting default plugin information for " + plugin.getId(), e );
}
catch ( MojoNotFoundException e )
{
throw new LifecycleExecutionException( "Error getting default plugin information for " + plugin.getId(), e );
}
catch ( InvalidPluginDescriptorException e )
{
throw new LifecycleExecutionException( "Error getting default plugin information for " + plugin.getId(), e );
}
return getMojoConfiguration( mojoDescriptor );
}
public Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor )
{
return convert( mojoDescriptor );

View File

@ -74,6 +74,9 @@ public interface LifecycleExecutor
//
void populateDefaultConfigurationForPlugins( Collection<Plugin> plugins, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException;
void populateDefaultConfigurationForPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException;
void execute( MavenSession session );
}

View File

@ -33,6 +33,7 @@ import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.DefaultModelBuildingRequest;
import org.apache.maven.model.building.DefaultModelProblem;
@ -127,23 +128,32 @@ public class DefaultProjectBuilder
project = toProject( result, configuration, listener );
}
try
if ( configuration.isProcessPlugins() && configuration.isProcessPluginConfiguration() )
{
if ( configuration.isProcessPlugins() && configuration.isProcessPluginConfiguration() )
RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
repositoryRequest.setLocalRepository( configuration.getLocalRepository() );
repositoryRequest.setRemoteRepositories( project.getPluginArtifactRepositories() );
repositoryRequest.setCache( configuration.getRepositoryCache() );
repositoryRequest.setOffline( configuration.isOffline() );
for ( Plugin plugin : project.getBuildPlugins() )
{
RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
repositoryRequest.setLocalRepository( configuration.getLocalRepository() );
repositoryRequest.setRemoteRepositories( project.getPluginArtifactRepositories() );
repositoryRequest.setCache( configuration.getRepositoryCache() );
repositoryRequest.setOffline( configuration.isOffline() );
lifecycle.populateDefaultConfigurationForPlugins( project.getModel().getBuild().getPlugins(), repositoryRequest );
try
{
lifecycle.populateDefaultConfigurationForPlugin( plugin, repositoryRequest );
}
catch ( LifecycleExecutionException e )
{
if ( modelProblems == null )
{
modelProblems = new ArrayList<ModelProblem>();
}
modelProblems.add( new DefaultModelProblem( e.getMessage(), ModelProblem.Severity.WARNING,
project.getModel(), e ) );
}
}
}
catch ( LifecycleExecutionException e )
{
throw new ProjectBuildingException( project.getId(), e.getMessage(), e );
}
ArtifactResolutionResult artifactResult = null;
@ -461,7 +471,6 @@ public class DefaultProjectBuilder
private MavenProject toProject( ModelBuildingResult result, ProjectBuildingRequest configuration,
DefaultModelBuildingListener listener )
throws ProjectBuildingException
{
Model model = result.getEffectiveModel();

View File

@ -111,6 +111,11 @@ public class EmptyLifecycleExecutor
{
}
public void populateDefaultConfigurationForPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException
{
}
public void resolvePluginVersion( Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginNotFoundException
{

View File

@ -49,7 +49,20 @@ public class DefaultModelProblem
*/
public DefaultModelProblem( String message, Severity severity, Model source )
{
this( message, severity, ModelProblemUtils.toSourceHint( source ), null );
this( message, severity, source, null );
}
/**
* Creates a new problem with the specified message and exception.
*
* @param message The message describing the problem, may be {@code null}.
* @param severity The severity level of the problem, may be {@code null} to default to {@link Severity#ERROR}.
* @param source The source of the problem, may be {@code null}.
* @param exception The exception that caused this problem, may be {@code null}.
*/
public DefaultModelProblem( String message, Severity severity, Model source, Exception exception )
{
this( message, severity, ModelProblemUtils.toSourceHint( source ), exception );
}
/**