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