1 package org.apache.maven.profiles.activation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.model.Activation;
23 import org.apache.maven.model.ActivationOS;
24 import org.apache.maven.model.Profile;
25 import org.codehaus.plexus.util.Os;
26
27
28
29
30 @Deprecated
31 public class OperatingSystemProfileActivator
32 implements ProfileActivator
33 {
34
35 public boolean canDetermineActivation( Profile profile )
36 {
37 Activation activation = profile.getActivation();
38 return activation != null && activation.getOs() != null;
39 }
40
41 public boolean isActive( Profile profile )
42 {
43 Activation activation = profile.getActivation();
44 ActivationOS os = activation.getOs();
45
46 boolean result = ensureAtLeastOneNonNull( os );
47
48 if ( result && os.getFamily() != null )
49 {
50 result = determineFamilyMatch( os.getFamily() );
51 }
52 if ( result && os.getName() != null )
53 {
54 result = determineNameMatch( os.getName() );
55 }
56 if ( result && os.getArch() != null )
57 {
58 result = determineArchMatch( os.getArch() );
59 }
60 if ( result && os.getVersion() != null )
61 {
62 result = determineVersionMatch( os.getVersion() );
63 }
64 return result;
65 }
66
67 private boolean ensureAtLeastOneNonNull( ActivationOS os )
68 {
69 return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null;
70 }
71
72 private boolean determineVersionMatch( String version )
73 {
74 String test = version;
75 boolean reverse = false;
76
77 if ( test.startsWith( "!" ) )
78 {
79 reverse = true;
80 test = test.substring( 1 );
81 }
82
83 boolean result = Os.isVersion( test );
84
85 if ( reverse )
86 {
87 return !result;
88 }
89 else
90 {
91 return result;
92 }
93 }
94
95 private boolean determineArchMatch( String arch )
96 {
97 String test = arch;
98 boolean reverse = false;
99
100 if ( test.startsWith( "!" ) )
101 {
102 reverse = true;
103 test = test.substring( 1 );
104 }
105
106 boolean result = Os.isArch( test );
107
108 if ( reverse )
109 {
110 return !result;
111 }
112 else
113 {
114 return result;
115 }
116 }
117
118 private boolean determineNameMatch( String name )
119 {
120 String test = name;
121 boolean reverse = false;
122
123 if ( test.startsWith( "!" ) )
124 {
125 reverse = true;
126 test = test.substring( 1 );
127 }
128
129 boolean result = Os.isName( test );
130
131 if ( reverse )
132 {
133 return !result;
134 }
135 else
136 {
137 return result;
138 }
139 }
140
141 private boolean determineFamilyMatch( String family )
142 {
143 String test = family;
144 boolean reverse = false;
145
146 if ( test.startsWith( "!" ) )
147 {
148 reverse = true;
149 test = test.substring( 1 );
150 }
151
152 boolean result = Os.isFamily( test );
153
154 if ( reverse )
155 {
156 return !result;
157 }
158 else
159 {
160 return result;
161 }
162 }
163
164 }