o Gave each model diddling component access to the building request to easy future extensions

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@781133 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-02 19:31:34 +00:00
parent a47090cd84
commit 7a2d55b8d1
16 changed files with 55 additions and 36 deletions

View File

@ -125,7 +125,7 @@ public class DefaultModelBuilder
Model rawModel = ModelUtils.cloneModel( current ); Model rawModel = ModelUtils.cloneModel( current );
rawModels.add( rawModel ); rawModels.add( rawModel );
modelNormalizer.mergeDuplicates( resultModel ); modelNormalizer.mergeDuplicates( resultModel, request );
List<Profile> activeProjectProfiles = getActiveProjectProfiles( rawModel, request ); List<Profile> activeProjectProfiles = getActiveProjectProfiles( rawModel, request );
@ -139,7 +139,7 @@ public class DefaultModelBuilder
for ( Profile activeProfile : activeProfiles ) for ( Profile activeProfile : activeProfiles )
{ {
profileInjector.injectProfile( resultModel, activeProfile ); profileInjector.injectProfile( resultModel, activeProfile, request );
} }
result.setActiveProfiles( rawModel, activeProfiles ); result.setActiveProfiles( rawModel, activeProfiles );
@ -153,25 +153,25 @@ public class DefaultModelBuilder
result.setRawModels( rawModels ); result.setRawModels( rawModels );
assembleInheritance( resultModels ); assembleInheritance( resultModels, request );
Model resultModel = resultModels.get( 0 ); Model resultModel = resultModels.get( 0 );
resultModel = interpolateModel( resultModel, request ); resultModel = interpolateModel( resultModel, request );
resultModels.set( 0, resultModel ); resultModels.set( 0, resultModel );
modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory() ); modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );
if ( request.isProcessPlugins() ) if ( request.isProcessPlugins() )
{ {
lifecycleBindingsInjector.injectLifecycleBindings( resultModel ); lifecycleBindingsInjector.injectLifecycleBindings( resultModel );
} }
managementInjector.injectManagement( resultModel ); managementInjector.injectManagement( resultModel, request );
if ( request.isProcessPlugins() ) if ( request.isProcessPlugins() )
{ {
pluginConfigurationExpander.expandPluginConfiguration( resultModel ); pluginConfigurationExpander.expandPluginConfiguration( resultModel, request );
} }
validateModel( resultModel, false, request ); validateModel( resultModel, false, request );
@ -215,11 +215,11 @@ public class DefaultModelBuilder
if ( raw ) if ( raw )
{ {
result = modelValidator.validateRawModel( model, request.istLenientValidation() ); result = modelValidator.validateRawModel( model, request );
} }
else else
{ {
result = modelValidator.validateEffectiveModel( model, request.istLenientValidation() ); result = modelValidator.validateEffectiveModel( model, request );
} }
if ( result.getMessageCount() > 0 ) if ( result.getMessageCount() > 0 )
@ -273,13 +273,13 @@ public class DefaultModelBuilder
} }
} }
private void assembleInheritance( List<Model> models ) private void assembleInheritance( List<Model> models, ModelBuildingRequest request )
{ {
for ( int i = models.size() - 2; i >= 0; i-- ) for ( int i = models.size() - 2; i >= 0; i-- )
{ {
Model parent = models.get( i + 1 ); Model parent = models.get( i + 1 );
Model child = models.get( i ); Model child = models.get( i );
inheritanceAssembler.assembleModelInheritance( child, parent ); inheritanceAssembler.assembleModelInheritance( child, parent, request );
} }
} }

View File

@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.merge.MavenModelMerger; import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@ -38,7 +39,7 @@ public class DefaultInheritanceAssembler
private MavenModelMerger merger = new MavenModelMerger(); private MavenModelMerger merger = new MavenModelMerger();
public void assembleModelInheritance( Model child, Model parent ) public void assembleModelInheritance( Model child, Model parent, ModelBuildingRequest request )
{ {
Map<Object, Object> hints = new HashMap<Object, Object>(); Map<Object, Object> hints = new HashMap<Object, Object>();
hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT, getChildPathAdjustment( child, parent ) ); hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT, getChildPathAdjustment( child, parent ) );

View File

@ -20,6 +20,7 @@ package org.apache.maven.model.inheritance;
*/ */
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
/** /**
* Handles inheritance of model values. * Handles inheritance of model values.
@ -35,7 +36,8 @@ public interface InheritanceAssembler
* @param child The child model into which to merge the values inherited from the parent, must not be * @param child The child model into which to merge the values inherited from the parent, must not be
* <code>null</code>. * <code>null</code>.
* @param parent The (read-only) parent model from which to inherit the values, may be <code>null</code>. * @param parent The (read-only) parent model from which to inherit the values, may be <code>null</code>.
* @param request The model building request that holds further settings, must not be {@code null}.
*/ */
void assembleModelInheritance( Model child, Model parent ); void assembleModelInheritance( Model child, Model parent, ModelBuildingRequest request );
} }

View File

@ -32,6 +32,7 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Exclusion; import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer; import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginExecution;
@ -51,7 +52,7 @@ public class DefaultManagementInjector
private ManagementModelMerger merger = new ManagementModelMerger(); private ManagementModelMerger merger = new ManagementModelMerger();
public void injectManagement( Model model ) public void injectManagement( Model model, ModelBuildingRequest request )
{ {
merger.mergeManagedDependencies( model ); merger.mergeManagedDependencies( model );
merger.mergeManagedBuildPlugins( model ); merger.mergeManagedBuildPlugins( model );

View File

@ -20,6 +20,7 @@ package org.apache.maven.model.management;
*/ */
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
/** /**
* Handles injection of plugin/dependency management into the model. * Handles injection of plugin/dependency management into the model.
@ -34,7 +35,8 @@ public interface ManagementInjector
* *
* @param child The model into which to merge the values specified by its management sections, must not be * @param child The model into which to merge the values specified by its management sections, must not be
* <code>null</code>. * <code>null</code>.
* @param request The model building request that holds further settings, must not be {@code null}.
*/ */
void injectManagement( Model child ); void injectManagement( Model child, ModelBuildingRequest request );
} }

View File

@ -27,6 +27,7 @@ import java.util.Map;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.merge.MavenModelMerger; import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@ -43,7 +44,7 @@ public class DefaultModelNormalizer
private DuplicateMerger merger = new DuplicateMerger(); private DuplicateMerger merger = new DuplicateMerger();
public void mergeDuplicates( Model model ) public void mergeDuplicates( Model model, ModelBuildingRequest request )
{ {
Build build = model.getBuild(); Build build = model.getBuild();
if ( build != null ) if ( build != null )

View File

@ -20,6 +20,7 @@ package org.apache.maven.model.normalization;
*/ */
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
/** /**
* Handles normalization of a model. * Handles normalization of a model.
@ -33,7 +34,8 @@ public interface ModelNormalizer
* Merges duplicate elements like multiple declarations of the same build plugin in the specified model. * Merges duplicate elements like multiple declarations of the same build plugin in the specified model.
* *
* @param model The model whose duplicate elements should be merged, must not be <code>null</code>. * @param model The model whose duplicate elements should be merged, must not be <code>null</code>.
* @param request The model building request that holds further settings, must not be {@code null}.
*/ */
void mergeDuplicates( Model model ); void mergeDuplicates( Model model, ModelBuildingRequest request );
} }

View File

@ -25,6 +25,7 @@ import java.util.List;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Reporting; import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource; import org.apache.maven.model.Resource;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@ -43,7 +44,7 @@ public class DefaultModelPathTranslator
@Requirement @Requirement
private PathTranslator pathTranslator; private PathTranslator pathTranslator;
public void alignToBaseDirectory( Model model, File basedir ) public void alignToBaseDirectory( Model model, File basedir, ModelBuildingRequest request )
{ {
if ( model == null || basedir == null ) if ( model == null || basedir == null )
{ {

View File

@ -22,6 +22,7 @@ package org.apache.maven.model.path;
import java.io.File; import java.io.File;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
/** /**
* Resolves relative paths of a model against a specific base directory. * Resolves relative paths of a model against a specific base directory.
@ -37,7 +38,8 @@ public interface ModelPathTranslator
* *
* @param model The model whose paths should be resolved, may be {@code null}. * @param model The model whose paths should be resolved, may be {@code null}.
* @param basedir The base directory to resolve relative paths against, may be {@code null}. * @param basedir The base directory to resolve relative paths against, may be {@code null}.
* @param request The model building request that holds further settings, must not be {@code null}.
*/ */
void alignToBaseDirectory( Model model, File basedir ); void alignToBaseDirectory( Model model, File basedir, ModelBuildingRequest request );
} }

View File

@ -21,6 +21,7 @@ package org.apache.maven.model.plugin;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportPlugin;
@ -39,7 +40,7 @@ public class DefaultPluginConfigurationExpander
implements PluginConfigurationExpander implements PluginConfigurationExpander
{ {
public void expandPluginConfiguration( Model model ) public void expandPluginConfiguration( Model model, ModelBuildingRequest request )
{ {
Build build = model.getBuild(); Build build = model.getBuild();
Reporting reporting = model.getReporting(); Reporting reporting = model.getReporting();

View File

@ -20,6 +20,7 @@ package org.apache.maven.model.plugin;
*/ */
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
/** /**
* Handles expansion of general plugin configuration into individual executions and report sets. * Handles expansion of general plugin configuration into individual executions and report sets.
@ -34,7 +35,8 @@ public interface PluginConfigurationExpander
* given model. * given model.
* *
* @param model The model whose plugin configuration should be expanded, must not be <code>null</code>. * @param model The model whose plugin configuration should be expanded, must not be <code>null</code>.
* @param request The model building request that holds further settings, must not be {@code null}.
*/ */
void expandPluginConfiguration( Model model ); void expandPluginConfiguration( Model model, ModelBuildingRequest request );
} }

View File

@ -25,6 +25,7 @@ import org.apache.maven.model.Build;
import org.apache.maven.model.BuildBase; import org.apache.maven.model.BuildBase;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBase; import org.apache.maven.model.ModelBase;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.model.merge.MavenModelMerger; import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@ -41,7 +42,7 @@ public class DefaultProfileInjector
private ProfileModelMerger merger = new ProfileModelMerger(); private ProfileModelMerger merger = new ProfileModelMerger();
public void injectProfile( Model model, Profile profile ) public void injectProfile( Model model, Profile profile, ModelBuildingRequest request )
{ {
if ( profile != null ) if ( profile != null )
{ {

View File

@ -20,6 +20,7 @@ package org.apache.maven.model.profile;
*/ */
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
/** /**
@ -35,7 +36,8 @@ public interface ProfileInjector
* *
* @param model The model into which to merge the values defined by the profile, must not be <code>null</code>. * @param model The model into which to merge the values defined by the profile, must not be <code>null</code>.
* @param profile The (read-only) profile whose values should be injected, may be <code>null</code>. * @param profile The (read-only) profile whose values should be injected, may be <code>null</code>.
* @param request The model building request that holds further settings, must not be {@code null}.
*/ */
void injectProfile( Model model, Profile profile ); void injectProfile( Model model, Profile profile, ModelBuildingRequest request );
} }

View File

@ -26,6 +26,7 @@ import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Parent; import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportPlugin;
@ -46,7 +47,7 @@ public class DefaultModelValidator
private static final String ID_REGEX = "[A-Za-z0-9_\\-.]+"; private static final String ID_REGEX = "[A-Za-z0-9_\\-.]+";
public ModelValidationResult validateRawModel( Model model, boolean lenient ) public ModelValidationResult validateRawModel( Model model, ModelBuildingRequest request )
{ {
ModelValidationResult result = new ModelValidationResult(); ModelValidationResult result = new ModelValidationResult();
@ -71,7 +72,7 @@ public class DefaultModelValidator
return result; return result;
} }
public ModelValidationResult validateEffectiveModel( Model model, boolean lenient ) public ModelValidationResult validateEffectiveModel( Model model, ModelBuildingRequest request )
{ {
ModelValidationResult result = new ModelValidationResult(); ModelValidationResult result = new ModelValidationResult();
@ -173,7 +174,7 @@ public class DefaultModelValidator
} }
} }
if ( !lenient ) if ( !request.istLenientValidation() )
{ {
Build build = model.getBuild(); Build build = model.getBuild();
if ( build != null ) if ( build != null )

View File

@ -20,6 +20,7 @@ package org.apache.maven.model.validation;
*/ */
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
/** /**
* Checks the model for missing or invalid values. * Checks the model for missing or invalid values.
@ -35,23 +36,19 @@ public interface ModelValidator
* file and has not been subjected to inheritance, interpolation or profile/default injection. * file and has not been subjected to inheritance, interpolation or profile/default injection.
* *
* @param model The model to validate, must not be {@code null}. * @param model The model to validate, must not be {@code null}.
* @param lenient A flag whether validation should be lenient instead of strict. For building of projects, strict * @param request The model building request that holds further settings, must not be {@code null}.
* validation should be used to ensure proper building. For the mere retrievel of dependencies during
* artifact resolution, lenient validation should be used to account for models of poor quality.
* @return The result of the validation, never {@code null}. * @return The result of the validation, never {@code null}.
*/ */
ModelValidationResult validateRawModel( Model model, boolean lenient ); ModelValidationResult validateRawModel( Model model, ModelBuildingRequest request );
/** /**
* Checks the specified (effective) model for missing or invalid values. The effective model is fully assembled and * Checks the specified (effective) model for missing or invalid values. The effective model is fully assembled and
* has undergone inheritance, interpolation and other model operations. * has undergone inheritance, interpolation and other model operations.
* *
* @param model The model to validate, must not be {@code null}. * @param model The model to validate, must not be {@code null}.
* @param lenient A flag whether validation should be lenient instead of strict. For building of projects, strict * @param request The model building request that holds further settings, must not be {@code null}.
* validation should be used to ensure proper building. For the mere retrievel of dependencies during
* artifact resolution, lenient validation should be used to account for models of poor quality.
* @return The result of the validation, never {@code null}. * @return The result of the validation, never {@code null}.
*/ */
ModelValidationResult validateEffectiveModel( Model model, boolean lenient ); ModelValidationResult validateEffectiveModel( Model model, ModelBuildingRequest request );
} }

View File

@ -22,7 +22,9 @@ package org.apache.maven.model.validation;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import org.apache.maven.model.DefaultModelBuildingRequest;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
@ -54,13 +56,14 @@ public class DefaultModelValidatorTest
private ModelValidationResult validate( String pom, boolean raw, boolean lenient ) private ModelValidationResult validate( String pom, boolean raw, boolean lenient )
throws Exception throws Exception
{ {
ModelBuildingRequest request = new DefaultModelBuildingRequest().setLenientValidation( lenient );
if ( raw ) if ( raw )
{ {
return validator.validateRawModel( read( pom ), lenient ); return validator.validateRawModel( read( pom ), request );
} }
else else
{ {
return validator.validateEffectiveModel( read( pom ), lenient ); return validator.validateEffectiveModel( read( pom ), request );
} }
} }