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;
25 import java.util.HashMap;
29 * ArtifactExtensionMapping
31 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
34 public class ArtifactExtensionMapping
36 protected static final Map<String, String> typeToExtensionMap;
40 typeToExtensionMap = new HashMap<String, String>();
41 typeToExtensionMap.put( "ejb-client", "jar" );
42 typeToExtensionMap.put( "ejb", "jar" );
43 typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
44 typeToExtensionMap.put( "distribution-zip", "zip" );
45 typeToExtensionMap.put( "java-source", "jar" );
46 typeToExtensionMap.put( "javadoc.jar", "jar" );
47 typeToExtensionMap.put( "javadoc", "jar" );
48 typeToExtensionMap.put( "aspect", "jar" );
49 typeToExtensionMap.put( "uberjar", "jar" );
50 typeToExtensionMap.put( "plugin", "jar" );
51 typeToExtensionMap.put( "maven-plugin", "jar" );
52 typeToExtensionMap.put( "maven-archetype", "jar" );
55 public static String getExtension( String type )
57 // Try specialized types first.
58 if ( typeToExtensionMap.containsKey( type ) )
60 return (String) typeToExtensionMap.get( type );
67 public static String guessTypeFromFilename( File file )
69 return guessTypeFromFilename( file.getName() );
72 public static String guessTypeFromFilename( String filename )
74 if ( StringUtils.isBlank( filename ) )
79 String normalizedName = filename.toLowerCase().trim();
80 int idx = normalizedName.lastIndexOf( '.' );
87 if ( normalizedName.endsWith( ".tar.gz" ) )
89 return "distribution-tgz";
91 if ( normalizedName.endsWith( ".tar.bz2" ) )
93 return "distribution-bzip";
95 else if ( normalizedName.endsWith( ".zip" ) )
97 return "distribution-zip";
99 else if ( normalizedName.endsWith( "-sources.jar" ) )
101 return "java-source";
103 else if ( normalizedName.endsWith( "-javadoc.jar" ) )
109 return normalizedName.substring( idx + 1 );