Coverage Report - org.apache.maven.archiva.repository.content.AbstractDefaultRepositoryContent
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractDefaultRepositoryContent
0%
0/36
0%
0/14
2.143
 
 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.common.utils.VersionUtil;
 24  
 import org.apache.maven.archiva.model.ArchivaArtifact;
 25  
 import org.apache.maven.archiva.model.ArtifactReference;
 26  
 import org.apache.maven.archiva.model.ProjectReference;
 27  
 import org.apache.maven.archiva.model.VersionedReference;
 28  
 import org.apache.maven.archiva.repository.layout.LayoutException;
 29  
 import org.slf4j.Logger;
 30  
 import org.slf4j.LoggerFactory;
 31  
 
 32  
 /**
 33  
  * AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout.
 34  
  *
 35  
  * @version $Id: AbstractDefaultRepositoryContent.java 751940 2009-03-10 01:35:35Z brett $
 36  
  */
 37  0
 public abstract class AbstractDefaultRepositoryContent
 38  
 {
 39  0
     protected Logger log = LoggerFactory.getLogger( AbstractDefaultRepositoryContent.class );
 40  
 
 41  
     public static final String MAVEN_METADATA = "maven-metadata.xml";
 42  
 
 43  
     protected static final char PATH_SEPARATOR = '/';
 44  
 
 45  
     protected static final char GROUP_SEPARATOR = '.';
 46  
 
 47  
     protected static final char ARTIFACT_SEPARATOR = '-';
 48  
 
 49  0
     private PathParser defaultPathParser = new DefaultPathParser();
 50  
 
 51  
     public ArtifactReference toArtifactReference( String path )
 52  
         throws LayoutException
 53  
     {
 54  0
         return defaultPathParser.toArtifactReference( path );
 55  
     }
 56  
 
 57  
     public String toMetadataPath( ProjectReference reference )
 58  
     {
 59  0
         StringBuffer path = new StringBuffer();
 60  
 
 61  0
         path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
 62  0
         path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
 63  0
         path.append( MAVEN_METADATA );
 64  
 
 65  0
         return path.toString();
 66  
     }
 67  
 
 68  
     public String toMetadataPath( VersionedReference reference )
 69  
     {
 70  0
         StringBuffer path = new StringBuffer();
 71  
 
 72  0
         path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
 73  0
         path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
 74  0
         if ( reference.getVersion() != null )
 75  
         {
 76  
             // add the version only if it is present
 77  0
             path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR );
 78  
         }
 79  0
         path.append( MAVEN_METADATA );
 80  
 
 81  0
         return path.toString();
 82  
     }
 83  
 
 84  
     public String toPath( ArchivaArtifact reference )
 85  
     {
 86  0
         if ( reference == null )
 87  
         {
 88  0
             throw new IllegalArgumentException( "ArchivaArtifact cannot be null" );
 89  
         }
 90  
 
 91  0
         String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
 92  0
         return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
 93  
                        reference.getClassifier(), reference.getType() );
 94  
     }
 95  
 
 96  
     public String toPath( ArtifactReference reference )
 97  
     {
 98  0
         if ( reference == null )
 99  
         {
 100  0
             throw new IllegalArgumentException( "Artifact reference cannot be null" );
 101  
         }
 102  
 
 103  0
         String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
 104  0
         return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
 105  
                        reference.getClassifier(), reference.getType() );
 106  
     }
 107  
 
 108  
     private String formatAsDirectory( String directory )
 109  
     {
 110  0
         return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
 111  
     }
 112  
 
 113  
     private String toPath( String groupId, String artifactId, String baseVersion, String version, String classifier,
 114  
                            String type )
 115  
     {
 116  0
         StringBuffer path = new StringBuffer();
 117  
 
 118  0
         path.append( formatAsDirectory( groupId ) ).append( PATH_SEPARATOR );
 119  0
         path.append( artifactId ).append( PATH_SEPARATOR );
 120  
 
 121  0
         if ( baseVersion != null )
 122  
         {
 123  0
             path.append( baseVersion ).append( PATH_SEPARATOR );
 124  0
             if ( ( version != null ) && ( type != null ) )
 125  
             {
 126  0
                 path.append( artifactId ).append( ARTIFACT_SEPARATOR ).append( version );
 127  
 
 128  0
                 if ( StringUtils.isNotBlank( classifier ) )
 129  
                 {
 130  0
                     path.append( ARTIFACT_SEPARATOR ).append( classifier );
 131  
                 }
 132  
 
 133  0
                 path.append( GROUP_SEPARATOR ).append( ArtifactExtensionMapping.getExtension( type ) );
 134  
             }
 135  
         }
 136  
 
 137  0
         return path.toString();
 138  
     }
 139  
 }