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