mirror of https://github.com/apache/maven.git
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:
parent
5e36879dd4
commit
975ac84b45
|
@ -21,7 +21,9 @@ package org.apache.maven.project;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
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.Model;
|
||||||
import org.apache.maven.model.building.AbstractModelBuildingListener;
|
import org.apache.maven.model.building.AbstractModelBuildingListener;
|
||||||
import org.apache.maven.model.building.ModelBuildingEvent;
|
import org.apache.maven.model.building.ModelBuildingEvent;
|
||||||
|
@ -104,21 +106,41 @@ class DefaultModelBuildingListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildExtensionsAssembled( ModelBuildingEvent event )
|
public void buildExtensionsAssembled( ModelBuildingEvent event )
|
||||||
throws Exception
|
|
||||||
{
|
{
|
||||||
Model model = event.getModel();
|
Model model = event.getModel();
|
||||||
|
|
||||||
remoteRepositories =
|
try
|
||||||
projectBuildingHelper.createArtifactRepositories( model.getRepositories(), remoteRepositories );
|
{
|
||||||
|
remoteRepositories =
|
||||||
|
projectBuildingHelper.createArtifactRepositories( model.getRepositories(), remoteRepositories );
|
||||||
|
}
|
||||||
|
catch ( InvalidRepositoryException e )
|
||||||
|
{
|
||||||
|
event.getProblems().addError( "Invalid artifact repository: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
|
||||||
pluginRepositories =
|
try
|
||||||
projectBuildingHelper.createArtifactRepositories( model.getPluginRepositories(), pluginRepositories );
|
{
|
||||||
|
pluginRepositories =
|
||||||
|
projectBuildingHelper.createArtifactRepositories( model.getPluginRepositories(), pluginRepositories );
|
||||||
|
}
|
||||||
|
catch ( InvalidRepositoryException e )
|
||||||
|
{
|
||||||
|
event.getProblems().addError( "Invalid plugin repository: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
|
||||||
if ( event.getRequest().isProcessPlugins() )
|
if ( event.getRequest().isProcessPlugins() )
|
||||||
{
|
{
|
||||||
projectRealm =
|
try
|
||||||
projectBuildingHelper.createProjectRealm( model, projectBuildingRequest.getLocalRepository(),
|
{
|
||||||
pluginRepositories );
|
projectRealm =
|
||||||
|
projectBuildingHelper.createProjectRealm( model, projectBuildingRequest.getLocalRepository(),
|
||||||
|
pluginRepositories );
|
||||||
|
}
|
||||||
|
catch ( ArtifactResolutionException e )
|
||||||
|
{
|
||||||
|
event.getProblems().addError( "Unresolveable build extensions: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
|
||||||
if ( projectRealm != null )
|
if ( projectRealm != null )
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,6 @@ public class AbstractModelBuildingListener
|
||||||
{
|
{
|
||||||
|
|
||||||
public void buildExtensionsAssembled( ModelBuildingEvent event )
|
public void buildExtensionsAssembled( ModelBuildingEvent event )
|
||||||
throws Exception
|
|
||||||
{
|
{
|
||||||
// default does nothing
|
// default does nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -718,18 +718,11 @@ public class DefaultModelBuilder
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelBuildingEvent event = new DefaultModelBuildingEvent( model, request );
|
ModelBuildingEvent event = new DefaultModelBuildingEvent( model, request, problems );
|
||||||
|
|
||||||
for ( ModelBuildingListener listener : request.getModelBuildingListeners() )
|
for ( ModelBuildingListener listener : request.getModelBuildingListeners() )
|
||||||
{
|
{
|
||||||
try
|
listener.buildExtensionsAssembled( event );
|
||||||
{
|
|
||||||
listener.buildExtensionsAssembled( event );
|
|
||||||
}
|
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
problems.addError( "Invalid build extensions: " + e.getMessage(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,13 @@ class DefaultModelBuildingEvent
|
||||||
|
|
||||||
private final ModelBuildingRequest request;
|
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.model = model;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
|
this.problems = problems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model getModel()
|
public Model getModel()
|
||||||
|
@ -50,4 +53,9 @@ class DefaultModelBuildingEvent
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModelProblemCollector getProblems()
|
||||||
|
{
|
||||||
|
return problems;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}.
|
* @return The model being built, never {@code null}.
|
||||||
*/
|
*/
|
||||||
Model getModel();
|
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}.
|
* @return The model building request being processed, never {@code null}.
|
||||||
*/
|
*/
|
||||||
ModelBuildingRequest getRequest();
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Defines events that the model builder fires during construction of the effective model. When a listener encounteres
|
||||||
* exception thrown by the listener during processing of the event will be treated as a fatal error and aborts building
|
* errors while processing the event, it can report these problems via {@link ModelBuildingEvent#getProblems()}.
|
||||||
* of the corresponding model.
|
|
||||||
*
|
*
|
||||||
* @author Benjamin Bentmann
|
* @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.
|
* 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.
|
* @param event The details about the event.
|
||||||
* @throws Exception If the listener encountered an error.
|
|
||||||
*/
|
*/
|
||||||
void buildExtensionsAssembled( ModelBuildingEvent event )
|
void buildExtensionsAssembled( ModelBuildingEvent event );
|
||||||
throws Exception;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue