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