Coverage Report - org.apache.maven.scm.command.changelog.AbstractChangeLogCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractChangeLogCommand
0 %
0/23
0 %
0/18
5,333
 
 1  
 package org.apache.maven.scm.command.changelog;
 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.scm.CommandParameter;
 23  
 import org.apache.maven.scm.CommandParameters;
 24  
 import org.apache.maven.scm.ScmBranch;
 25  
 import org.apache.maven.scm.ScmException;
 26  
 import org.apache.maven.scm.ScmFileSet;
 27  
 import org.apache.maven.scm.ScmResult;
 28  
 import org.apache.maven.scm.ScmVersion;
 29  
 import org.apache.maven.scm.command.AbstractCommand;
 30  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 31  
 
 32  
 import java.util.Date;
 33  
 
 34  
 /**
 35  
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 36  
  * @author Olivier Lamy
 37  
  * @version $Id: AbstractChangeLogCommand.java 1328509 2012-04-20 21:13:09Z olamy $
 38  
  */
 39  0
 public abstract class AbstractChangeLogCommand
 40  
     extends AbstractCommand
 41  
     implements ChangeLogCommand
 42  
 {
 43  
     protected abstract ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 44  
                                                                    Date startDate, Date endDate, ScmBranch branch,
 45  
                                                                    String datePattern )
 46  
         throws ScmException;
 47  
 
 48  
     protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 49  
                                                           ScmVersion startVersion, ScmVersion endVersion,
 50  
                                                           String datePattern )
 51  
         throws ScmException
 52  
     {
 53  0
         throw new ScmException( "Unsupported method for this provider." );
 54  
     }
 55  
 
 56  
     /**
 57  
      * {@inheritDoc}
 58  
      */
 59  
     public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 60  
                                      CommandParameters parameters )
 61  
         throws ScmException
 62  
     {
 63  0
         Date startDate = parameters.getDate( CommandParameter.START_DATE, null );
 64  
 
 65  0
         Date endDate = parameters.getDate( CommandParameter.END_DATE, null );
 66  
 
 67  0
         int numDays = parameters.getInt( CommandParameter.NUM_DAYS, 0 );
 68  
 
 69  0
         ScmBranch branch = (ScmBranch) parameters.getScmVersion( CommandParameter.BRANCH, null );
 70  
 
 71  0
         ScmVersion startVersion = parameters.getScmVersion( CommandParameter.START_SCM_VERSION, null );
 72  
 
 73  0
         ScmVersion endVersion = parameters.getScmVersion( CommandParameter.END_SCM_VERSION, null );
 74  
 
 75  0
         String datePattern = parameters.getString( CommandParameter.CHANGELOG_DATE_PATTERN, null );
 76  
 
 77  0
         if ( startVersion != null || endVersion != null )
 78  
         {
 79  0
             return executeChangeLogCommand( repository, fileSet, startVersion, endVersion, datePattern );
 80  
         }
 81  
         else
 82  
         {
 83  0
             if ( numDays != 0 && ( startDate != null || endDate != null ) )
 84  
             {
 85  0
                 throw new ScmException( "Start or end date cannot be set if num days is set." );
 86  
             }
 87  
 
 88  0
             if ( endDate != null && startDate == null )
 89  
             {
 90  0
                 throw new ScmException( "The end date is set but the start date isn't." );
 91  
             }
 92  
 
 93  0
             if ( numDays > 0 )
 94  
             {
 95  0
                 int day = 24 * 60 * 60 * 1000;
 96  0
                 startDate = new Date( System.currentTimeMillis() - (long) numDays * day );
 97  
 
 98  0
                 endDate = new Date( System.currentTimeMillis() + (long) day );
 99  0
             }
 100  0
             else if ( endDate == null )
 101  
             {
 102  0
                 endDate = new Date();
 103  
             }
 104  
 
 105  0
             return executeChangeLogCommand( repository, fileSet, startDate, endDate, branch, datePattern );
 106  
         }
 107  
     }
 108  
 }