Coverage Report - org.apache.maven.plugin.ear.WebModule
 
Classes in this File Line Coverage Branch Coverage Complexity
WebModule
0%
0/27
0%
0/4
1.375
 
 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.MojoFailureException;
 24  
 import org.codehaus.plexus.util.xml.XMLWriter;
 25  
 
 26  
 import java.util.Set;
 27  
 
 28  
 /**
 29  
  * The {@link EarModule} implementation for a Web application module.
 30  
  *
 31  
  * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
 32  
  * @version $Id: WebModule.java 1228837 2012-01-08 13:19:38Z rfscholte $
 33  
  */
 34  
 public class WebModule
 35  
     extends AbstractEarModule
 36  
 {
 37  
     protected static final String WEB_MODULE = "web";
 38  
 
 39  
     protected static final String WEB_URI_FIELD = "web-uri";
 40  
 
 41  
     protected static final String CONTEXT_ROOT_FIELD = "context-root";
 42  
 
 43  
     private String contextRoot;
 44  
 
 45  
     public WebModule()
 46  0
     {
 47  0
     }
 48  
 
 49  
     public WebModule( Artifact a )
 50  
     {
 51  0
         super( a );
 52  0
         this.contextRoot = getDefaultContextRoot( a );
 53  0
     }
 54  
 
 55  
     public void appendModule( XMLWriter writer, String version, Boolean generateId )
 56  
     {
 57  0
         startModuleElement( writer, generateId );
 58  0
         writer.startElement( WEB_MODULE );
 59  0
         writer.startElement( WEB_URI_FIELD );
 60  0
         writer.writeText( getUri() );
 61  0
         writer.endElement(); // web-uri
 62  
 
 63  0
         writer.startElement( CONTEXT_ROOT_FIELD );
 64  0
         writer.writeText( getContextRoot() );
 65  0
         writer.endElement(); // context-root
 66  
 
 67  0
         writer.endElement(); // web
 68  
 
 69  0
         writeAltDeploymentDescriptor( writer, version );
 70  
 
 71  0
         writer.endElement(); // module
 72  0
     }
 73  
 
 74  
     public void resolveArtifact( Set<Artifact> artifacts )
 75  
         throws EarPluginException, MojoFailureException
 76  
     {
 77  
         // Let's resolve the artifact
 78  0
         super.resolveArtifact( artifacts );
 79  
 
 80  
         // Context root has not been customized - using default
 81  0
         if ( contextRoot == null )
 82  
         {
 83  0
             contextRoot = getDefaultContextRoot( getArtifact() );
 84  
         }
 85  0
     }
 86  
 
 87  
     /**
 88  
      * Returns the context root to use for the web module.
 89  
      * <p/>
 90  
      * Note that this might return <tt>null</tt> till the
 91  
      * artifact has been resolved.
 92  
      *
 93  
      * @return the context root
 94  
      */
 95  
     public String getContextRoot()
 96  
     {
 97  0
         return contextRoot;
 98  
     }
 99  
 
 100  
     public String getType()
 101  
     {
 102  0
         return "war";
 103  
     }
 104  
 
 105  
     /**
 106  
      * Generates a default context root for the given artifact, based
 107  
      * on the <tt>artifactId</tt>.
 108  
      *
 109  
      * @param a the artifact
 110  
      * @return a context root for the artifact
 111  
      */
 112  
     private static String getDefaultContextRoot( Artifact a )
 113  
     {
 114  0
         if ( a == null )
 115  
         {
 116  0
             throw new NullPointerException( "Artifact could not be null." );
 117  
         }
 118  0
         return "/" + a.getArtifactId();
 119  
     }
 120  
 
 121  
     public String getLibDir()
 122  
     {
 123  0
         return "WEB-INF/lib";
 124  
     }
 125  
 }