o Minor tweaks to the interpolation post process:

- Excluded it completely if it has nothing to do
  - Switched contains() test to use hash-based lookup rather than linear search

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@781168 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-02 21:06:57 +00:00
parent a65f6d71f0
commit 1e730aa8ad
2 changed files with 24 additions and 11 deletions

View File

@ -38,7 +38,9 @@ import org.codehaus.plexus.interpolation.ValueSource;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
@ -54,11 +56,11 @@ public abstract class AbstractStringBasedModelInterpolator
{
private static final List<String> PROJECT_PREFIXES = Arrays.asList( new String[]{ "pom.", "project." } );
private static final List<String> TRANSLATED_PATH_EXPRESSIONS;
private static final Collection<String> TRANSLATED_PATH_EXPRESSIONS;
static
{
List<String> translatedPrefixes = new ArrayList<String>();
Collection<String> translatedPrefixes = new HashSet<String>();
// MNG-1927, MNG-2124, MNG-3355:
// If the build section is present and the project directory is non-null, we should make
@ -150,9 +152,16 @@ public abstract class AbstractStringBasedModelInterpolator
final File projectDir,
final ModelBuildingRequest config )
{
return Collections.singletonList( new PathTranslatingPostProcessor( PROJECT_PREFIXES,
TRANSLATED_PATH_EXPRESSIONS, projectDir,
pathTranslator ) );
if ( projectDir != null )
{
return Collections.singletonList( new PathTranslatingPostProcessor( PROJECT_PREFIXES,
TRANSLATED_PATH_EXPRESSIONS,
projectDir, pathTranslator ) );
}
else
{
return Collections.emptyList();
}
}
protected String interpolateInternal( String src, List<? extends ValueSource> valueSources,

View File

@ -24,6 +24,7 @@ import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
import org.codehaus.plexus.interpolation.util.ValueSourceUtils;
import java.io.File;
import java.util.Collection;
import java.util.List;
/**
@ -34,12 +35,12 @@ class PathTranslatingPostProcessor
implements InterpolationPostProcessor
{
private final List<String> unprefixedPathKeys;
private final Collection<String> unprefixedPathKeys;
private final File projectDir;
private final PathTranslator pathTranslator;
private final List<String> expressionPrefixes;
public PathTranslatingPostProcessor( List<String> expressionPrefixes, List<String> unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
public PathTranslatingPostProcessor( List<String> expressionPrefixes, Collection<String> unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
{
this.expressionPrefixes = expressionPrefixes;
this.unprefixedPathKeys = unprefixedPathKeys;
@ -49,11 +50,14 @@ class PathTranslatingPostProcessor
public Object execute( String expression, Object value )
{
expression = ValueSourceUtils.trimPrefix( expression, expressionPrefixes, true );
if ( projectDir != null && value != null && unprefixedPathKeys.contains( expression ) )
if ( value != null )
{
return pathTranslator.alignToBaseDirectory( String.valueOf( value ), projectDir );
expression = ValueSourceUtils.trimPrefix( expression, expressionPrefixes, true );
if ( unprefixedPathKeys.contains( expression ) )
{
return pathTranslator.alignToBaseDirectory( String.valueOf( value ), projectDir );
}
}
return value;