Coverage Report - org.apache.maven.plugin.ear.EarModuleFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
EarModuleFactory
0%
0/43
0%
0/24
9.333
 
 1  
 package org.apache.maven.plugin.ear;
 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 org.apache.maven.artifact.Artifact;
 23  
 import org.apache.maven.plugin.ear.util.ArtifactTypeMappingService;
 24  
 import org.apache.maven.plugin.ear.util.JavaEEVersion;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.Collections;
 28  
 import java.util.List;
 29  
 
 30  
 /**
 31  
  * Builds an {@link EarModule} based on an <tt>Artifact</tt>.
 32  
  *
 33  
  * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
 34  
  * @version $Id: EarModuleFactory.java 1088330 2011-04-03 16:46:31Z snicoll $
 35  
  */
 36  0
 public final class EarModuleFactory
 37  
 {
 38  
     public final static List standardArtifactTypes;
 39  
 
 40  
     static
 41  
     {
 42  0
         List temp = new ArrayList();
 43  0
         temp.add( "jar" );
 44  0
         temp.add( "ejb" );
 45  0
         temp.add( "ejb3" );
 46  0
         temp.add( "par" );
 47  0
         temp.add( "ejb-client" );
 48  0
         temp.add( "app-client" );
 49  0
         temp.add( "rar" );
 50  0
         temp.add( "war" );
 51  0
         temp.add( "sar" );
 52  0
         temp.add( "wsr" );
 53  0
         temp.add( "har" );
 54  0
         standardArtifactTypes = Collections.unmodifiableList( temp );
 55  0
     }
 56  
 
 57  
     /**
 58  
      * Creates a new {@link EarModule} based on the
 59  
      * specified {@link Artifact} and the specified
 60  
      * execution configuration.
 61  
      *
 62  
      * @param artifact                the artifact
 63  
      * @param javaEEVersion           the javaEE version to use
 64  
      * @param defaultLibBundleDir     the default bundle dir for {@link org.apache.maven.plugin.ear.JarModule}
 65  
      * @param includeInApplicationXml should {@link org.apache.maven.plugin.ear.JarModule} be included in application Xml
 66  
      * @param typeMappingService      The artifact type mapping service
 67  
      * @return an ear module for this artifact
 68  
      * @throws UnknownArtifactTypeException if the artifact is not handled
 69  
      */
 70  
     public static EarModule newEarModule( Artifact artifact, JavaEEVersion javaEEVersion, String defaultLibBundleDir,
 71  
                                           Boolean includeInApplicationXml,
 72  
                                           ArtifactTypeMappingService typeMappingService )
 73  
         throws UnknownArtifactTypeException
 74  
     {
 75  
         // Get the standard artifact type based on default config and user-defined mapping(s)
 76  0
         final String artifactType = typeMappingService.getStandardType( artifact.getType() );
 77  
 
 78  0
         if ( "jar".equals( artifactType ) )
 79  
         {
 80  0
             return new JarModule( artifact, defaultLibBundleDir, includeInApplicationXml );
 81  
         }
 82  0
         else if ( "ejb".equals( artifactType ) )
 83  
         {
 84  0
             return new EjbModule( artifact );
 85  
         }
 86  0
         else if ( "ejb3".equals( artifactType ) )
 87  
         {
 88  0
             return new Ejb3Module( artifact );
 89  
         }
 90  0
         else if ( "par".equals( artifactType ) )
 91  
         {
 92  0
             return new ParModule( artifact );
 93  
         }
 94  0
         else if ( "ejb-client".equals( artifactType ) )
 95  
         {
 96  
             // Somewhat weird way to tackle the problem described in MEAR-85
 97  0
             if ( javaEEVersion.le( JavaEEVersion.OneDotFour ) )
 98  
             {
 99  0
                 return new EjbClientModule( artifact, null );
 100  
             }
 101  
             else
 102  
             {
 103  0
                 return new EjbClientModule( artifact, defaultLibBundleDir );
 104  
             }
 105  
         }
 106  0
         else if ( "app-client".equals( artifactType ) )
 107  
         {
 108  0
             return new AppClientModule( artifact );
 109  
         }
 110  0
         else if ( "rar".equals( artifactType ) )
 111  
         {
 112  0
             return new RarModule( artifact );
 113  
         }
 114  0
         else if ( "war".equals( artifactType ) )
 115  
         {
 116  0
             return new WebModule( artifact );
 117  
         }
 118  0
         else if ( "sar".equals( artifactType ) )
 119  
         {
 120  0
             return new SarModule( artifact );
 121  
         }
 122  0
         else if ( "wsr".equals( artifactType ) )
 123  
         {
 124  0
             return new WsrModule( artifact );
 125  
         }
 126  0
         else if ( "har".equals( artifactType ) )
 127  
         {
 128  0
             return new HarModule( artifact );
 129  
         }
 130  
         else
 131  
         {
 132  0
             throw new IllegalStateException( "Could not handle artifact type[" + artifactType + "]" );
 133  
         }
 134  
     }
 135  
 
 136  
     /**
 137  
      * Returns a list of standard artifact types.
 138  
      *
 139  
      * @return the standard artifact types
 140  
      */
 141  
     public static List getStandardArtifactTypes()
 142  
     {
 143  0
         return standardArtifactTypes;
 144  
     }
 145  
 
 146  
     /**
 147  
      * Specify whether the specified type is standard artifact
 148  
      * type.
 149  
      *
 150  
      * @param type the type to check
 151  
      * @return true if the specified type is a standard artifact type
 152  
      */
 153  
     public static boolean isStandardArtifactType( final String type )
 154  
     {
 155  0
         return standardArtifactTypes.contains( type );
 156  
     }
 157  
 
 158  
 }