1 package org.apache.maven.archiva.repository.content;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
27 import java.util.HashMap;
31 * AbstractLegacyRepositoryContent
33 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
36 public abstract class AbstractLegacyRepositoryContent
38 private static final String PATH_SEPARATOR = "/";
40 private static final Map<String, String> typeToDirectoryMap;
44 typeToDirectoryMap = new HashMap<String, String>();
45 typeToDirectoryMap.put( "ejb-client", "ejb" );
46 typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_PLUGIN, "maven-plugin" );
47 typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN, "plugin" );
48 typeToDirectoryMap.put( "distribution-tgz", "distribution" );
49 typeToDirectoryMap.put( "distribution-zip", "distribution" );
50 typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
54 * @plexus.requirement role-hint="legacy"
56 private PathParser legacyPathParser;
58 public ArtifactReference toArtifactReference( String path )
59 throws LayoutException
61 return legacyPathParser.toArtifactReference( path );
64 public String toPath( ArchivaArtifact reference )
66 if ( reference == null )
68 throw new IllegalArgumentException( "Artifact reference cannot be null" );
71 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
72 .getClassifier(), reference.getType() );
75 public String toPath( ArtifactReference reference )
77 if ( reference == null )
79 throw new IllegalArgumentException( "Artifact reference cannot be null" );
82 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
83 .getClassifier(), reference.getType() );
86 private String toPath( String groupId, String artifactId, String version, String classifier, String type )
88 StringBuffer path = new StringBuffer();
90 path.append( groupId ).append( PATH_SEPARATOR );
91 path.append( getDirectory( classifier, type ) ).append( PATH_SEPARATOR );
93 if ( version != null )
95 path.append( artifactId ).append( '-' ).append( version );
97 if ( StringUtils.isNotBlank( classifier ) )
99 path.append( '-' ).append( classifier );
102 path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
105 return path.toString();
108 private String getDirectory( String classifier, String type )
110 String dirname = (String) typeToDirectoryMap.get( type );
112 if ( dirname != null )
114 return dirname + "s";