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