Coverage Report - org.apache.maven.profiles.activation.OperatingSystemProfileActivator
 
Classes in this File Line Coverage Branch Coverage Complexity
OperatingSystemProfileActivator
0%
0/52
0%
0/52
3.286
 
 1  
 package org.apache.maven.profiles.activation;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 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  0
 public class OperatingSystemProfileActivator
 28  
     implements ProfileActivator
 29  
 {
 30  
 
 31  
     public boolean canDetermineActivation( Profile profile )
 32  
     {
 33  0
         Activation activation = profile.getActivation();
 34  0
         return activation != null && activation.getOs() != null;
 35  
     }
 36  
 
 37  
     public boolean isActive( Profile profile )
 38  
     {
 39  0
         Activation activation = profile.getActivation();
 40  0
         ActivationOS os = activation.getOs();
 41  
 
 42  0
         boolean result = ensureAtLeastOneNonNull( os );
 43  
 
 44  0
         if ( result && os.getFamily() != null )
 45  
         {
 46  0
             result = determineFamilyMatch( os.getFamily() );
 47  
         }
 48  0
         if ( result && os.getName() != null )
 49  
         {
 50  0
             result = determineNameMatch( os.getName() );
 51  
         }
 52  0
         if ( result && os.getArch() != null )
 53  
         {
 54  0
             result = determineArchMatch( os.getArch() );
 55  
         }
 56  0
         if ( result && os.getVersion() != null )
 57  
         {
 58  0
             result = determineVersionMatch( os.getVersion() );
 59  
         }
 60  0
         return result;
 61  
     }
 62  
 
 63  
     private boolean ensureAtLeastOneNonNull( ActivationOS os )
 64  
     {
 65  0
         return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null;
 66  
     }
 67  
 
 68  
     private boolean determineVersionMatch( String version )
 69  
     {
 70  0
         String test = version;
 71  0
         boolean reverse = false;
 72  
         
 73  0
         if ( test.startsWith( "!" ) )
 74  
         {
 75  0
             reverse = true;
 76  0
             test = test.substring( 1 );
 77  
         }
 78  
         
 79  0
         boolean result = Os.isVersion( test );
 80  
         
 81  0
         if ( reverse )
 82  
         {
 83  0
             return !result;
 84  
         }
 85  
         else
 86  
         {
 87  0
             return result;
 88  
         }
 89  
     }
 90  
 
 91  
     private boolean determineArchMatch( String arch )
 92  
     {
 93  0
         String test = arch;
 94  0
         boolean reverse = false;
 95  
         
 96  0
         if ( test.startsWith( "!" ) )
 97  
         {
 98  0
             reverse = true;
 99  0
             test = test.substring( 1 );
 100  
         }
 101  
         
 102  0
         boolean result = Os.isArch( test );
 103  
         
 104  0
         if ( reverse )
 105  
         {
 106  0
             return !result;
 107  
         }
 108  
         else
 109  
         {
 110  0
             return result;
 111  
         }
 112  
     }
 113  
 
 114  
     private boolean determineNameMatch( String name )
 115  
     {
 116  0
         String test = name;
 117  0
         boolean reverse = false;
 118  
         
 119  0
         if ( test.startsWith( "!" ) )
 120  
         {
 121  0
             reverse = true;
 122  0
             test = test.substring( 1 );
 123  
         }
 124  
 
 125  0
         boolean result = Os.isName( test );
 126  
 
 127  0
         if ( reverse )
 128  
         {
 129  0
             return !result;
 130  
         }
 131  
         else
 132  
         {
 133  0
             return result;
 134  
         }
 135  
     }
 136  
 
 137  
     private boolean determineFamilyMatch( String family )
 138  
     {
 139  0
         String test = family;
 140  0
         boolean reverse = false;
 141  
         
 142  0
         if ( test.startsWith( "!" ) )
 143  
         {
 144  0
             reverse = true;
 145  0
             test = test.substring( 1 );
 146  
         }
 147  
         
 148  0
         boolean result = Os.isFamily( test );
 149  
         
 150  0
         if ( reverse )
 151  
         {
 152  0
             return !result;
 153  
         }
 154  
         else
 155  
         {
 156  0
             return result;
 157  
         }
 158  
     }
 159  
 
 160  
 }