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;
27 import java.util.regex.Pattern;
30 * ArtifactExtensionMapping
32 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
35 public class ArtifactExtensionMapping
37 public static final String MAVEN_ARCHETYPE = "maven-archetype";
39 public static final String MAVEN_PLUGIN = "maven-plugin";
41 private static final Map<String, String> typeToExtensionMap;
43 private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" );
47 typeToExtensionMap = new HashMap<String, String>();
48 typeToExtensionMap.put( "ejb-client", "jar" );
49 typeToExtensionMap.put( "ejb", "jar" );
50 typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
51 typeToExtensionMap.put( "distribution-zip", "zip" );
52 typeToExtensionMap.put( "java-source", "jar" );
53 typeToExtensionMap.put( "javadoc.jar", "jar" );
54 typeToExtensionMap.put( "javadoc", "jar" );
55 typeToExtensionMap.put( "aspect", "jar" );
56 typeToExtensionMap.put( "uberjar", "jar" );
57 typeToExtensionMap.put( MAVEN_PLUGIN, "jar" );
58 typeToExtensionMap.put( MAVEN_ARCHETYPE, "jar" );
61 public static String getExtension( String type )
63 // Try specialized types first.
64 if ( typeToExtensionMap.containsKey( type ) )
66 return (String) typeToExtensionMap.get( type );
70 return type.replace( '-', '.' );
73 public static String guessTypeFromFilename( File file )
75 return guessTypeFromFilename( file.getName() );
78 public static String guessTypeFromFilename( String filename )
80 if ( StringUtils.isBlank( filename ) )
85 String normalizedName = filename.toLowerCase().trim();
86 int idx = normalizedName.lastIndexOf( '.' );
93 if ( normalizedName.endsWith( ".tar.gz" ) )
95 return "distribution-tgz";
97 if ( normalizedName.endsWith( ".tar.bz2" ) )
99 return "distribution-bzip";
101 else if ( normalizedName.endsWith( ".zip" ) )
103 return "distribution-zip";
105 else if ( normalizedName.endsWith( "-sources.jar" ) )
107 return "java-source";
109 else if ( normalizedName.endsWith( "-javadoc.jar" ) )
115 return normalizedName.substring( idx + 1 );
120 * Determine if a given artifact Id conforms to the naming scheme for a maven plugin.
122 * @param artifactId the artifactId to test.
123 * @return true if this artifactId conforms to the naming scheme for a maven plugin.
125 public static boolean isMavenPlugin( String artifactId )
127 return mavenPluginPattern.matcher( artifactId ).matches();