mirror of https://github.com/apache/maven.git
Fix: mng3746 - Implemented proper ordering of system, user and model properties used in interpolation. this required creating a tag value, which could be used for comparing and ordering of InterpolatorProperty.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@695196 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5d266e85ba
commit
6221dfb9e6
|
@ -36,6 +36,7 @@ import org.apache.maven.project.MavenProjectBuilder;
|
|||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.builder.PomClassicTransformer;
|
||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||
import org.apache.maven.extension.lineage.ModelLineage;
|
||||
import org.apache.maven.extension.lineage.ModelLineageBuilder;
|
||||
import org.apache.maven.extension.lineage.ModelLineageIterator;
|
||||
|
@ -163,8 +164,10 @@ public class DefaultBuildExtensionScanner
|
|||
config.setExecutionProperties( execProps );
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(),
|
||||
PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(),
|
||||
PomInterpolatorTag.USER_PROPERTIES.name()));
|
||||
model = PomClassicTransformer.interpolateModel( model, interpolatorProperties, modelPom.getParentFile());
|
||||
|
||||
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
|
||||
|
|
|
@ -61,6 +61,7 @@ import org.apache.maven.project.MavenProjectBuilder;
|
|||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.ModelUtils;
|
||||
import org.apache.maven.project.builder.PomClassicTransformer;
|
||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.artifact.MavenMetadataSource;
|
||||
import org.apache.maven.realm.MavenRealmManager;
|
||||
|
@ -558,8 +559,10 @@ public class DefaultPluginManager
|
|||
try
|
||||
{
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getExecutionProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getExecutionProperties(),
|
||||
PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(),
|
||||
PomInterpolatorTag.USER_PROPERTIES.name()));
|
||||
String interpolatedDom =
|
||||
PomClassicTransformer.interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
|
||||
dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) );
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.maven.profiles.build.ProfileAdvisor;
|
|||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.builder.PomArtifactResolver;
|
||||
import org.apache.maven.project.builder.ProjectBuilder;
|
||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.project.validation.ModelValidator;
|
||||
import org.apache.maven.project.workspace.ProjectWorkspace;
|
||||
|
@ -532,8 +533,10 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(),
|
||||
PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(),
|
||||
PomInterpolatorTag.USER_PROPERTIES.name()));
|
||||
|
||||
MavenProject mavenProject;
|
||||
try
|
||||
|
|
|
@ -29,14 +29,7 @@ import java.io.IOException;
|
|||
import java.io.StringReader;
|
||||
import java.io.File;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Provides methods for transforming model properties into a domain model for the pom classic format and vice versa.
|
||||
|
@ -506,7 +499,7 @@ public final class PomClassicTransformer
|
|||
|
||||
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>(interpolatorProperties);
|
||||
ips.addAll(ModelTransformerContext.createInterpolatorProperties(modelProperties, ProjectUri.baseUri, aliases,
|
||||
false, false));
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false));
|
||||
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
|
@ -593,9 +586,12 @@ public final class PomClassicTransformer
|
|||
List<InterpolatorProperty> standardInterpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
if(domainModel.isPomInBuild())
|
||||
{
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty("${project.basedir}", basedir ));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty("${basedir}", basedir ));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty("${pom.basedir}", basedir ));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty("${project.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty("${basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty("${pom.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ));
|
||||
|
||||
}
|
||||
|
||||
|
@ -605,15 +601,21 @@ public final class PomClassicTransformer
|
|||
{
|
||||
String uri = mp.getUri();
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1,
|
||||
uri.length() ) + "}", mp.getValue() ) );
|
||||
uri.length() ) + "}", mp.getValue(), PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
}
|
||||
}
|
||||
|
||||
//FIRST PASS - Withhold using build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>(interpolatorProperties);
|
||||
ips1.addAll(ModelTransformerContext.createInterpolatorProperties(firstPassModelProperties, ProjectUri.baseUri, aliases,
|
||||
false, false));
|
||||
ips1.addAll(standardInterpolatorProperties);
|
||||
ips1.addAll(ModelTransformerContext.createInterpolatorProperties(firstPassModelProperties, ProjectUri.baseUri, aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false));
|
||||
Collections.sort(ips1, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
public int compare(InterpolatorProperty o, InterpolatorProperty o1) {
|
||||
return PomInterpolatorTag.valueOf(o.getTag()).compareTo(PomInterpolatorTag.valueOf(o1.getTag()));
|
||||
}
|
||||
});
|
||||
|
||||
ModelTransformerContext.interpolateModelProperties( modelProperties, ips1 );
|
||||
|
||||
|
@ -642,9 +644,16 @@ public final class PomClassicTransformer
|
|||
|
||||
//THIRD PASS - Use build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips2 = new ArrayList<InterpolatorProperty>(interpolatorProperties);
|
||||
ips2.addAll(ModelTransformerContext.createInterpolatorProperties(secondPassModelProperties, ProjectUri.baseUri, aliases,
|
||||
false, false));
|
||||
ips2.addAll(standardInterpolatorProperties);
|
||||
ips2.addAll(ModelTransformerContext.createInterpolatorProperties(secondPassModelProperties, ProjectUri.baseUri, aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false));
|
||||
ips2.addAll(interpolatorProperties);
|
||||
Collections.sort(ips2, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
public int compare(InterpolatorProperty o, InterpolatorProperty o1) {
|
||||
return PomInterpolatorTag.valueOf(o.getTag()).compareTo(PomInterpolatorTag.valueOf(o1.getTag()));
|
||||
}
|
||||
});
|
||||
|
||||
ModelTransformerContext.interpolateModelProperties( modelProperties, ips2 );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
|
||||
public enum PomInterpolatorTag
|
||||
{
|
||||
|
||||
USER_PROPERTIES,
|
||||
|
||||
PROJECT_PROPERTIES,
|
||||
|
||||
SYSTEM_PROPERTIES
|
||||
|
||||
|
||||
}
|
|
@ -36,6 +36,11 @@ public final class InterpolatorProperty
|
|||
*/
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* Metadata tag (general use)
|
||||
*/
|
||||
private String tag;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -44,6 +49,11 @@ public final class InterpolatorProperty
|
|||
* @param value the value of the property. May not be null.
|
||||
*/
|
||||
public InterpolatorProperty( String key, String value )
|
||||
{
|
||||
this(key, value, null);
|
||||
}
|
||||
|
||||
public InterpolatorProperty( String key, String value, String tag )
|
||||
{
|
||||
if ( key == null )
|
||||
{
|
||||
|
@ -56,6 +66,8 @@ public final class InterpolatorProperty
|
|||
}
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.tag = tag;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,6 +90,16 @@ public final class InterpolatorProperty
|
|||
return value;
|
||||
}
|
||||
|
||||
public String getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag)
|
||||
{
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if key values match, otherwise returns false.
|
||||
*
|
||||
|
@ -121,7 +143,7 @@ public final class InterpolatorProperty
|
|||
this.hashCode();
|
||||
}
|
||||
|
||||
public static List<InterpolatorProperty> toInterpolatorProperties( Properties properties )
|
||||
public static List<InterpolatorProperty> toInterpolatorProperties( Properties properties, String tag )
|
||||
{
|
||||
if( properties == null )
|
||||
{
|
||||
|
@ -131,7 +153,7 @@ public final class InterpolatorProperty
|
|||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
for ( Map.Entry<Object, Object> e : properties.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", (String) e.getValue()) );
|
||||
interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", (String) e.getValue(), tag) );
|
||||
}
|
||||
return interpolatorProperties;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public final class ModelTransformerContext
|
|||
public static List<InterpolatorProperty> createInterpolatorProperties(List<ModelProperty> modelProperties,
|
||||
String baseUriForModel,
|
||||
Map<String, String> aliases,
|
||||
String interpolatorTag,
|
||||
boolean includeSystemProperties,
|
||||
boolean includeEnvironmentProperties)
|
||||
{
|
||||
|
@ -108,13 +109,14 @@ public final class ModelTransformerContext
|
|||
{
|
||||
InterpolatorProperty ip = mp.asInterpolatorProperty( baseUriForModel );
|
||||
if ( ip != null )
|
||||
{
|
||||
{ ip.setTag( interpolatorTag );
|
||||
interpolatorProperties.add( ip );
|
||||
for ( Map.Entry<String, String> a : aliases.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty(
|
||||
ip.getKey().replaceAll( a.getKey(), a.getValue()),
|
||||
ip.getValue().replaceAll( a.getKey(), a.getValue()) ) );
|
||||
ip.getValue().replaceAll( a.getKey(), a.getValue()),
|
||||
interpolatorTag) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +126,15 @@ public final class ModelTransformerContext
|
|||
public static void interpolateModelProperties(List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties )
|
||||
{
|
||||
if( modelProperties == null )
|
||||
{
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if( interpolatorProperties == null )
|
||||
{
|
||||
throw new IllegalArgumentException("interpolatorProperties: null");
|
||||
}
|
||||
|
||||
List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
|
@ -134,7 +145,10 @@ public final class ModelTransformerContext
|
|||
}
|
||||
}
|
||||
|
||||
for ( InterpolatorProperty ip : interpolatorProperties )
|
||||
LinkedHashSet<InterpolatorProperty> ips = new LinkedHashSet<InterpolatorProperty>();
|
||||
ips.addAll(interpolatorProperties);
|
||||
|
||||
for ( InterpolatorProperty ip : ips)
|
||||
{
|
||||
for ( ModelProperty mp : unresolvedProperties )
|
||||
{
|
||||
|
@ -142,8 +156,7 @@ public final class ModelTransformerContext
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
for ( InterpolatorProperty ip : interpolatorProperties )
|
||||
for ( InterpolatorProperty ip : ips )
|
||||
{
|
||||
for ( ModelProperty mp : unresolvedProperties )
|
||||
{
|
||||
|
@ -152,7 +165,6 @@ public final class ModelTransformerContext
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transforms the specified model properties using the specified transformers.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue