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, "plugin" );
47 typeToDirectoryMap.put( "distribution-tgz", "distribution" );
48 typeToDirectoryMap.put( "distribution-zip", "distribution" );
49 typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
53 * @plexus.requirement role-hint="legacy"
55 private PathParser legacyPathParser;
57 public ArtifactReference toArtifactReference( String path )
58 throws LayoutException
60 return legacyPathParser.toArtifactReference( path );
63 public String toPath( ArchivaArtifact reference )
65 if ( reference == null )
67 throw new IllegalArgumentException( "Artifact reference cannot be null" );
70 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
71 .getClassifier(), reference.getType() );
74 public String toPath( ArtifactReference reference )
76 if ( reference == null )
78 throw new IllegalArgumentException( "Artifact reference cannot be null" );
81 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
82 .getClassifier(), reference.getType() );
85 private String toPath( String groupId, String artifactId, String version, String classifier, String type )
87 StringBuffer path = new StringBuffer();
89 path.append( groupId ).append( PATH_SEPARATOR );
90 path.append( getDirectory( classifier, type ) ).append( PATH_SEPARATOR );
92 if ( version != null )
94 path.append( artifactId ).append( '-' ).append( version );
96 if ( StringUtils.isNotBlank( classifier ) )
98 path.append( '-' ).append( classifier );
101 path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
104 return path.toString();
107 private String getDirectory( String classifier, String type )
109 String dirname = (String) typeToDirectoryMap.get( type );
111 if ( dirname != null )
113 return dirname + "s";