Coverage Report - org.codehaus.plexus.classworlds.UrlUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
UrlUtils
53 %
7/13
62 %
5/8
3
 
 1  
 package org.codehaus.plexus.classworlds;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.net.URL;
 20  
 import java.net.URLClassLoader;
 21  
 import java.util.HashSet;
 22  
 import java.util.Set;
 23  
 
 24  
 /**
 25  
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
 26  
  */
 27  0
 public class UrlUtils
 28  
 {
 29  
     public static String normalizeUrlPath( String name )
 30  
     {
 31  3
         if ( name.startsWith( "/" ) )
 32  
         {
 33  0
             name = name.substring( 1 );
 34  
         }
 35  
 
 36  
         // Looking for org/codehaus/werkflow/personality/basic/../common/core-idioms.xml
 37  
         //                                               |    i  |
 38  
         //                                               +-------+ remove
 39  
         //
 40  3
         int i = name.indexOf( "/.." );
 41  
 
 42  
         // Can't be at the beginning because we have no root to refer to so
 43  
         // we start at 1.
 44  3
         if ( i > 0 )
 45  
         {
 46  2
             int j = name.lastIndexOf( "/", i - 1 );
 47  
 
 48  2
             if ( j >= 0 )
 49  
             {
 50  1
                 name = name.substring( 0, j ) + name.substring( i + 3 );
 51  
             }
 52  
         }
 53  
 
 54  3
         return name;
 55  
     }
 56  
 
 57  
     public static Set<URL> getURLs( URLClassLoader loader )
 58  
     {
 59  0
         Set<URL> ret = new HashSet<URL>();
 60  
 
 61  0
         for ( URL url : loader.getURLs() )
 62  
         {
 63  0
             ret.add( url );
 64  
         }
 65  
 
 66  0
         return ret;
 67  
     }
 68  
 }