Coverage Report - org.apache.maven.plugin.war.WarManifestMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
WarManifestMojo
67%
14/21
50%
1/2
8
 
 1  
 package org.apache.maven.plugin.war;
 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.archiver.MavenArchiver;
 23  
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 24  
 import org.apache.maven.plugin.MojoExecutionException;
 25  
 import org.codehaus.plexus.archiver.jar.Manifest;
 26  
 import org.codehaus.plexus.archiver.jar.ManifestException;
 27  
 import org.codehaus.plexus.archiver.war.WarArchiver;
 28  
 import org.codehaus.plexus.util.IOUtil;
 29  
 import org.codehaus.plexus.util.WriterFactory;
 30  
 
 31  
 import java.io.File;
 32  
 import java.io.IOException;
 33  
 import java.io.PrintWriter;
 34  
 
 35  
 /**
 36  
  * Generate a manifest for this webapp. The manifest file is created in the
 37  
  * <code>warSourceDirectory</code>.
 38  
  *
 39  
  * @author Mike Perham
 40  
  * @version $Id: WarManifestMojo.java 985625 2010-08-15 08:15:16Z dennisl $
 41  
  * @goal manifest
 42  
  * @phase process-resources
 43  
  * @threadSafe
 44  
  * @requiresDependencyResolution runtime
 45  
  */
 46  6
 public class WarManifestMojo
 47  
     extends AbstractWarMojo
 48  
 {
 49  
     /**
 50  
      * The WAR archiver.
 51  
      *
 52  
      * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="war"
 53  
      */
 54  
     private WarArchiver warArchiver;
 55  
 
 56  
 
 57  
     /**
 58  
      * Executes this mojo on the current project.
 59  
      *
 60  
      * @throws MojoExecutionException if an error occurred while building the webapp
 61  
      */
 62  
     public void execute()
 63  
         throws MojoExecutionException
 64  
     {
 65  5
         File manifestDir = new File( getWarSourceDirectory(), "META-INF" );
 66  5
         if ( !manifestDir.exists() )
 67  
         {
 68  0
             manifestDir.mkdirs();
 69  
         }
 70  5
         File manifestFile = new File( manifestDir, "MANIFEST.MF" );
 71  5
         MavenArchiver ma = new MavenArchiver();
 72  5
         ma.setArchiver( warArchiver );
 73  5
         ma.setOutputFile( manifestFile );
 74  
 
 75  5
         PrintWriter printWriter = null;
 76  
         try
 77  
         {
 78  5
             Manifest mf = ma.getManifest( getProject(), getArchive() );
 79  5
             printWriter = new PrintWriter( WriterFactory.newWriter( manifestFile, WriterFactory.UTF_8 ) );
 80  5
             mf.write( printWriter );
 81  
         }
 82  0
         catch ( ManifestException e )
 83  
         {
 84  0
             throw new MojoExecutionException( "Error preparing the manifest: " + e.getMessage(), e );
 85  
         }
 86  0
         catch ( DependencyResolutionRequiredException e )
 87  
         {
 88  0
             throw new MojoExecutionException( "Error preparing the manifest: " + e.getMessage(), e );
 89  
         }
 90  0
         catch ( IOException e )
 91  
         {
 92  0
             throw new MojoExecutionException( "Error preparing the manifest: " + e.getMessage(), e );
 93  
         }
 94  
         finally
 95  
         {
 96  5
             IOUtil.close( printWriter );
 97  5
         }
 98  5
     }
 99  
 }