KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > profiles > activation > SystemPropertyProfileActivator


1 package org.apache.maven.profiles.activation;
2
3 import org.apache.maven.model.Activation;
4 import org.apache.maven.model.ActivationProperty;
5 import org.apache.maven.model.Profile;
6 import org.codehaus.plexus.util.StringUtils;
7
8 /*
9  * Copyright 2001-2005 The Apache Software Foundation.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */

23
24 public class SystemPropertyProfileActivator
25     extends DetectedProfileActivator
26 {
27     protected boolean canDetectActivation( Profile profile )
28     {
29         return profile.getActivation() != null && profile.getActivation().getProperty() != null;
30     }
31
32     public boolean isActive( Profile profile )
33     {
34         Activation activation = profile.getActivation();
35
36         ActivationProperty property = activation.getProperty();
37
38         if ( property != null )
39         {
40             String JavaDoc name = property.getName();
41             boolean reverseName = false;
42             
43             if ( name.startsWith("!") )
44             {
45                 reverseName = true;
46                 name = name.substring( 1 );
47             }
48             
49             String JavaDoc sysValue = System.getProperty( name );
50
51             String JavaDoc propValue = property.getValue();
52             if ( StringUtils.isNotEmpty( propValue ) )
53             {
54                 boolean reverseValue = false;
55                 if ( propValue.startsWith( "!" ) )
56                 {
57                     reverseValue = true;
58                     propValue = propValue.substring( 1 );
59                 }
60                 
61                 // we have a value, so it has to match the system value...
62
boolean result = propValue.equals( sysValue );
63                 
64                 if ( reverseValue )
65                 {
66                     return !result;
67                 }
68                 else
69                 {
70                     return result;
71                 }
72             }
73             else
74             {
75                 boolean result = StringUtils.isNotEmpty( sysValue );
76                 
77                 if ( reverseName )
78                 {
79                     return !result;
80                 }
81                 else
82                 {
83                     return result;
84                 }
85             }
86         }
87
88         return false;
89     }
90
91 }
92
Popular Tags