1 package org.apache.maven.plugin.assembly.interpolation;
2
3 import java.io.File;
4
5 import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
6 import org.apache.maven.plugin.assembly.utils.InterpolationConstants;
7 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
8 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
9 import org.codehaus.plexus.interpolation.InterpolationException;
10 import org.codehaus.plexus.interpolation.Interpolator;
11 import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
12
13 public class AssemblyExpressionEvaluator
14 implements ExpressionEvaluator
15 {
16
17 private final AssemblerConfigurationSource configSource;
18 private Interpolator interpolator;
19 private PrefixAwareRecursionInterceptor interceptor;
20
21 public AssemblyExpressionEvaluator( AssemblerConfigurationSource configSource )
22 {
23 this.configSource = configSource;
24
25 interpolator = AssemblyInterpolator.buildInterpolator( configSource.getProject(), configSource );
26 interceptor = new PrefixAwareRecursionInterceptor( InterpolationConstants.PROJECT_PREFIXES, true );
27 }
28
29 public File alignToBaseDirectory( File f )
30 {
31 String basePath = configSource.getBasedir().getAbsolutePath();
32 String path = f.getPath();
33
34 if ( !f.isAbsolute() && !path.startsWith( basePath ) )
35 {
36 return new File( configSource.getBasedir(), path );
37 }
38 else
39 {
40 return f;
41 }
42 }
43
44 public Object evaluate( String expression )
45 throws ExpressionEvaluationException
46 {
47 try
48 {
49 return interpolator.interpolate( expression, interceptor );
50 }
51 catch ( InterpolationException e )
52 {
53 throw new ExpressionEvaluationException( "Interpolation failed for archiver expression: " + expression, e );
54 }
55 }
56
57 }