Coverage Report - org.apache.maven.plugin.assembly.io.PrefixedClasspathLocatorStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
PrefixedClasspathLocatorStrategy
92%
12/13
75%
6/8
2
 
 1  
 package org.apache.maven.plugin.assembly.io;
 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.shared.io.location.ClasspathResourceLocatorStrategy;
 23  
 import org.apache.maven.shared.io.location.Location;
 24  
 import org.apache.maven.shared.io.logging.MessageHolder;
 25  
 
 26  
 /**
 27  
  * @version $Id: PrefixedClasspathLocatorStrategy.java 887583 2009-12-05 19:43:54Z bentmann $
 28  
  */
 29  
 public class PrefixedClasspathLocatorStrategy
 30  
     extends ClasspathResourceLocatorStrategy
 31  
 {
 32  
 
 33  
     private final String prefix;
 34  
 
 35  
     public PrefixedClasspathLocatorStrategy( String prefix )
 36  36
     {
 37  36
         this.prefix = formatPrefix( prefix );
 38  36
     }
 39  
 
 40  
     private String formatPrefix( String prefix )
 41  
     {
 42  36
         if ( prefix.startsWith( "/" ) )
 43  
         {
 44  30
             prefix = prefix.substring( 1 );
 45  
         }
 46  
 
 47  36
         if ( prefix.length() > 0 && !prefix.endsWith( "/" ) )
 48  
         {
 49  6
             prefix += "/";
 50  
         }
 51  
 
 52  36
         return prefix;
 53  
     }
 54  
 
 55  
     public Location resolve( String locationSpecification, MessageHolder messageHolder )
 56  
     {
 57  12
         String spec = formatLocation( locationSpecification );
 58  
 
 59  12
         return super.resolve( spec, messageHolder );
 60  
     }
 61  
 
 62  
     private String formatLocation( String location )
 63  
     {
 64  12
         if ( location.startsWith( "/" ) )
 65  
         {
 66  0
             location = location.substring( 1 );
 67  
         }
 68  
 
 69  12
         return prefix + location;
 70  
     }
 71  
 
 72  
 }