1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl.model;
20
21 import java.nio.file.Path;
22
23 import org.apache.maven.api.di.Inject;
24 import org.apache.maven.api.di.Named;
25 import org.apache.maven.api.di.Singleton;
26 import org.apache.maven.api.model.ActivationFile;
27 import org.apache.maven.api.services.Interpolator;
28 import org.apache.maven.api.services.InterpolatorException;
29 import org.apache.maven.api.services.model.PathTranslator;
30 import org.apache.maven.api.services.model.ProfileActivationContext;
31 import org.apache.maven.api.services.model.RootLocator;
32
33
34
35
36 @Named
37 @Singleton
38 public class ProfileActivationFilePathInterpolator {
39
40 private final PathTranslator pathTranslator;
41
42 private final RootLocator rootLocator;
43
44 private final Interpolator interpolator;
45
46 @Inject
47 public ProfileActivationFilePathInterpolator(
48 PathTranslator pathTranslator, RootLocator rootLocator, Interpolator interpolator) {
49 this.pathTranslator = pathTranslator;
50 this.rootLocator = rootLocator;
51 this.interpolator = interpolator;
52 }
53
54
55
56
57
58
59 public String interpolate(String path, ProfileActivationContext context) throws InterpolatorException {
60 if (path == null) {
61 return null;
62 }
63
64 Path basedir = context.getProjectDirectory();
65
66 String absolutePath = interpolator.interpolate(path, s -> {
67 if ("basedir".equals(s) || "project.basedir".equals(s)) {
68 return basedir != null ? basedir.toFile().getAbsolutePath() : null;
69 }
70 if ("project.rootDirectory".equals(s)) {
71 Path root = rootLocator.findMandatoryRoot(basedir);
72 return root.toFile().getAbsolutePath();
73 }
74 String r = context.getProjectProperties().get(s);
75 if (r == null) {
76 r = context.getUserProperties().get(s);
77 }
78 if (r == null) {
79 r = context.getSystemProperties().get(s);
80 }
81 return r;
82 });
83
84 return pathTranslator.alignToBaseDirectory(absolutePath, basedir);
85 }
86 }