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