Coverage Report - org.apache.maven.scm.plugin.ChangeLogMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangeLogMojo
0%
0/22
0%
0/6
6.5
 
 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 java.io.IOException;
 23  
 import java.text.ParseException;
 24  
 import java.text.SimpleDateFormat;
 25  
 import java.util.Date;
 26  
 
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.scm.ChangeSet;
 29  
 import org.apache.maven.scm.ScmBranch;
 30  
 import org.apache.maven.scm.ScmException;
 31  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 32  
 import org.apache.maven.scm.command.changelog.ChangeLogSet;
 33  
 import org.apache.maven.scm.provider.ScmProvider;
 34  
 import org.apache.maven.scm.repository.ScmRepository;
 35  
 
 36  
 /**
 37  
  * Dump changelog contents to console. It is mainly used to test maven-scm-api's changelog command.
 38  
  *
 39  
  * @author <a href="dantran@gmail.com">Dan Tran</a>
 40  
  * @author Olivier Lamy
 41  
  * @version $Id: ChangeLogMojo.java 1054215 2011-01-01 09:45:44Z olamy $
 42  
  * @goal changelog
 43  
  * @aggregator
 44  
  */
 45  0
 public class ChangeLogMojo
 46  
     extends AbstractScmMojo
 47  
 {
 48  
     private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
 49  
 
 50  
     /**
 51  
      * Start Date.
 52  
      *
 53  
      * @parameter expression="${startDate}"
 54  
      */
 55  
     private String startDate;
 56  
 
 57  
     /**
 58  
      * End Date.
 59  
      *
 60  
      * @parameter expression="${endDate}"
 61  
      */
 62  
     private String endDate;
 63  
 
 64  
     /**
 65  
      * Date Format in changelog output of scm tool.
 66  
      *
 67  
      * @parameter expression="${dateFormat}"
 68  
      */
 69  
     private String dateFormat;
 70  
 
 71  
     /**
 72  
      * Date format to use for the specified startDate and/or endDate.
 73  
      *
 74  
      * @parameter expression="${userDateFormat}" default-value="yyyy-MM-dd"
 75  
      */
 76  0
     private String userDateFormat = DEFAULT_DATE_FORMAT;
 77  
 
 78  
     /**
 79  
      * The version type (branch/tag) of scmVersion.
 80  
      *
 81  
      * @parameter expression="${scmVersionType}"
 82  
      */
 83  
     private String scmVersionType;
 84  
 
 85  
     /**
 86  
      * The version (revision number/branch name/tag name).
 87  
      *
 88  
      * @parameter expression="${scmVersion}"
 89  
      */
 90  
     private String scmVersion;
 91  
 
 92  
     /** {@inheritDoc} */
 93  
     public void execute()
 94  
         throws MojoExecutionException
 95  
     {
 96  0
         super.execute();
 97  
 
 98  0
         SimpleDateFormat localFormat = new SimpleDateFormat( userDateFormat );
 99  
 
 100  
         try
 101  
         {
 102  0
             ScmRepository repository = getScmRepository();
 103  
 
 104  0
             ScmProvider provider = getScmManager().getProviderByRepository( repository );
 105  
 
 106  0
             ChangeLogScmResult result = provider.changeLog( repository, getFileSet(),
 107  
                                                             this.parseDate( localFormat, this.startDate ),
 108  
                                                             this.parseDate( localFormat, this.endDate ), 0,
 109  
                                                             (ScmBranch) getScmVersion( scmVersionType, scmVersion ),
 110  
                                                             dateFormat );
 111  0
             checkResult( result );
 112  
 
 113  0
             ChangeLogSet changeLogSet = result.getChangeLog();
 114  
 
 115  0
             for ( ChangeSet changeSet : changeLogSet.getChangeSets() )
 116  
             {
 117  0
                 getLog().info( changeSet.toString() );
 118  
             }
 119  
 
 120  
         }
 121  0
         catch ( IOException e )
 122  
         {
 123  0
             throw new MojoExecutionException( "Cannot run changelog command : ", e );
 124  
         }
 125  0
         catch ( ScmException e )
 126  
         {
 127  0
             throw new MojoExecutionException( "Cannot run changelog command : ", e );
 128  0
         }
 129  0
     }
 130  
 
 131  
     /**
 132  
      * Converts the localized date string pattern to date object.
 133  
      *
 134  
      * @return A date
 135  
      */
 136  
     private Date parseDate( SimpleDateFormat format, String date )
 137  
         throws MojoExecutionException
 138  
     {
 139  0
         if ( date == null || date.trim().length() == 0 )
 140  
         {
 141  0
             return null;
 142  
         }
 143  
 
 144  
         try
 145  
         {
 146  0
             return format.parse( date.toString() );
 147  
         }
 148  0
         catch ( ParseException e )
 149  
         {
 150  0
             throw new MojoExecutionException( "Please use this date pattern: " + format.toLocalizedPattern().toString(),
 151  
                                               e );
 152  
         }
 153  
     }
 154  
 }