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.util.Properties;
22
23 import org.apache.maven.model.Activation;
24 import org.apache.maven.model.ActivationProperty;
25 import org.apache.maven.model.Profile;
26 import org.codehaus.plexus.context.Context;
27 import org.codehaus.plexus.context.ContextException;
28 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
29 import org.codehaus.plexus.util.StringUtils;
30
31
32
33
34 @Deprecated
35 public class SystemPropertyProfileActivator extends DetectedProfileActivator implements Contextualizable {
36 private Properties properties;
37
38 public void contextualize(Context context) throws ContextException {
39 properties = (Properties) context.get("SystemProperties");
40 }
41
42 protected boolean canDetectActivation(Profile profile) {
43 return profile.getActivation() != null && profile.getActivation().getProperty() != null;
44 }
45
46 public boolean isActive(Profile profile) throws ProfileActivationException {
47 Activation activation = profile.getActivation();
48
49 ActivationProperty property = activation.getProperty();
50
51 if (property != null) {
52 String name = property.getName();
53 boolean reverseName = false;
54
55 if (name == null) {
56 throw new ProfileActivationException(
57 "The property name is required to activate the profile '" + profile.getId() + "'");
58 }
59
60 if (name.startsWith("!")) {
61 reverseName = true;
62 name = name.substring(1);
63 }
64
65 String sysValue = properties.getProperty(name);
66
67 String propValue = property.getValue();
68 if (StringUtils.isNotEmpty(propValue)) {
69 boolean reverseValue = false;
70 if (propValue.startsWith("!")) {
71 reverseValue = true;
72 propValue = propValue.substring(1);
73 }
74
75
76 boolean result = propValue.equals(sysValue);
77
78 if (reverseValue) {
79 return !result;
80 } else {
81 return result;
82 }
83 } else {
84 boolean result = StringUtils.isNotEmpty(sysValue);
85
86 if (reverseName) {
87 return !result;
88 } else {
89 return result;
90 }
91 }
92 }
93
94 return false;
95 }
96 }