1 package org.apache.maven.model.path;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.api.model.ActivationFile;
23 import org.apache.maven.model.profile.ProfileActivationContext;
24 import org.codehaus.plexus.interpolation.AbstractValueSource;
25 import org.codehaus.plexus.interpolation.InterpolationException;
26 import org.codehaus.plexus.interpolation.MapBasedValueSource;
27 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
28
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.inject.Singleton;
32 import java.io.File;
33
34
35
36
37
38
39 @Named
40 @Singleton
41 public class ProfileActivationFilePathInterpolator
42 {
43
44 private final PathTranslator pathTranslator;
45
46 @Inject
47 public ProfileActivationFilePathInterpolator( PathTranslator pathTranslator )
48 {
49 this.pathTranslator = pathTranslator;
50 }
51
52
53
54
55
56
57 public String interpolate( String path, ProfileActivationContext context ) throws InterpolationException
58 {
59 if ( path == null )
60 {
61 return null;
62 }
63
64 RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
65
66 final File basedir = context.getProjectDirectory();
67
68 if ( basedir != null )
69 {
70 interpolator.addValueSource( new AbstractValueSource( false )
71 {
72 @Override
73 public Object getValue( String expression )
74 {
75
76
77
78
79 if ( "basedir".equals( expression ) )
80 {
81 return basedir.getAbsolutePath();
82 }
83 return null;
84 }
85 } );
86 }
87 else if ( path.contains( "${basedir}" ) )
88 {
89 return null;
90 }
91
92 interpolator.addValueSource( new MapBasedValueSource( context.getProjectProperties() ) );
93
94 interpolator.addValueSource( new MapBasedValueSource( context.getUserProperties() ) );
95
96 interpolator.addValueSource( new MapBasedValueSource( context.getSystemProperties() ) );
97
98 String absolutePath = interpolator.interpolate( path, "" );
99
100 return pathTranslator.alignToBaseDirectory( absolutePath, basedir );
101 }
102 }