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 org.apache.maven.model.Activation;
22 import org.apache.maven.model.ActivationOS;
23 import org.apache.maven.model.Profile;
24 import org.apache.maven.utils.Os;
25
26
27
28
29 @Deprecated
30 public class OperatingSystemProfileActivator implements ProfileActivator {
31
32 public boolean canDetermineActivation(Profile profile) {
33 Activation activation = profile.getActivation();
34 return activation != null && activation.getOs() != null;
35 }
36
37 public boolean isActive(Profile profile) {
38 Activation activation = profile.getActivation();
39 ActivationOS os = activation.getOs();
40
41 boolean result = ensureAtLeastOneNonNull(os);
42
43 if (result && os.getFamily() != null) {
44 result = determineFamilyMatch(os.getFamily());
45 }
46 if (result && os.getName() != null) {
47 result = determineNameMatch(os.getName());
48 }
49 if (result && os.getArch() != null) {
50 result = determineArchMatch(os.getArch());
51 }
52 if (result && os.getVersion() != null) {
53 result = determineVersionMatch(os.getVersion());
54 }
55 return result;
56 }
57
58 private boolean ensureAtLeastOneNonNull(ActivationOS os) {
59 return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null;
60 }
61
62 private boolean determineVersionMatch(String version) {
63 String test = version;
64 boolean reverse = false;
65
66 if (test.startsWith("!")) {
67 reverse = true;
68 test = test.substring(1);
69 }
70
71 boolean result = Os.OS_VERSION.equals(test);
72
73 if (reverse) {
74 return !result;
75 } else {
76 return result;
77 }
78 }
79
80 private boolean determineArchMatch(String arch) {
81 String test = arch;
82 boolean reverse = false;
83
84 if (test.startsWith("!")) {
85 reverse = true;
86 test = test.substring(1);
87 }
88
89 boolean result = Os.OS_ARCH.equals(test);
90
91 if (reverse) {
92 return !result;
93 } else {
94 return result;
95 }
96 }
97
98 private boolean determineNameMatch(String name) {
99 String test = name;
100 boolean reverse = false;
101
102 if (test.startsWith("!")) {
103 reverse = true;
104 test = test.substring(1);
105 }
106
107 boolean result = Os.OS_NAME.equals(test);
108
109 if (reverse) {
110 return !result;
111 } else {
112 return result;
113 }
114 }
115
116 private boolean determineFamilyMatch(String family) {
117 String test = family;
118 boolean reverse = false;
119
120 if (test.startsWith("!")) {
121 reverse = true;
122 test = test.substring(1);
123 }
124
125 boolean result = Os.isFamily(test);
126
127 if (reverse) {
128 return !result;
129 } else {
130 return result;
131 }
132 }
133 }