Coverage Report - org.apache.maven.plugin.source.JarDefaultSourceMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
JarDefaultSourceMojo
65% 
100% 
7
 
 1  
 package org.apache.maven.plugin.source;
 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.plugin.MojoExecutionException;
 23  
 import org.codehaus.plexus.archiver.ArchiverException;
 24  
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 25  
 
 26  
 import java.io.File;
 27  
 import java.io.IOException;
 28  
 
 29  
 /**
 30  
  * This plugin bundles all the sources into a jar archive.
 31  
  *
 32  
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 33  
  * @version $Id: AbstractJarSourceMojo.java 389062 2006-03-27 08:19:25Z aramirez $
 34  
  * @goal jar
 35  
  * @phase package
 36  
  * @execute phase="generate-sources"
 37  
  */
 38  4
 public class JarDefaultSourceMojo
 39  
     extends AbstractJarSourceMojo
 40  
 {
 41  
     /**
 42  
      * @see org.apache.maven.plugin.AbstractMojo#execute()
 43  
      */
 44  
     public void execute()
 45  
         throws MojoExecutionException
 46  
     {
 47  4
         if ( "pom".equals( packaging ) )
 48  
         {
 49  1
             getLog().info( "NOT adding sources to attached artifacts for packaging: \'" + packaging + "\'." );
 50  1
         }
 51  
         else
 52  
         {
 53  
             // Do not attach source JAR for artifacts with classifier. This is because Maven2 only supports a single
 54  
             // classifier per artifact. This is a limitation. See http://jira.codehaus.org/browse/MSOURCES-10.
 55  3
             if ( getProject().getArtifact().getClassifier() != null )
 56  
             {
 57  0
                 getLog().warn( "NOT adding sources to artifacts with classifier as Maven only supports one classifier "
 58  
                     + "per artifact. Current artifact [" + getProject().getArtifact().getId() + "] has a ["
 59  
                     + getProject().getArtifact().getClassifier() + "] classifier.");
 60  0
             }
 61  
             else
 62  
             {
 63  3
                 File outputFile = new File( outputDirectory, finalName + "-sources.jar" );
 64  
 
 65  3
                 File[] sourceDirectories = getDefaultSources();
 66  
 
 67  
                 try
 68  
                 {
 69  3
                     createJar( outputFile, sourceDirectories, createArchiver() );
 70  
                 }
 71  0
                 catch ( IOException e )
 72  
                 {
 73  0
                     throw new MojoExecutionException( "Error creating source archive: " + e.getMessage(), e );
 74  
                 }
 75  0
                 catch ( ArchiverException e )
 76  
                 {
 77  0
                     throw new MojoExecutionException( "Error creating source archive: " + e.getMessage(), e );
 78  3
                 }
 79  
 
 80  3
                 attachArtifact( outputFile, "sources" );
 81  
             }
 82  
         }
 83  4
     }
 84  
 
 85  
 }