Coverage Report - org.apache.maven.archiva.repository.content.ArtifactExtensionMapping
 
Classes in this File Line Coverage Branch Coverage Complexity
ArtifactExtensionMapping
0%
0/56
0%
0/22
0
 
 1  
 package org.apache.maven.archiva.repository.content;
 2  
 
 3  
 /*
 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
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 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
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.HashMap;
 23  
 import java.util.Map;
 24  
 import java.util.regex.Pattern;
 25  
 
 26  
 /**
 27  
  * ArtifactExtensionMapping
 28  
  *
 29  
  * @version $Id: ArtifactExtensionMapping.java 952596 2010-06-08 10:00:39Z oching $
 30  
  */
 31  0
 public class ArtifactExtensionMapping
 32  
 {
 33  
     public static final String MAVEN_ARCHETYPE = "maven-archetype";
 34  
 
 35  
     public static final String MAVEN_PLUGIN = "maven-plugin";
 36  
         
 37  
         public static final String MAVEN_ONE_PLUGIN = "maven-one-plugin";
 38  
 
 39  
     private static final Map<String, String> typeToExtensionMap;
 40  
 
 41  0
     private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" );
 42  
 
 43  
     static
 44  
     {
 45  0
         typeToExtensionMap = new HashMap<String, String>();
 46  0
         typeToExtensionMap.put( "ejb-client", "jar" );
 47  0
         typeToExtensionMap.put( "ejb", "jar" );
 48  0
         typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
 49  0
         typeToExtensionMap.put( "distribution-zip", "zip" );
 50  0
         typeToExtensionMap.put( "java-source", "jar" );
 51  0
         typeToExtensionMap.put( "javadoc.jar", "jar" );
 52  0
         typeToExtensionMap.put( "javadoc", "jar" );
 53  0
         typeToExtensionMap.put( "aspect", "jar" );
 54  0
         typeToExtensionMap.put( "uberjar", "jar" );
 55  0
         typeToExtensionMap.put( MAVEN_PLUGIN, "jar" );
 56  0
         typeToExtensionMap.put( MAVEN_ONE_PLUGIN, "jar" );
 57  0
         typeToExtensionMap.put( MAVEN_ARCHETYPE, "jar" );
 58  
 
 59  
         // NPanday types
 60  0
         typeToExtensionMap.put( "library", "dll" );
 61  0
         typeToExtensionMap.put( "asp", "dll" );
 62  0
         typeToExtensionMap.put( "gac", "dll" );
 63  0
         typeToExtensionMap.put( "gac_generic", "dll" );
 64  0
         typeToExtensionMap.put( "gac_msil", "dll" );
 65  0
         typeToExtensionMap.put( "gac_32", "dll" );
 66  0
         typeToExtensionMap.put( "netplugin", "dll" );
 67  0
         typeToExtensionMap.put( "visual-studio-addin", "dll" );
 68  0
         typeToExtensionMap.put( "module", "netmodule" );
 69  0
         typeToExtensionMap.put( "exe.config", "exe.config" );
 70  0
         typeToExtensionMap.put( "winexe", "exe" );
 71  0
         typeToExtensionMap.put( "nar", "nar" );
 72  0
     }
 73  
 
 74  
     public static String getExtension( String type )
 75  
     {
 76  
         // Try specialized types first.
 77  0
         if ( typeToExtensionMap.containsKey( type ) )
 78  
         {
 79  0
             return typeToExtensionMap.get( type );
 80  
         }
 81  
 
 82  
         // Return type
 83  0
         return type;
 84  
     }
 85  
 
 86  
     /**
 87  
      * Determine if a given artifact Id conforms to the naming scheme for a maven plugin.
 88  
      *
 89  
      * @param artifactId the artifactId to test.
 90  
      * @return true if this artifactId conforms to the naming scheme for a maven plugin.
 91  
      */
 92  
     public static boolean isMavenPlugin( String artifactId )
 93  
     {
 94  0
         return mavenPluginPattern.matcher( artifactId ).matches();
 95  
     }
 96  
 
 97  
     public static String mapExtensionAndClassifierToType( String classifier, String extension )
 98  
     {
 99  0
         return mapExtensionAndClassifierToType( classifier, extension, extension );
 100  
     }
 101  
 
 102  
     public static String mapExtensionAndClassifierToType( String classifier, String extension,
 103  
                                                            String defaultExtension )
 104  
     {
 105  0
         if ( "sources".equals( classifier ) )
 106  
         {
 107  0
             return "java-source";
 108  
         }
 109  0
         else if ( "javadoc".equals( classifier ) )
 110  
         {
 111  0
             return "javadoc";
 112  
         }
 113  0
         return mapExtensionToType( extension, defaultExtension );
 114  
     }
 115  
 
 116  
     public static String mapExtensionToType( String extension )
 117  
     {
 118  0
         return mapExtensionToType( extension, extension );
 119  
     }
 120  
 
 121  
     private static String mapExtensionToType( String extension, String defaultExtension )
 122  
     {
 123  0
         if ( "tar.gz".equals( extension ) )
 124  
         {
 125  0
             return "distribution-tgz";
 126  
         }
 127  0
         else  if ( "tar.bz2".equals( extension ) )
 128  
         {
 129  0
             return "distribution-bzip";
 130  
         }
 131  0
         else  if ( "zip".equals( extension ) )
 132  
         {
 133  0
             return "distribution-zip";
 134  
         }
 135  0
         else if ( "dll".equals( extension ) )
 136  
         {
 137  0
             return "library";
 138  
         }
 139  0
         else if ( "netmodule".equals( extension ) )
 140  
         {
 141  0
             return "module";
 142  
         }
 143  0
         else if ( "exe.config".equals( extension ) )
 144  
         {
 145  0
             return "exe.config";
 146  
         }
 147  0
         else if ( "exe".equals( extension ) )
 148  
         {
 149  0
             return "winexe";
 150  
         }
 151  0
         else if ( "nar".equals( extension ) )
 152  
         {
 153  0
             return "nar";
 154  
         }
 155  0
         return defaultExtension;
 156  
     }
 157  
 }