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 DIR_JAVADOC = "javadoc.jars";
40 private static final String DIR_JAVA_SOURCE = "java-sources";
42 private static final String PATH_SEPARATOR = "/";
44 private static final Map<String, String> typeToDirectoryMap;
48 typeToDirectoryMap = new HashMap<String, String>();
49 typeToDirectoryMap.put( "ejb-client", "ejb" );
50 typeToDirectoryMap.put( "distribution-tgz", "distribution" );
51 typeToDirectoryMap.put( "distribution-zip", "distribution" );
54 public ArtifactReference toArtifactReference( String path )
55 throws LayoutException
57 return LegacyPathParser.toArtifactReference( path );
60 public String toPath( ArchivaArtifact reference )
62 if ( reference == null )
64 throw new IllegalArgumentException( "Artifact reference cannot be null" );
67 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
68 .getClassifier(), reference.getType() );
71 public String toPath( ArtifactReference reference )
73 if ( reference == null )
75 throw new IllegalArgumentException( "Artifact reference cannot be null" );
78 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
79 .getClassifier(), reference.getType() );
82 private String toPath( String groupId, String artifactId, String version, String classifier, String type )
84 StringBuffer path = new StringBuffer();
86 path.append( groupId ).append( PATH_SEPARATOR );
87 path.append( getDirectory( classifier, type ) ).append( PATH_SEPARATOR );
89 if ( version != null )
91 path.append( artifactId ).append( '-' ).append( version );
93 if ( StringUtils.isNotBlank( classifier ) )
95 path.append( '-' ).append( classifier );
98 path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
101 return path.toString();
104 private String getDirectory( String classifier, String type )
106 // Special Cases involving type + classifier
107 if ( "jar".equals( type ) && StringUtils.isNotBlank( classifier ) )
109 if ( "sources".equals( classifier ) )
111 return DIR_JAVA_SOURCE;
114 if ( "javadoc".equals( classifier ) )
120 // Special Cases involving only type.
121 String dirname = (String) typeToDirectoryMap.get( type );
123 if ( dirname != null )
125 return dirname + "s";