1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.profiles.activation;
20
21 import java.io.IOException;
22
23 import org.apache.maven.model.Activation;
24 import org.apache.maven.model.ActivationFile;
25 import org.apache.maven.model.Profile;
26 import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
27 import org.codehaus.plexus.interpolation.InterpolationException;
28 import org.codehaus.plexus.interpolation.MapBasedValueSource;
29 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
30 import org.codehaus.plexus.logging.LogEnabled;
31 import org.codehaus.plexus.logging.Logger;
32 import org.codehaus.plexus.util.FileUtils;
33 import org.codehaus.plexus.util.StringUtils;
34
35
36
37
38 @Deprecated
39 public class FileProfileActivator extends DetectedProfileActivator implements LogEnabled {
40 private Logger logger;
41
42 protected boolean canDetectActivation(Profile profile) {
43 return profile.getActivation() != null && profile.getActivation().getFile() != null;
44 }
45
46 public boolean isActive(Profile profile) {
47 Activation activation = profile.getActivation();
48
49 ActivationFile actFile = activation.getFile();
50
51 if (actFile != null) {
52
53 String fileString = actFile.getExists();
54
55 RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
56 try {
57 interpolator.addValueSource(new EnvarBasedValueSource());
58 } catch (IOException e) {
59
60 }
61 interpolator.addValueSource(new MapBasedValueSource(System.getProperties()));
62
63 try {
64 if (fileString != null && !fileString.isEmpty()) {
65 fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
66 return FileUtils.fileExists(fileString);
67 }
68
69
70 fileString = actFile.getMissing();
71
72 if (fileString != null && !fileString.isEmpty()) {
73 fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
74 return !FileUtils.fileExists(fileString);
75 }
76 } catch (InterpolationException e) {
77 if (logger.isDebugEnabled()) {
78 logger.debug("Failed to interpolate missing file location for profile activator: " + fileString, e);
79 } else {
80 logger.warn("Failed to interpolate missing file location for profile activator: " + fileString
81 + ", enable verbose output (-X) for more details");
82 }
83 }
84 }
85
86 return false;
87 }
88
89 public void enableLogging(Logger logger) {
90 this.logger = logger;
91 }
92 }