Coverage Report - org.apache.maven.wagon.proxy.ProxyUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
ProxyUtils
88%
15/17
100%
10/10
5
 
 1  
 package org.apache.maven.wagon.proxy;
 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 java.util.StringTokenizer;
 23  
 
 24  
 /**
 25  
  * @author <a href="mailto:lafeuil@gmail.com">Thomas Champagne</a>
 26  
  */
 27  
 public final class ProxyUtils
 28  
 {
 29  
     private ProxyUtils()
 30  0
     {
 31  0
     }
 32  
 
 33  
     /**
 34  
      * Check if the specified host is in the list of non proxy hosts.
 35  
      * 
 36  
      * @param proxy the proxy info object contains set of properties.
 37  
      * @param targetHost the target hostname
 38  
      * @return true if the hostname is in the list of non proxy hosts, false otherwise.
 39  
      */
 40  
     public static boolean validateNonProxyHosts( ProxyInfo proxy, String targetHost )
 41  
     {
 42  22
         if ( targetHost == null )
 43  
         {
 44  1
             targetHost = new String();
 45  
         }
 46  22
         if ( proxy == null )
 47  
         {
 48  10
             return false;
 49  
         }
 50  12
         String nonProxyHosts = proxy.getNonProxyHosts();
 51  12
         if ( nonProxyHosts == null )
 52  
         {
 53  5
             return false;
 54  
         }
 55  
 
 56  7
         StringTokenizer tokenizer = new StringTokenizer( nonProxyHosts, "|" );
 57  
 
 58  12
         while ( tokenizer.hasMoreTokens() )
 59  
         {
 60  8
             String pattern = tokenizer.nextToken();
 61  8
             pattern = pattern.replaceAll( "\\.", "\\\\." ).replaceAll( "\\*", ".*" );
 62  8
             if ( targetHost.matches( pattern ) )
 63  
             {
 64  3
                 return true;
 65  
             }
 66  5
         }
 67  4
         return false;
 68  
     }
 69  
 }