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