o Consolidated all inputs of the model builder in the building request

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@793891 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-07-14 12:54:16 +00:00
parent 42340c1b92
commit 1759fb3979
5 changed files with 101 additions and 50 deletions

View File

@ -91,6 +91,15 @@ public class DefaultProjectBuilder
DefaultModelBuildingListener listener = new DefaultModelBuildingListener( projectBuildingHelper, configuration );
request.setModelBuildingListeners( Arrays.asList( listener ) );
if ( localProject )
{
request.setPomFile( pomFile );
}
else
{
request.setModelSource( new FileModelSource( pomFile ) );
}
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
try
@ -98,14 +107,7 @@ public class DefaultProjectBuilder
ModelBuildingResult result;
try
{
if ( localProject )
{
result = modelBuilder.build( pomFile, request );
}
else
{
result = modelBuilder.build( new FileModelSource( pomFile ), request );
}
result = modelBuilder.build( request );
}
catch ( ModelBuildingException e )
{
@ -254,10 +256,12 @@ public class DefaultProjectBuilder
{
ModelBuildingRequest request = getModelBuildingRequest( config );
request.setModelSource( new UrlModelSource( getClass().getResource( "standalone.xml" ) ) );
ModelBuildingResult result;
try
{
result = modelBuilder.build( new UrlModelSource( getClass().getResource( "standalone.xml" ) ), request );
result = modelBuilder.build( request );
}
catch ( ModelBuildingException e )
{

View File

@ -103,30 +103,18 @@ public class DefaultModelBuilder
@Requirement
private PluginConfigurationExpander pluginConfigurationExpander;
public ModelBuildingResult build( File pomFile, ModelBuildingRequest request )
throws ModelBuildingException
{
return build( new FileModelSource( pomFile ), pomFile, request );
}
public ModelBuildingResult build( ModelSource modelSource, ModelBuildingRequest request )
throws ModelBuildingException
{
return build( modelSource, null, request );
}
private ModelBuildingResult build( ModelSource modelSource, File pomFile, ModelBuildingRequest request )
public ModelBuildingResult build( ModelBuildingRequest request )
throws ModelBuildingException
{
DefaultModelBuildingResult result = new DefaultModelBuildingResult();
List<ModelProblem> problems = new ArrayList<ModelProblem>();
ProfileActivationContext profileActivationContext = getProfileActivationContext( pomFile, request );
ProfileActivationContext profileActivationContext = getProfileActivationContext( request );
List<Profile> activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext, problems );
Model inputModel = readModel( modelSource, pomFile, request, problems );
Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );
ModelData resultData = new ModelData( inputModel );
@ -234,6 +222,18 @@ public class DefaultModelBuilder
{
Model model;
if ( modelSource == null )
{
if ( pomFile != null )
{
modelSource = new FileModelSource( pomFile );
}
else
{
throw new IllegalArgumentException( "neither model source nor input file are specified" );
}
}
try
{
boolean strict = request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0;
@ -300,14 +300,14 @@ public class DefaultModelBuilder
}
}
private ProfileActivationContext getProfileActivationContext( File pomFile, ModelBuildingRequest request )
private ProfileActivationContext getProfileActivationContext( ModelBuildingRequest request )
{
ProfileActivationContext context = new DefaultProfileActivationContext();
context.setActiveProfileIds( request.getActiveProfileIds() );
context.setInactiveProfileIds( request.getInactiveProfileIds() );
context.setExecutionProperties( request.getExecutionProperties() );
context.setProjectDirectory( ( pomFile != null ) ? pomFile.getParentFile() : null );
context.setProjectDirectory( ( request.getPomFile() != null ) ? request.getPomFile().getParentFile() : null );
return context;
}
@ -438,7 +438,7 @@ public class DefaultModelBuilder
return null;
}
Model candidateModel = readModel( new FileModelSource( pomFile ), pomFile, request, problems );
Model candidateModel = readModel( null, pomFile, request, problems );
String groupId = candidateModel.getGroupId();
if ( groupId == null && candidateModel.getParent() != null )

View File

@ -19,6 +19,7 @@ package org.apache.maven.model.building;
* under the License.
*/
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -36,6 +37,10 @@ public class DefaultModelBuildingRequest
implements ModelBuildingRequest
{
private File pomFile;
private ModelSource modelSource;
private int validationLevel = VALIDATION_LEVEL_STRICT;
private boolean processPlugins;
@ -54,6 +59,30 @@ public class DefaultModelBuildingRequest
private List<ModelBuildingListener> modelBuildingListeners;
public File getPomFile()
{
return pomFile;
}
public DefaultModelBuildingRequest setPomFile( File pomFile )
{
this.pomFile = pomFile;
return this;
}
public ModelSource getModelSource()
{
return modelSource;
}
public DefaultModelBuildingRequest setModelSource( ModelSource modelSource )
{
this.modelSource = modelSource;
return this;
}
public int getValidationLevel()
{
return validationLevel;

View File

@ -19,10 +19,6 @@ package org.apache.maven.model.building;
* under the License.
*/
import java.io.File;
import org.apache.maven.model.resolution.ModelResolver;
/**
* Builds the effective model from a POM.
*
@ -32,29 +28,13 @@ public interface ModelBuilder
{
/**
* Builds the effective model of the specified POM file. Note that this method overload is meant to build the
* effective model for the build process of a project. Hence the effective model supports the notion of a project
* directory.
* Builds the effective model of the specified POM.
*
* @param pomFile The POM file of the project to build the effective model from, must not be {@code null}.
* @param request The model building request that holds further settings, must not be {@code null}.
* @param request The model building request that holds the parameters, must not be {@code null}.
* @return The result of the model building, never {@code null}.
* @throws ModelBuildingException If the effective model could not be built.
*/
ModelBuildingResult build( File pomFile, ModelBuildingRequest request )
throws ModelBuildingException;
/**
* Builds the effective model for the specified POM. In contrast to
* {@link #build(File, ModelBuildingRequest, ModelResolver)} the resulting model does not support the notion of a
* project directory. As a consequence, parent POMs are always resolved via the provided model resolver.
*
* @param modelSource The source of the POM, must not be {@code null}.
* @param request The model building request that holds further settings, must not be {@code null}.
* @return The result of the model building, never {@code null}.
* @throws ModelBuildingException If the effective model could not be built.
*/
ModelBuildingResult build( ModelSource modelSource, ModelBuildingRequest request )
ModelBuildingResult build( ModelBuildingRequest request )
throws ModelBuildingException;
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.model.building;
* under the License.
*/
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@ -61,6 +62,43 @@ public interface ModelBuildingRequest
*/
static final int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_0;
/**
* Gets the source of the POM to process.
*
* @return The source of the POM or {@code null} if not set.
*/
ModelSource getModelSource();
/**
* Sets the source of the POM to process. Eventually, either {@link #setModelSource(ModelSource)} or
* {@link #setPomFile(File)} must be set.
*
* @param modelSource The source of the POM to process, may be {@code null}.
* @return This request, never {@code null}.
*/
ModelBuildingRequest setModelSource( ModelSource modelSource );
/**
* Gets the POM file of the project to build.
*
* @return The POM file of the project or {@code null} if not applicable (i.e. when processing a POM from the
* repository).
*/
File getPomFile();
/**
* Sets the POM file of the project to build. Note that providing the path to a POM file via this method will make
* the model builder operate in project mode. This mode is meant for effective models that are employed during the
* build process of a local project. Hence the effective model will support the notion of a project directory. To
* build the model for a POM from the repository, use {@link #setModelSource(ModelSource)} in combination with a
* {@link FileModelSource} instead.
*
* @param pomFile The POM file of the project to build the effective model for, may be {@code null} to build the
* model of some POM from the repository.
* @return This request, never {@code null}.
*/
ModelBuildingRequest setPomFile( File pomFile );
/**
* Gets the level of validation to perform on processed models.
*