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 java.util.HashMap;
24 import java.util.regex.Pattern;
27 * ArtifactExtensionMapping
29 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
32 public class ArtifactExtensionMapping
34 public static final String MAVEN_ARCHETYPE = "maven-archetype";
36 public static final String MAVEN_PLUGIN = "maven-plugin";
38 private static final Map<String, String> typeToExtensionMap;
40 private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" );
44 typeToExtensionMap = new HashMap<String, String>();
45 typeToExtensionMap.put( "ejb-client", "jar" );
46 typeToExtensionMap.put( "ejb", "jar" );
47 typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
48 typeToExtensionMap.put( "distribution-zip", "zip" );
49 typeToExtensionMap.put( "java-source", "jar" );
50 typeToExtensionMap.put( "javadoc.jar", "jar" );
51 typeToExtensionMap.put( "javadoc", "jar" );
52 typeToExtensionMap.put( "aspect", "jar" );
53 typeToExtensionMap.put( "uberjar", "jar" );
54 typeToExtensionMap.put( MAVEN_PLUGIN, "jar" );
55 typeToExtensionMap.put( MAVEN_ARCHETYPE, "jar" );
58 public static String getExtension( String type )
60 // Try specialized types first.
61 if ( typeToExtensionMap.containsKey( type ) )
63 return (String) typeToExtensionMap.get( type );
71 * Determine if a given artifact Id conforms to the naming scheme for a maven plugin.
73 * @param artifactId the artifactId to test.
74 * @return true if this artifactId conforms to the naming scheme for a maven plugin.
76 public static boolean isMavenPlugin( String artifactId )
78 return mavenPluginPattern.matcher( artifactId ).matches();
81 public static String mapExtensionAndClassifierToType( String classifier, String extension )
83 return mapExtensionAndClassifierToType( classifier, extension, extension );
86 public static String mapExtensionAndClassifierToType( String classifier, String extension,
87 String defaultExtension )
89 if ( "sources".equals( classifier ) )
93 else if ( "javadoc".equals( classifier ) )
97 return mapExtensionToType( extension, defaultExtension );
100 public static String mapExtensionToType( String extension )
102 return mapExtensionToType( extension, extension );
105 private static String mapExtensionToType( String extension, String defaultExtension )
107 if ( "tar.gz".equals( extension ) )
109 return "distribution-tgz";
111 else if ( "tar.bz2".equals( extension ) )
113 return "distribution-bzip";
115 else if ( "zip".equals( extension ) )
117 return "distribution-zip";
119 return defaultExtension;