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.File;
22 import java.io.IOException;
23
24 import org.apache.maven.model.Activation;
25 import org.apache.maven.model.ActivationFile;
26 import org.apache.maven.model.Profile;
27 import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
28 import org.codehaus.plexus.interpolation.InterpolationException;
29 import org.codehaus.plexus.interpolation.MapBasedValueSource;
30 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
31 import org.codehaus.plexus.logging.LogEnabled;
32 import org.codehaus.plexus.logging.Logger;
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 (fileString != null && !fileString.isEmpty()) {
64 fileString = interpolator.interpolate(fileString, "").replace("\\", "/");
65 File file = new File(fileString);
66 return file.exists();
67 }
68
69
70 fileString = actFile.getMissing();
71
72 if (fileString != null && !fileString.isEmpty()) {
73 fileString = interpolator.interpolate(fileString, "").replace("\\", "/");
74 File file = new File(fileString);
75 return !file.exists();
76 }
77 } catch (InterpolationException e) {
78 if (logger.isDebugEnabled()) {
79 logger.debug("Failed to interpolate missing file location for profile activator: " + fileString, e);
80 } else {
81 logger.warn("Failed to interpolate missing file location for profile activator: " + fileString
82 + ", enable verbose output (-X) for more details");
83 }
84 }
85 }
86
87 return false;
88 }
89
90 public void enableLogging(Logger logger) {
91 this.logger = logger;
92 }
93 }