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" );
52 public ArtifactReference toArtifactReference( String path )
53 throws LayoutException
55 return LegacyPathParser.toArtifactReference( path );
58 public String toPath( ArchivaArtifact reference )
60 if ( reference == null )
62 throw new IllegalArgumentException( "Artifact reference cannot be null" );
65 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
66 .getClassifier(), reference.getType() );
69 public String toPath( ArtifactReference reference )
71 if ( reference == null )
73 throw new IllegalArgumentException( "Artifact reference cannot be null" );
76 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
77 .getClassifier(), reference.getType() );
80 private String toPath( String groupId, String artifactId, String version, String classifier, String type )
82 StringBuffer path = new StringBuffer();
84 path.append( groupId ).append( PATH_SEPARATOR );
85 path.append( getDirectory( classifier, type ) ).append( PATH_SEPARATOR );
87 if ( version != null )
89 path.append( artifactId ).append( '-' ).append( version );
91 if ( StringUtils.isNotBlank( classifier ) )
93 path.append( '-' ).append( classifier );
96 path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
99 return path.toString();
102 private String getDirectory( String classifier, String type )
104 String dirname = (String) typeToDirectoryMap.get( type );
106 if ( dirname != null )
108 return dirname + "s";