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 import java.nio.file.Path;
27
28 import org.apache.maven.model.ActivationFile;
29 import org.apache.maven.model.profile.ProfileActivationContext;
30 import org.apache.maven.model.root.RootLocator;
31 import org.codehaus.plexus.interpolation.AbstractValueSource;
32 import org.codehaus.plexus.interpolation.InterpolationException;
33 import org.codehaus.plexus.interpolation.MapBasedValueSource;
34 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
35
36
37
38
39
40
41 @Named
42 @Singleton
43 @Deprecated
44 public class ProfileActivationFilePathInterpolator {
45
46 @Inject
47 private PathTranslator pathTranslator;
48
49 @Inject
50 private RootLocator rootLocator;
51
52 public ProfileActivationFilePathInterpolator setPathTranslator(PathTranslator pathTranslator) {
53 this.pathTranslator = pathTranslator;
54 return this;
55 }
56
57 public ProfileActivationFilePathInterpolator setRootLocator(RootLocator rootLocator) {
58 this.rootLocator = rootLocator;
59 return this;
60 }
61
62
63
64
65
66
67 public String interpolate(String path, ProfileActivationContext context) throws InterpolationException {
68 if (path == null) {
69 return null;
70 }
71
72 RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
73
74 final File basedir = context.getProjectDirectory();
75
76 if (basedir != null) {
77 interpolator.addValueSource(new AbstractValueSource(false) {
78 @Override
79 public Object getValue(String expression) {
80 if ("basedir".equals(expression) || "project.basedir".equals(expression)) {
81 return basedir.getAbsolutePath();
82 }
83 return null;
84 }
85 });
86 } else if (path.contains("${basedir}")) {
87 return null;
88 }
89
90 interpolator.addValueSource(new AbstractValueSource(false) {
91 @Override
92 public Object getValue(String expression) {
93 if ("project.rootDirectory".equals(expression)) {
94 Path base = basedir != null ? basedir.toPath() : null;
95 Path root = rootLocator.findMandatoryRoot(base);
96 return root.toFile().getAbsolutePath();
97 }
98 return null;
99 }
100 });
101
102 interpolator.addValueSource(new MapBasedValueSource(context.getProjectProperties()));
103
104 interpolator.addValueSource(new MapBasedValueSource(context.getUserProperties()));
105
106 interpolator.addValueSource(new MapBasedValueSource(context.getSystemProperties()));
107
108 String absolutePath = interpolator.interpolate(path, "");
109
110 return pathTranslator.alignToBaseDirectory(absolutePath, basedir);
111 }
112 }