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