mirror of https://github.com/apache/maven.git
Adding -V|--show-version, and cleaning up interpolation to correspond with recent refactoriing in 2.0.x branch. Also, changing super-POM to use basedir/build.directory expressions in build paths, to enable paths to respond to changes in other, more basic paths (like outputDirectory responding to a change in build.directory). This is in preparation for merging over the dynamicBuild behavior.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@671936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
179ce1a925
commit
cd2602d9e6
|
@ -743,6 +743,7 @@ public class DefaultMavenExecutionRequest
|
||||||
projectBuildingConfiguration.setExecutionProperties( getProperties() );
|
projectBuildingConfiguration.setExecutionProperties( getProperties() );
|
||||||
projectBuildingConfiguration.setGlobalProfileManager( getProfileManager() );
|
projectBuildingConfiguration.setGlobalProfileManager( getProfileManager() );
|
||||||
projectBuildingConfiguration.setUserProperties( getUserProperties() );
|
projectBuildingConfiguration.setUserProperties( getUserProperties() );
|
||||||
|
projectBuildingConfiguration.setBuildStartTime( getStartTime() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectBuildingConfiguration;
|
return projectBuildingConfiguration;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.maven.monitor.event.EventDispatcher;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||||
import org.apache.maven.realm.MavenRealmManager;
|
import org.apache.maven.realm.MavenRealmManager;
|
||||||
import org.apache.maven.reporting.MavenReport;
|
import org.apache.maven.reporting.MavenReport;
|
||||||
import org.apache.maven.settings.Settings;
|
import org.apache.maven.settings.Settings;
|
||||||
|
@ -276,4 +277,9 @@ public class MavenSession
|
||||||
return buildPlans;
|
return buildPlans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProjectBuilderConfiguration getProjectBuilderConfiguration()
|
||||||
|
{
|
||||||
|
return request.getProjectBuildingConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -162,7 +162,7 @@ public class DefaultBuildExtensionScanner
|
||||||
inheritedInterpolationValues = new HashMap();
|
inheritedInterpolationValues = new HashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
model = modelInterpolator.interpolate( model, inheritedInterpolationValues, request.getUserProperties(), false );
|
model = modelInterpolator.interpolate( model, modelPom.getParentFile(), request.getProjectBuildingConfiguration(), getLogger().isDebugEnabled() );
|
||||||
|
|
||||||
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
|
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,8 @@ public class CLIManager
|
||||||
|
|
||||||
public static final char VERSION = 'v';
|
public static final char VERSION = 'v';
|
||||||
|
|
||||||
|
public static final char SHOW_VERSION = 'V';
|
||||||
|
|
||||||
public static final char NON_RECURSIVE = 'N';
|
public static final char NON_RECURSIVE = 'N';
|
||||||
|
|
||||||
public static final char UPDATE_SNAPSHOTS = 'U';
|
public static final char UPDATE_SNAPSHOTS = 'U';
|
||||||
|
@ -161,6 +163,10 @@ public class CLIManager
|
||||||
|
|
||||||
options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription(
|
options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription(
|
||||||
"Log file to where all build output will go." ).create( LOG_FILE ) );
|
"Log file to where all build output will go." ).create( LOG_FILE ) );
|
||||||
|
|
||||||
|
options.addOption(
|
||||||
|
OptionBuilder.withLongOpt( "show-version" ).withDescription( "Display version information WITHOUT stopping build" ).create(
|
||||||
|
SHOW_VERSION ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandLine parse( String[] args )
|
public CommandLine parse( String[] args )
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class MavenCli
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if ( debug )
|
else if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) )
|
||||||
{
|
{
|
||||||
CLIReportingUtils.showVersion();
|
CLIReportingUtils.showVersion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,6 +201,7 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
|
@Deprecated
|
||||||
public MavenProject buildFromRepository( Artifact artifact,
|
public MavenProject buildFromRepository( Artifact artifact,
|
||||||
List remoteArtifactRepositories,
|
List remoteArtifactRepositories,
|
||||||
ArtifactRepository localRepository,
|
ArtifactRepository localRepository,
|
||||||
|
@ -965,18 +966,6 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
List activeProfiles = project.getActiveProfiles();
|
List activeProfiles = project.getActiveProfiles();
|
||||||
|
|
||||||
// TODO: Clean this up...we're using this to 'jump' the interpolation step for model properties not expressed in XML.
|
|
||||||
// [BP] - Can this above comment be explained?
|
|
||||||
// We don't need all the project methods that are added over those in the model, but we do need basedir
|
|
||||||
// mkleint - using System.getProperties() is almost definitely bad for embedding.
|
|
||||||
Map context = new HashMap();
|
|
||||||
|
|
||||||
// [MNG-2339] ensure the system properties are still interpolated for backwards compat, but the model values must win
|
|
||||||
if ( config.getExecutionProperties() != null && !config.getExecutionProperties().isEmpty() )
|
|
||||||
{
|
|
||||||
context.putAll( config.getExecutionProperties() );
|
|
||||||
}
|
|
||||||
|
|
||||||
File projectDir = null;
|
File projectDir = null;
|
||||||
|
|
||||||
if ( pomFile != null )
|
if ( pomFile != null )
|
||||||
|
@ -984,13 +973,7 @@ public class DefaultMavenProjectBuilder
|
||||||
projectDir = pomFile.getAbsoluteFile().getParentFile();
|
projectDir = pomFile.getAbsoluteFile().getParentFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map overrideContext = new HashMap();
|
model = modelInterpolator.interpolate( model, projectDir, config, getLogger().isDebugEnabled() );
|
||||||
if ( !isSuperPom && config.getUserProperties() != null && !config.getUserProperties().isEmpty() )
|
|
||||||
{
|
|
||||||
overrideContext.putAll( config.getUserProperties() );
|
|
||||||
}
|
|
||||||
|
|
||||||
model = modelInterpolator.interpolate( model, context, overrideContext, projectDir, true );
|
|
||||||
|
|
||||||
// We must inject any imported dependencyManagement information ahead of the defaults injection.
|
// We must inject any imported dependencyManagement information ahead of the defaults injection.
|
||||||
if ( !isSuperPom )
|
if ( !isSuperPom )
|
||||||
|
@ -1309,6 +1292,7 @@ public class DefaultMavenProjectBuilder
|
||||||
* @return
|
* @return
|
||||||
* @throws ProjectBuildingException
|
* @throws ProjectBuildingException
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
protected Set createPluginArtifacts( String projectId,
|
protected Set createPluginArtifacts( String projectId,
|
||||||
List plugins, String pomLocation )
|
List plugins, String pomLocation )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
|
@ -1372,6 +1356,7 @@ public class DefaultMavenProjectBuilder
|
||||||
* @return
|
* @return
|
||||||
* @throws ProjectBuildingException
|
* @throws ProjectBuildingException
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
protected Set createReportArtifacts( String projectId,
|
protected Set createReportArtifacts( String projectId,
|
||||||
List reports, String pomLocation )
|
List reports, String pomLocation )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
|
@ -1431,6 +1416,7 @@ public class DefaultMavenProjectBuilder
|
||||||
* @return
|
* @return
|
||||||
* @throws ProjectBuildingException
|
* @throws ProjectBuildingException
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
protected Set createExtensionArtifacts( String projectId,
|
protected Set createExtensionArtifacts( String projectId,
|
||||||
List extensions, String pomLocation )
|
List extensions, String pomLocation )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.apache.maven.project;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.profiles.ProfileManager;
|
import org.apache.maven.profiles.ProfileManager;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class DefaultProjectBuilderConfiguration
|
public class DefaultProjectBuilderConfiguration
|
||||||
|
@ -17,6 +18,8 @@ public class DefaultProjectBuilderConfiguration
|
||||||
|
|
||||||
private Properties executionProperties = System.getProperties();
|
private Properties executionProperties = System.getProperties();
|
||||||
|
|
||||||
|
private Date buildStartTime;
|
||||||
|
|
||||||
public DefaultProjectBuilderConfiguration()
|
public DefaultProjectBuilderConfiguration()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -70,4 +73,15 @@ public class DefaultProjectBuilderConfiguration
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getBuildStartTime()
|
||||||
|
{
|
||||||
|
return buildStartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectBuilderConfiguration setBuildStartTime( Date buildStartTime )
|
||||||
|
{
|
||||||
|
this.buildStartTime = buildStartTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.apache.maven.project;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.profiles.ProfileManager;
|
import org.apache.maven.profiles.ProfileManager;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public interface ProjectBuilderConfiguration
|
public interface ProjectBuilderConfiguration
|
||||||
|
@ -24,4 +25,8 @@ public interface ProjectBuilderConfiguration
|
||||||
|
|
||||||
ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties );
|
ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties );
|
||||||
|
|
||||||
|
Date getBuildStartTime();
|
||||||
|
|
||||||
|
ProjectBuilderConfiguration setBuildStartTime( Date buildStartTime );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.apache.maven.project.interpolation;
|
||||||
|
|
||||||
|
import org.codehaus.plexus.interpolation.ValueSource;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class BuildTimestampValueSource
|
||||||
|
implements ValueSource
|
||||||
|
{
|
||||||
|
|
||||||
|
private String formattedDate;
|
||||||
|
|
||||||
|
public BuildTimestampValueSource( Date startTime, String format )
|
||||||
|
{
|
||||||
|
if ( startTime != null )
|
||||||
|
{
|
||||||
|
formattedDate = new SimpleDateFormat( format ).format( startTime );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValue( String expression )
|
||||||
|
{
|
||||||
|
if ( "build.timestamp".equals( expression ) || "maven.build.timestamp".equals( expression ) )
|
||||||
|
{
|
||||||
|
return formattedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package org.apache.maven.project.interpolation;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
|
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -31,27 +32,39 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public interface ModelInterpolator
|
public interface ModelInterpolator
|
||||||
{
|
{
|
||||||
|
String DEFAULT_BUILD_TIMESTAMP_FORMAT = "yyyyMMdd-hhmm";
|
||||||
|
|
||||||
|
String BUILD_TIMESTAMP_FORMAT_PROPERTY = "maven.build.timestamp.format";
|
||||||
|
|
||||||
String ROLE = ModelInterpolator.class.getName();
|
String ROLE = ModelInterpolator.class.getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
Model interpolate( Model project,
|
Model interpolate( Model project,
|
||||||
Map context )
|
Map<String, ?> context )
|
||||||
throws ModelInterpolationException;
|
throws ModelInterpolationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
Model interpolate( Model model,
|
Model interpolate( Model model,
|
||||||
Map context,
|
Map<String, ?> context,
|
||||||
boolean strict )
|
boolean strict )
|
||||||
throws ModelInterpolationException;
|
throws ModelInterpolationException;
|
||||||
|
|
||||||
Model interpolate( Model model,
|
Model interpolate( Model model,
|
||||||
Map context,
|
File projectDir,
|
||||||
Map overrideContext,
|
ProjectBuilderConfiguration config,
|
||||||
boolean outputDebugMessages )
|
boolean debugEnabled )
|
||||||
throws ModelInterpolationException;
|
throws ModelInterpolationException;
|
||||||
|
|
||||||
Model interpolate( Model model,
|
String interpolate( String src,
|
||||||
Map context,
|
Model model,
|
||||||
Map overrideContext,
|
|
||||||
File projectDir,
|
File projectDir,
|
||||||
boolean outputDebugMessages )
|
ProjectBuilderConfiguration config,
|
||||||
|
boolean debugEnabled )
|
||||||
throws ModelInterpolationException;
|
throws ModelInterpolationException;
|
||||||
}
|
}
|
|
@ -11,11 +11,11 @@ public class PathTranslatingValueSource
|
||||||
extends AbstractFunctionValueSourceWrapper
|
extends AbstractFunctionValueSourceWrapper
|
||||||
{
|
{
|
||||||
|
|
||||||
private final List unprefixedPathKeys;
|
private final List<String> unprefixedPathKeys;
|
||||||
private final File projectDir;
|
private final File projectDir;
|
||||||
private final PathTranslator pathTranslator;
|
private final PathTranslator pathTranslator;
|
||||||
|
|
||||||
protected PathTranslatingValueSource( ValueSource valueSource, List unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
|
protected PathTranslatingValueSource( ValueSource valueSource, List<String> unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
|
||||||
{
|
{
|
||||||
super( valueSource );
|
super( valueSource );
|
||||||
this.unprefixedPathKeys = unprefixedPathKeys;
|
this.unprefixedPathKeys = unprefixedPathKeys;
|
||||||
|
@ -23,6 +23,7 @@ public class PathTranslatingValueSource
|
||||||
this.pathTranslator = pathTranslator;
|
this.pathTranslator = pathTranslator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Object executeFunction( String expression,
|
protected Object executeFunction( String expression,
|
||||||
Object value )
|
Object value )
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,8 @@ package org.apache.maven.project.interpolation;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||||
|
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||||
|
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||||
import org.apache.maven.project.path.PathTranslator;
|
import org.apache.maven.project.path.PathTranslator;
|
||||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||||
import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
||||||
|
@ -34,7 +36,6 @@ import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
|
||||||
import org.codehaus.plexus.interpolation.ValueSource;
|
import org.codehaus.plexus.interpolation.ValueSource;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -43,12 +44,10 @@ import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.Properties;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use a regular expression search to find and resolve expressions within the POM.
|
* Use a regular expression search to find and resolve expressions within the POM.
|
||||||
|
@ -61,14 +60,13 @@ public class RegexBasedModelInterpolator
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
implements ModelInterpolator
|
implements ModelInterpolator
|
||||||
{
|
{
|
||||||
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{([^}]+)\\}" );
|
|
||||||
|
|
||||||
private static final List PROJECT_PREFIXES = Arrays.asList( new String[]{ "pom.", "project." } );
|
private static final List<String> PROJECT_PREFIXES = Arrays.asList( new String[]{ "pom.", "project." } );
|
||||||
private static final List TRANSLATED_PATH_EXPRESSIONS;
|
private static final List<String> TRANSLATED_PATH_EXPRESSIONS;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
List translatedPrefixes = new ArrayList();
|
List<String> translatedPrefixes = new ArrayList<String>();
|
||||||
|
|
||||||
// MNG-1927, MNG-2124, MNG-3355:
|
// MNG-1927, MNG-2124, MNG-3355:
|
||||||
// If the build section is present and the project directory is non-null, we should make
|
// If the build section is present and the project directory is non-null, we should make
|
||||||
|
@ -91,25 +89,28 @@ public class RegexBasedModelInterpolator
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model interpolate( Model model, Map context )
|
public Model interpolate( Model model, Map<String, ?> context )
|
||||||
throws ModelInterpolationException
|
throws ModelInterpolationException
|
||||||
{
|
{
|
||||||
return interpolate( model, context, Collections.EMPTY_MAP, null, true );
|
Properties props = new Properties();
|
||||||
|
props.putAll( context );
|
||||||
|
|
||||||
|
return interpolate( model,
|
||||||
|
null,
|
||||||
|
new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
|
||||||
|
true );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model interpolate( Model model, Map context, boolean strict )
|
public Model interpolate( Model model, Map<String, ?> context, boolean strict )
|
||||||
throws ModelInterpolationException
|
throws ModelInterpolationException
|
||||||
{
|
{
|
||||||
return interpolate( model, context, Collections.EMPTY_MAP, null, true );
|
Properties props = new Properties();
|
||||||
}
|
props.putAll( context );
|
||||||
|
|
||||||
public Model interpolate( Model model,
|
return interpolate( model,
|
||||||
Map context,
|
null,
|
||||||
Map overrideContext,
|
new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
|
||||||
boolean strict )
|
true );
|
||||||
throws ModelInterpolationException
|
|
||||||
{
|
|
||||||
return interpolate( model, context, Collections.EMPTY_MAP, null, true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,10 +126,10 @@ public class RegexBasedModelInterpolator
|
||||||
* or userProperties in the execution request.
|
* or userProperties in the execution request.
|
||||||
* @param projectDir The directory from which the current model's pom was read.
|
* @param projectDir The directory from which the current model's pom was read.
|
||||||
* @param strict This parameter is ignored!
|
* @param strict This parameter is ignored!
|
||||||
* @param outputDebugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
|
* @param debugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
|
||||||
* @return The resolved instance of the inbound Model. This is a different instance!
|
* @return The resolved instance of the inbound Model. This is a different instance!
|
||||||
*/
|
*/
|
||||||
public Model interpolate( Model model, Map context, Map overrideContext, File projectDir, boolean outputDebugMessages )
|
public Model interpolate( Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugMessages )
|
||||||
throws ModelInterpolationException
|
throws ModelInterpolationException
|
||||||
{
|
{
|
||||||
StringWriter sWriter = new StringWriter();
|
StringWriter sWriter = new StringWriter();
|
||||||
|
@ -144,7 +145,7 @@ public class RegexBasedModelInterpolator
|
||||||
}
|
}
|
||||||
|
|
||||||
String serializedModel = sWriter.toString();
|
String serializedModel = sWriter.toString();
|
||||||
serializedModel = interpolateInternal( serializedModel, model, context, overrideContext, projectDir, outputDebugMessages );
|
serializedModel = interpolate( serializedModel, model, projectDir, config, debugMessages );
|
||||||
|
|
||||||
StringReader sReader = new StringReader( serializedModel );
|
StringReader sReader = new StringReader( serializedModel );
|
||||||
|
|
||||||
|
@ -179,18 +180,25 @@ public class RegexBasedModelInterpolator
|
||||||
* <li>If the value is null, get it from the model properties.</li>
|
* <li>If the value is null, get it from the model properties.</li>
|
||||||
* <li>
|
* <li>
|
||||||
* @param overrideContext
|
* @param overrideContext
|
||||||
* @param outputDebugMessages
|
* @param debugMessages
|
||||||
*/
|
*/
|
||||||
private String interpolateInternal( String src,
|
public String interpolate( String src,
|
||||||
Model model,
|
Model model,
|
||||||
Map context,
|
|
||||||
Map overrideContext,
|
|
||||||
final File projectDir,
|
final File projectDir,
|
||||||
boolean outputDebugMessages )
|
ProjectBuilderConfiguration config,
|
||||||
|
boolean debugMessages )
|
||||||
throws ModelInterpolationException
|
throws ModelInterpolationException
|
||||||
{
|
{
|
||||||
Logger logger = getLogger();
|
Logger logger = getLogger();
|
||||||
|
|
||||||
|
String timestampFormat = DEFAULT_BUILD_TIMESTAMP_FORMAT;
|
||||||
|
|
||||||
|
Properties modelProperties = model.getProperties();
|
||||||
|
if ( modelProperties != null )
|
||||||
|
{
|
||||||
|
timestampFormat = modelProperties.getProperty( BUILD_TIMESTAMP_FORMAT_PROPERTY, timestampFormat );
|
||||||
|
}
|
||||||
|
|
||||||
ValueSource baseModelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false );
|
ValueSource baseModelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false );
|
||||||
ValueSource modelValueSource1 = new PathTranslatingValueSource( baseModelValueSource1,
|
ValueSource modelValueSource1 = new PathTranslatingValueSource( baseModelValueSource1,
|
||||||
TRANSLATED_PATH_EXPRESSIONS,
|
TRANSLATED_PATH_EXPRESSIONS,
|
||||||
|
@ -218,76 +226,34 @@ public class RegexBasedModelInterpolator
|
||||||
|
|
||||||
// NOTE: Order counts here!
|
// NOTE: Order counts here!
|
||||||
interpolator.addValueSource( basedirValueSource );
|
interpolator.addValueSource( basedirValueSource );
|
||||||
interpolator.addValueSource( new MapBasedValueSource( overrideContext ) );
|
interpolator.addValueSource( new BuildTimestampValueSource( config.getBuildStartTime(), timestampFormat ) );
|
||||||
|
interpolator.addValueSource( new MapBasedValueSource( config.getExecutionProperties() ) );
|
||||||
interpolator.addValueSource( modelValueSource1 );
|
interpolator.addValueSource( modelValueSource1 );
|
||||||
interpolator.addValueSource( new PrefixedValueSourceWrapper( new MapBasedValueSource( model.getProperties() ), PROJECT_PREFIXES, true ) );
|
interpolator.addValueSource( new PrefixedValueSourceWrapper( new MapBasedValueSource( modelProperties ), PROJECT_PREFIXES, true ) );
|
||||||
interpolator.addValueSource( modelValueSource2 );
|
interpolator.addValueSource( modelValueSource2 );
|
||||||
interpolator.addValueSource( new MapBasedValueSource( context ) );
|
interpolator.addValueSource( new MapBasedValueSource( config.getUserProperties() ) );
|
||||||
|
|
||||||
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
|
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
|
||||||
|
|
||||||
String result = src;
|
String result = src;
|
||||||
Matcher matcher = EXPRESSION_PATTERN.matcher( result );
|
|
||||||
while ( matcher.find() )
|
|
||||||
{
|
|
||||||
String wholeExpr = matcher.group( 0 );
|
|
||||||
|
|
||||||
Object value;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
value = interpolator.interpolate( wholeExpr, "", recursionInterceptor );
|
result = interpolator.interpolate( result, "", recursionInterceptor );
|
||||||
}
|
}
|
||||||
catch( InterpolationException e )
|
catch( InterpolationException e )
|
||||||
{
|
{
|
||||||
throw new ModelInterpolationException( e.getMessage(), e );
|
throw new ModelInterpolationException( e.getMessage(), e );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( value == null || value.equals( wholeExpr ) )
|
if ( debugMessages )
|
||||||
{
|
{
|
||||||
continue;
|
List<?> feedback = interpolator.getFeedback();
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Does this account for the case where ${project.build.directory} -> ${build.directory}??
|
|
||||||
if ( value != null )
|
|
||||||
{
|
|
||||||
// if the expression refers to itself, skip it.
|
|
||||||
// replace project. expressions with pom. expressions to circumvent self-referencing expressions using
|
|
||||||
// the 2 different model expressions.
|
|
||||||
if ( StringUtils.replace( value.toString(), "${project.", "${pom." ).indexOf(
|
|
||||||
StringUtils.replace( wholeExpr, "${project.", "${pom." ) ) > -1 )
|
|
||||||
{
|
|
||||||
throw new ModelInterpolationException( wholeExpr, "Expression value '" + value
|
|
||||||
+ "' references itself in '" + model.getId() + "'." );
|
|
||||||
}
|
|
||||||
|
|
||||||
result = StringUtils.replace( result, wholeExpr, value.toString() );
|
|
||||||
// could use:
|
|
||||||
// result = matcher.replaceFirst( stringValue );
|
|
||||||
// but this could result in multiple lookups of stringValue, and replaceAll is not correct behaviour
|
|
||||||
matcher.reset( result );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the
|
|
||||||
// timing of executing the interpolation
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ModelInterpolationException(
|
|
||||||
"Expression '" + wholeExpr + "' did not evaluate to anything in the model" );
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( outputDebugMessages )
|
|
||||||
{
|
|
||||||
List feedback = interpolator.getFeedback();
|
|
||||||
if ( feedback != null && !feedback.isEmpty() )
|
if ( feedback != null && !feedback.isEmpty() )
|
||||||
{
|
{
|
||||||
logger.debug( "Maven encountered the following problems during initial POM interpolation:" );
|
logger.debug( "Maven encountered the following problems during initial POM interpolation:" );
|
||||||
|
|
||||||
Object last = null;
|
Object last = null;
|
||||||
for ( Iterator it = feedback.iterator(); it.hasNext(); )
|
for ( Iterator<?> it = feedback.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Object next = it.next();
|
Object next = it.next();
|
||||||
|
|
||||||
|
|
|
@ -50,21 +50,21 @@ under the License.
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<directory>target</directory>
|
<directory>${project.basedir}/target</directory>
|
||||||
<outputDirectory>target/classes</outputDirectory>
|
<outputDirectory>${project.build.directory}/classes</outputDirectory>
|
||||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
|
||||||
<sourceDirectory>src/main/java</sourceDirectory>
|
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||||
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
|
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
|
||||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>${project.basedir}/src/main/resources</directory>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<testResources>
|
<testResources>
|
||||||
<testResource>
|
<testResource>
|
||||||
<directory>src/test/resources</directory>
|
<directory>${project.basedir}/src/test/resources</directory>
|
||||||
</testResource>
|
</testResource>
|
||||||
</testResources>
|
</testResources>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
|
@ -150,7 +150,7 @@ under the License.
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<outputDirectory>target/site</outputDirectory>
|
<outputDirectory>${project.build.directory}/site</outputDirectory>
|
||||||
</reporting>
|
</reporting>
|
||||||
</project>
|
</project>
|
||||||
<!-- END SNIPPET: superpom -->
|
<!-- END SNIPPET: superpom -->
|
||||||
|
|
|
@ -26,11 +26,12 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Organization;
|
import org.apache.maven.model.Organization;
|
||||||
import org.apache.maven.model.Repository;
|
import org.apache.maven.model.Repository;
|
||||||
import org.apache.maven.model.Scm;
|
import org.apache.maven.model.Scm;
|
||||||
|
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||||
|
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ public class RegexBasedModelInterpolatorTest
|
||||||
{
|
{
|
||||||
private Map context;
|
private Map context;
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -66,15 +68,15 @@ public class RegexBasedModelInterpolatorTest
|
||||||
dm.setRepository( repo );
|
dm.setRepository( repo );
|
||||||
model.setDistributionManagement( dm );
|
model.setDistributionManagement( dm );
|
||||||
|
|
||||||
Map context = new HashMap();
|
|
||||||
String path = "path/to/project";
|
String path = "path/to/project";
|
||||||
|
|
||||||
File basedir = new File( path ).getAbsoluteFile();
|
File basedir = new File( path ).getAbsoluteFile();
|
||||||
|
|
||||||
|
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
|
||||||
|
|
||||||
Model out = new RegexBasedModelInterpolator().interpolate( model,
|
Model out = new RegexBasedModelInterpolator().interpolate( model,
|
||||||
context,
|
|
||||||
Collections.EMPTY_MAP,
|
|
||||||
basedir,
|
basedir,
|
||||||
|
config,
|
||||||
false );
|
false );
|
||||||
|
|
||||||
assertEquals( "http://localhost/" + basedir.getAbsolutePath() + "/target/test-repo",
|
assertEquals( "http://localhost/" + basedir.getAbsolutePath() + "/target/test-repo",
|
||||||
|
|
Loading…
Reference in New Issue