Coverage Report - org.apache.maven.scm.plugin.DiffMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
DiffMojo
0%
0/17
0%
0/2
8
 
 1  
 package org.apache.maven.scm.plugin;
 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.apache.maven.scm.ScmException;
 24  
 import org.apache.maven.scm.command.diff.DiffScmResult;
 25  
 import org.apache.maven.scm.repository.ScmRepository;
 26  
 import org.codehaus.plexus.util.FileUtils;
 27  
 
 28  
 import java.io.File;
 29  
 import java.io.IOException;
 30  
 
 31  
 /**
 32  
  * Display the difference of the working copy with the latest copy in the configured scm url.
 33  
  *
 34  
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
 35  
  * @version $Id: DiffMojo.java 538856 2007-05-17 09:58:55Z evenisse $
 36  
  * @goal diff
 37  
  * @description Create a diff
 38  
  * @aggregator
 39  
  */
 40  0
 public class DiffMojo
 41  
     extends AbstractScmMojo
 42  
 {
 43  
     /**
 44  
      * The version type (branch/tag/revision) of scmVersion.
 45  
      *
 46  
      * @parameter expression="${startScmVersionType}"
 47  
      */
 48  
     private String startScmVersionType;
 49  
 
 50  
     /**
 51  
      * The version (revision number/branch name/tag name).
 52  
      *
 53  
      * @parameter expression="${startScmVersion}"
 54  
      */
 55  
     private String startScmVersion;
 56  
 
 57  
     /**
 58  
      * The version type (branch/tag/revision) of scmVersion.
 59  
      *
 60  
      * @parameter expression="${endScmVersionType}"
 61  
      */
 62  
     private String endScmVersionType;
 63  
 
 64  
     /**
 65  
      * The version (revision number/branch name/tag name).
 66  
      *
 67  
      * @parameter expression="${startScmVersion}"
 68  
      */
 69  
     private String endScmVersion;
 70  
 
 71  
     /**
 72  
      * Output file name.
 73  
      *
 74  
      * @parameter expression="${outputFile}"
 75  
      * default-value="${project.artifactId}.diff"
 76  
      */
 77  
     private File outputFile;
 78  
 
 79  
     public void execute()
 80  
         throws MojoExecutionException
 81  
     {
 82  0
         super.execute();
 83  
 
 84  
         try
 85  
         {
 86  0
             ScmRepository repository = getScmRepository();
 87  
 
 88  0
             DiffScmResult result = getScmManager().diff( repository, getFileSet(),
 89  
                                                          getScmVersion( startScmVersionType, startScmVersion ),
 90  
                                                          getScmVersion( endScmVersionType, endScmVersion ) );
 91  
 
 92  0
             checkResult( result );
 93  
 
 94  0
             getLog().info( result.getPatch() );
 95  
 
 96  
             try
 97  
             {
 98  0
                 if ( outputFile != null )
 99  
                 {
 100  0
                     FileUtils.fileWrite( outputFile.getAbsolutePath(), result.getPatch() );
 101  
                 }
 102  
             }
 103  0
             catch ( IOException e )
 104  
             {
 105  0
                 throw new MojoExecutionException( "Can't write patch file.", e );
 106  0
             }
 107  
         }
 108  0
         catch ( IOException e )
 109  
         {
 110  0
             throw new MojoExecutionException( "Cannot run diff command : ", e );
 111  
         }
 112  0
         catch ( ScmException e )
 113  
         {
 114  0
             throw new MojoExecutionException( "Cannot run diff command : ", e );
 115  0
         }
 116  0
     }
 117  
 }