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 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 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 sysValue = System.getProperty( name ); 50 51 String 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 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 |