o Refactored model building listener to use problem collector

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@800418 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-03 15:13:46 +00:00
parent 5e36879dd4
commit 975ac84b45
6 changed files with 53 additions and 27 deletions

View File

@ -21,7 +21,9 @@ package org.apache.maven.project;
import java.util.List;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.AbstractModelBuildingListener;
import org.apache.maven.model.building.ModelBuildingEvent;
@ -104,21 +106,41 @@ class DefaultModelBuildingListener
@Override
public void buildExtensionsAssembled( ModelBuildingEvent event )
throws Exception
{
Model model = event.getModel();
try
{
remoteRepositories =
projectBuildingHelper.createArtifactRepositories( model.getRepositories(), remoteRepositories );
}
catch ( InvalidRepositoryException e )
{
event.getProblems().addError( "Invalid artifact repository: " + e.getMessage(), e );
}
try
{
pluginRepositories =
projectBuildingHelper.createArtifactRepositories( model.getPluginRepositories(), pluginRepositories );
}
catch ( InvalidRepositoryException e )
{
event.getProblems().addError( "Invalid plugin repository: " + e.getMessage(), e );
}
if ( event.getRequest().isProcessPlugins() )
{
try
{
projectRealm =
projectBuildingHelper.createProjectRealm( model, projectBuildingRequest.getLocalRepository(),
pluginRepositories );
}
catch ( ArtifactResolutionException e )
{
event.getProblems().addError( "Unresolveable build extensions: " + e.getMessage(), e );
}
if ( projectRealm != null )
{

View File

@ -29,7 +29,6 @@ public class AbstractModelBuildingListener
{
public void buildExtensionsAssembled( ModelBuildingEvent event )
throws Exception
{
// default does nothing
}

View File

@ -718,19 +718,12 @@ public class DefaultModelBuilder
return;
}
ModelBuildingEvent event = new DefaultModelBuildingEvent( model, request );
ModelBuildingEvent event = new DefaultModelBuildingEvent( model, request, problems );
for ( ModelBuildingListener listener : request.getModelBuildingListeners() )
{
try
{
listener.buildExtensionsAssembled( event );
}
catch ( Exception e )
{
problems.addError( "Invalid build extensions: " + e.getMessage(), e );
}
}
}
}

View File

@ -34,10 +34,13 @@ class DefaultModelBuildingEvent
private final ModelBuildingRequest request;
public DefaultModelBuildingEvent( Model model, ModelBuildingRequest request )
private final ModelProblemCollector problems;
public DefaultModelBuildingEvent( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
{
this.model = model;
this.request = request;
this.problems = problems;
}
public Model getModel()
@ -50,4 +53,9 @@ class DefaultModelBuildingEvent
return request;
}
public ModelProblemCollector getProblems()
{
return problems;
}
}

View File

@ -30,17 +30,24 @@ public interface ModelBuildingEvent
{
/**
* The model being built. The precise state of this model depends on the event being fired.
* Gets the model being built. The precise state of this model depends on the event being fired.
*
* @return The model being built, never {@code null}.
*/
Model getModel();
/**
* The model building request being processed.
* Gets the model building request being processed.
*
* @return The model building request being processed, never {@code null}.
*/
ModelBuildingRequest getRequest();
/**
* Gets the container used to collect problems that were encountered while processing the event.
*
* @return The container used to collect problems that were encountered, never {@code null}.
*/
ModelProblemCollector getProblems();
}

View File

@ -20,9 +20,8 @@ package org.apache.maven.model.building;
*/
/**
* Defines events that the model builder fires during construction of the effective model. Unless otherwise noted, an
* exception thrown by the listener during processing of the event will be treated as a fatal error and aborts building
* of the corresponding model.
* Defines events that the model builder fires during construction of the effective model. When a listener encounteres
* errors while processing the event, it can report these problems via {@link ModelBuildingEvent#getProblems()}.
*
* @author Benjamin Bentmann
*/
@ -33,9 +32,7 @@ public interface ModelBuildingListener
* Notifies the listener that the model has been constructed to the extent where build extensions can be processed.
*
* @param event The details about the event.
* @throws Exception If the listener encountered an error.
*/
void buildExtensionsAssembled( ModelBuildingEvent event )
throws Exception;
void buildExtensionsAssembled( ModelBuildingEvent event );
}