allow the expression evaluator to align strings to a base directory, for the purposes of the file converter

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163949 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-15 05:29:00 +00:00
parent 1166e16562
commit f4bf6c145d
3 changed files with 23 additions and 14 deletions

View File

@ -395,7 +395,7 @@ public class DefaultPluginManager
configuration = mergeConfiguration( configuration, mojoDescriptor.getConfiguration() );
PluginParameterExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator );
try
{
if ( newMojoTechnique )
@ -577,6 +577,12 @@ public class DefaultPluginManager
for ( Iterator i = map.keySet().iterator(); i.hasNext(); )
{
String key = (String) i.next();
if ( configuration.getChild( key ) != null )
{
continue;
}
Object value = map.get( key );
if ( value != null )
@ -684,15 +690,6 @@ public class DefaultPluginManager
throw new PluginConfigurationException( createPluginParameterRequiredMessage( goal, parameter ) );
}
String type = parameter.getType();
// TODO: remove - done via plexus configuration, but need to inject the base directory into it
if ( type != null && ( type.equals( "File" ) || type.equals( "java.io.File" ) ) )
{
value = pathTranslator.alignToBaseDirectory( (String) value,
session.getProject().getFile().getParentFile() );
}
map.put( key, value );
}
return map;

View File

@ -17,11 +17,14 @@ package org.apache.maven.plugin;
*/
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.util.introspection.ReflectionValueExtractor;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.io.File;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@ -30,11 +33,14 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
public class PluginParameterExpressionEvaluator
implements ExpressionEvaluator
{
private final PathTranslator pathTranslator;
private final MavenSession context;
public PluginParameterExpressionEvaluator( MavenSession context )
public PluginParameterExpressionEvaluator( MavenSession context, PathTranslator pathTranslator )
{
this.context = context;
this.pathTranslator = pathTranslator;
}
public Object evaluate( String expression )
@ -165,5 +171,11 @@ public class PluginParameterExpressionEvaluator
return value;
}
public File alignToBaseDirectory( File file )
{
File basedir = context.getProject().getFile().getParentFile();
return new File( pathTranslator.alignToBaseDirectory( file.getPath(), basedir ) );
}
}

View File

@ -62,7 +62,7 @@ public class PluginParameterExpressionEvaluatorTest
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
Object value = expressionEvaluator.evaluate( "#project.build.directory/classes" );
String actual = new File( value.toString() ).getCanonicalPath();
@ -90,7 +90,7 @@ public class PluginParameterExpressionEvaluatorTest
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
Object value = expressionEvaluator.evaluate( role );
assertNotNull( value );
@ -111,7 +111,7 @@ public class PluginParameterExpressionEvaluatorTest
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
Object value = expressionEvaluator.evaluate( "#localRepository" );
assertEquals( "local", ( (ArtifactRepository) value ).getId() );