diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index fc154cb8aa..915ee725f9 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -376,7 +376,7 @@ public class DefaultArtifactResolver ArtifactFilter resolutionFilter = request.getResolutionFilter(); RepositorySystemSession session = getSession( request.getLocalRepository() ); - // TODO hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the + // TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the // workspace if ( source == null ) { @@ -506,6 +506,7 @@ public class DefaultArtifactResolver if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions() ) { + logger.info( "Failure detected." ); return result; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 4ebb033cf9..463bf1cb39 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -62,6 +62,8 @@ import org.apache.maven.model.superpom.SuperPomProvider; import org.apache.maven.model.validation.ModelValidator; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.interpolation.MapBasedValueSource; +import org.codehaus.plexus.interpolation.StringSearchInterpolator; import java.io.File; import java.io.IOException; @@ -766,13 +768,40 @@ public class DefaultModelBuilder // save profile activations before interpolation, since they are evaluated with limited scope Map originalActivations = getProfileActivations( model, true ); - Model result = modelInterpolator.interpolateModel( model, model.getProjectDirectory(), request, problems ); - result.setPomFile( model.getPomFile() ); + Model interpolatedModel = + modelInterpolator.interpolateModel( model, model.getProjectDirectory(), request, problems ); + if ( interpolatedModel.getParent() != null ) + { + StringSearchInterpolator ssi = new StringSearchInterpolator(); + ssi.addValueSource( new MapBasedValueSource( request.getUserProperties() ) ); + + ssi.addValueSource( new MapBasedValueSource( model.getProperties() ) ); + + ssi.addValueSource( new MapBasedValueSource( request.getSystemProperties() ) ); + + try + { + String interpolated = ssi.interpolate( interpolatedModel.getParent().getVersion() ); + interpolatedModel.getParent().setVersion( interpolated ); + } + catch ( Exception e ) + { + ModelProblemCollectorRequest mpcr = + new ModelProblemCollectorRequest( Severity.ERROR, + Version.BASE ).setMessage( "Failed to interpolate field: " + + interpolatedModel.getParent().getVersion() + + " on class: " ).setException( e ); + problems.add( mpcr ); + } + + + } + interpolatedModel.setPomFile( model.getPomFile() ); // restore profiles with file activation to their value before full interpolation injectProfileActivations( model, originalActivations ); - return result; + return interpolatedModel; } private ModelData readParent( Model childModel, ModelSource childSource, ModelBuildingRequest request, diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java index cee376f113..b47edbe989 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java @@ -56,6 +56,12 @@ import org.codehaus.plexus.interpolation.ValueSource; public abstract class AbstractStringBasedModelInterpolator implements ModelInterpolator { + public static final String SHA1_PROPERTY = "sha1"; + + public static final String CHANGELIST_PROPERTY = "changelist"; + + public static final String REVISION_PROPERTY = "revision"; + private static final List PROJECT_PREFIXES = Arrays.asList( "pom.", "project." ); private static final Collection TRANSLATED_PATH_EXPRESSIONS; @@ -165,6 +171,20 @@ public abstract class AbstractStringBasedModelInterpolator valueSources.add( new MapBasedValueSource( config.getUserProperties() ) ); + // Overwrite existing values in model properties. Otherwise it's not possible + // to define the version via command line: mvn -Drevision=6.5.7 ... + if ( config.getSystemProperties().containsKey( REVISION_PROPERTY ) ) + { + modelProperties.put( REVISION_PROPERTY, config.getSystemProperties().get( REVISION_PROPERTY ) ); + } + if ( config.getSystemProperties().containsKey( CHANGELIST_PROPERTY ) ) + { + modelProperties.put( CHANGELIST_PROPERTY, config.getSystemProperties().get( CHANGELIST_PROPERTY ) ); + } + if ( config.getSystemProperties().containsKey( SHA1_PROPERTY ) ) + { + modelProperties.put( SHA1_PROPERTY, config.getSystemProperties().get( SHA1_PROPERTY ) ); + } valueSources.add( new MapBasedValueSource( modelProperties ) ); valueSources.add( new MapBasedValueSource( config.getSystemProperties() ) ); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index 59b05329bf..e790f211a6 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -53,6 +53,7 @@ import org.apache.maven.model.building.ModelProblem.Severity; import org.apache.maven.model.building.ModelProblem.Version; import org.apache.maven.model.building.ModelProblemCollector; import org.apache.maven.model.building.ModelProblemCollectorRequest; +import org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.StringUtils; @@ -806,8 +807,10 @@ public class DefaultModelValidator // revision // sha1 // - if ( string.trim().contains( "${changelist}" ) || string.trim().contains( "${revision}" ) - || string.trim().contains( "${sha1}" ) ) + string = string.trim(); + if ( string.contains( "${" + AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY + "}" ) + || string.contains( "${" + AbstractStringBasedModelInterpolator.REVISION_PROPERTY + "}" ) + || string.contains( "${" + AbstractStringBasedModelInterpolator.SHA1_PROPERTY + "}" ) ) { return true; }