[MNG-6090] CI friendly properties break submodule builds

[MNG-6057] Problem with CI friendly usage of ${..} reactor order is changed
 o Based on the missing replacement of the versions ${revision}
   ${changelist} or ${sha1} within the parent element the order
   of the reactor changes.
[MNG-5895] Problem with CI friendly usage of ${..} which is already
defined via property in pom file.
This commit is contained in:
Karl Heinz Marbaise 2015-09-29 11:46:48 +02:00
parent 181b0215aa
commit 51cc76c326
4 changed files with 59 additions and 6 deletions

View File

@ -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;
}

View File

@ -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<String, Activation> 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,

View File

@ -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<String> PROJECT_PREFIXES = Arrays.asList( "pom.", "project." );
private static final Collection<String> 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() ) );

View File

@ -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;
}