Coverage Report - org.apache.maven.archiva.repository.content.AbstractLegacyRepositoryContent
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractLegacyRepositoryContent
0%
0/31
0%
0/10
0
 
 1  
 package org.apache.maven.archiva.repository.content;
 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.commons.lang.StringUtils;
 23  
 import org.apache.maven.archiva.model.ArchivaArtifact;
 24  
 import org.apache.maven.archiva.model.ArtifactReference;
 25  
 import org.apache.maven.archiva.repository.layout.LayoutException;
 26  
 
 27  
 import java.util.HashMap;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * AbstractLegacyRepositoryContent
 32  
  *
 33  
  * @version $Id: AbstractLegacyRepositoryContent.java 718864 2008-11-19 06:33:35Z brett $
 34  
  */
 35  0
 public abstract class AbstractLegacyRepositoryContent
 36  
 {
 37  
     private static final String PATH_SEPARATOR = "/";
 38  
 
 39  
     private static final Map<String, String> typeToDirectoryMap;
 40  
 
 41  
     static
 42  
     {
 43  0
         typeToDirectoryMap = new HashMap<String, String>();
 44  0
         typeToDirectoryMap.put( "ejb-client", "ejb" );
 45  0
         typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_PLUGIN, "maven-plugin" );
 46  0
         typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN, "plugin" );
 47  0
         typeToDirectoryMap.put( "distribution-tgz", "distribution" );
 48  0
         typeToDirectoryMap.put( "distribution-zip", "distribution" );
 49  0
         typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
 50  0
     }
 51  
 
 52  
     /**
 53  
      * @plexus.requirement role-hint="legacy"
 54  
      */
 55  
     private PathParser legacyPathParser;
 56  
 
 57  
     public ArtifactReference toArtifactReference( String path )
 58  
         throws LayoutException
 59  
     {
 60  0
         return legacyPathParser.toArtifactReference( path );
 61  
     }
 62  
 
 63  
     public String toPath( ArchivaArtifact reference )
 64  
     {
 65  0
         if ( reference == null )
 66  
         {
 67  0
             throw new IllegalArgumentException( "Artifact reference cannot be null" );
 68  
         }
 69  
 
 70  0
         return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
 71  
             .getClassifier(), reference.getType() );
 72  
     }
 73  
 
 74  
     public String toPath( ArtifactReference reference )
 75  
     {
 76  0
         if ( reference == null )
 77  
         {
 78  0
             throw new IllegalArgumentException( "Artifact reference cannot be null" );
 79  
         }
 80  
 
 81  0
         return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
 82  
             .getClassifier(), reference.getType() );
 83  
     }
 84  
 
 85  
     private String toPath( String groupId, String artifactId, String version, String classifier, String type )
 86  
     {
 87  0
         StringBuffer path = new StringBuffer();
 88  
 
 89  0
         path.append( groupId ).append( PATH_SEPARATOR );
 90  0
         path.append( getDirectory( classifier, type ) ).append( PATH_SEPARATOR );
 91  
 
 92  0
         if ( version != null )
 93  
         {
 94  0
             path.append( artifactId ).append( '-' ).append( version );
 95  
 
 96  0
             if ( StringUtils.isNotBlank( classifier ) )
 97  
             {
 98  0
                 path.append( '-' ).append( classifier );
 99  
             }
 100  
 
 101  0
             path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
 102  
         }
 103  
 
 104  0
         return path.toString();
 105  
     }
 106  
 
 107  
     private String getDirectory( String classifier, String type )
 108  
     {
 109  0
         String dirname = (String) typeToDirectoryMap.get( type );
 110  
 
 111  0
         if ( dirname != null )
 112  
         {
 113  0
             return dirname + "s";
 114  
         }
 115  
 
 116  
         // Default process.
 117  0
         return type + "s";
 118  
     }
 119  
     
 120  
     public void setLegacyPathParser( PathParser parser )
 121  
     {
 122  0
         this.legacyPathParser = parser;
 123  0
     }
 124  
 }