1 package org.apache.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.archiva.model.ArchivaArtifact;
24 import org.apache.archiva.model.ArtifactReference;
25 import org.apache.archiva.repository.layout.LayoutException;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import java.util.HashMap;
33 * AbstractLegacyRepositoryContent
37 public abstract class AbstractLegacyRepositoryContent
39 private static final String PATH_SEPARATOR = "/";
41 private static final Map<String, String> typeToDirectoryMap;
45 typeToDirectoryMap = new HashMap<String, String>();
46 typeToDirectoryMap.put( "ejb-client", "ejb" );
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" );
57 @Named( value = "pathParser#legacy" )
58 private PathParser legacyPathParser;
60 public ArtifactReference toArtifactReference( String path )
61 throws LayoutException
63 return legacyPathParser.toArtifactReference( path );
66 public String toPath( ArchivaArtifact reference )
68 if ( reference == null )
70 throw new IllegalArgumentException( "Artifact reference cannot be null" );
73 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
74 reference.getClassifier(), reference.getType() );
77 public String toPath( ArtifactReference reference )
79 if ( reference == null )
81 throw new IllegalArgumentException( "Artifact reference cannot be null" );
84 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
85 reference.getClassifier(), reference.getType() );
88 private String toPath( String groupId, String artifactId, String version, String classifier, String type )
90 StringBuilder path = new StringBuilder();
92 path.append( groupId ).append( PATH_SEPARATOR );
93 path.append( getDirectory( type ) ).append( PATH_SEPARATOR );
95 if ( version != null )
97 path.append( artifactId ).append( '-' ).append( version );
99 if ( StringUtils.isNotBlank( classifier ) )
101 path.append( '-' ).append( classifier );
104 path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
107 return path.toString();
110 private String getDirectory( String type )
112 String dirname = typeToDirectoryMap.get( type );
114 if ( dirname != null )
116 return dirname + "s";
123 public void setLegacyPathParser( PathParser parser )
125 this.legacyPathParser = parser;