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.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 @Inject
44 private PathTranslator pathTranslator;
45
46 public ProfileActivationFilePathInterpolator setPathTranslator(PathTranslator pathTranslator) {
47 this.pathTranslator = pathTranslator;
48 return this;
49 }
50
51
52
53
54
55
56 public String interpolate(String path, ProfileActivationContext context) throws InterpolationException {
57 if (path == null) {
58 return null;
59 }
60
61 RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
62
63 final File basedir = context.getProjectDirectory();
64
65 if (basedir != null) {
66 interpolator.addValueSource(new AbstractValueSource(false) {
67 @Override
68 public Object getValue(String expression) {
69 if ("basedir".equals(expression) || "project.basedir".equals(expression)) {
70 return basedir.getAbsolutePath();
71 }
72 return null;
73 }
74 });
75 } else if (path.contains("${basedir}")) {
76 return null;
77 }
78
79 interpolator.addValueSource(new MapBasedValueSource(context.getProjectProperties()));
80
81 interpolator.addValueSource(new MapBasedValueSource(context.getUserProperties()));
82
83 interpolator.addValueSource(new MapBasedValueSource(context.getSystemProperties()));
84
85 String absolutePath = interpolator.interpolate(path, "");
86
87 return pathTranslator.alignToBaseDirectory(absolutePath, basedir);
88 }
89 }