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