1 package org.apache.archiva.repository.content.legacy;
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.archiva.model.ArchivaArtifact;
23 import org.apache.archiva.model.ArtifactReference;
24 import org.apache.archiva.repository.content.PathParser;
25 import org.apache.archiva.repository.content.maven2.ArtifactExtensionMapping;
26 import org.apache.archiva.repository.layout.LayoutException;
27 import org.apache.commons.lang.StringUtils;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import java.util.HashMap;
35 * AbstractLegacyRepositoryContent
39 public abstract class AbstractLegacyRepositoryContent
41 private static final String PATH_SEPARATOR = "/";
43 private static final Map<String, String> typeToDirectoryMap;
47 typeToDirectoryMap = new HashMap<>( 5 );
48 typeToDirectoryMap.put( "ejb-client", "ejb" );
49 typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN, "plugin" );
50 typeToDirectoryMap.put( "distribution-tgz", "distribution" );
51 typeToDirectoryMap.put( "distribution-zip", "distribution" );
52 typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
59 @Named( "pathParser#legacy" )
60 private PathParser legacyPathParser;
62 public ArtifactReference toArtifactReference( String path )
63 throws LayoutException
65 return legacyPathParser.toArtifactReference( path );
68 public String toPath( ArchivaArtifact reference )
70 if ( reference == null )
72 throw new IllegalArgumentException( "Artifact reference cannot be null" );
75 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
76 reference.getClassifier(), reference.getType() );
79 public String toPath( ArtifactReference reference )
81 if ( reference == null )
83 throw new IllegalArgumentException( "Artifact reference cannot be null" );
86 return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
87 reference.getClassifier(), reference.getType() );
90 private String toPath( String groupId, String artifactId, String version, String classifier, String type )
92 StringBuilder path = new StringBuilder();
94 path.append( groupId ).append( PATH_SEPARATOR );
95 path.append( getDirectory( type ) ).append( PATH_SEPARATOR );
97 if ( version != null )
99 path.append( artifactId ).append( '-' ).append( version );
101 if ( StringUtils.isNotBlank( classifier ) )
103 path.append( '-' ).append( classifier );
106 path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
109 return path.toString();
112 private String getDirectory( String type )
114 String dirname = typeToDirectoryMap.get( type );
116 if ( dirname != null )
118 return dirname + "s";
125 public void setLegacyPathParser( PathParser parser )
127 this.legacyPathParser = parser;