Coverage Report - org.apache.maven.scm.provider.hg.command.changelog.HgChangeLogCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
HgChangeLogCommand
0 %
0/31
0 %
0/10
3,5
 
 1  
 package org.apache.maven.scm.provider.hg.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.ChangeSet;
 23  
 import org.apache.maven.scm.ScmBranch;
 24  
 import org.apache.maven.scm.ScmException;
 25  
 import org.apache.maven.scm.ScmFileSet;
 26  
 import org.apache.maven.scm.ScmResult;
 27  
 import org.apache.maven.scm.ScmVersion;
 28  
 import org.apache.maven.scm.command.Command;
 29  
 import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
 30  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 31  
 import org.apache.maven.scm.command.changelog.ChangeLogSet;
 32  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 33  
 import org.apache.maven.scm.provider.hg.HgUtils;
 34  
 import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
 35  
 
 36  
 import java.text.SimpleDateFormat;
 37  
 import java.util.Date;
 38  
 import java.util.List;
 39  
 
 40  
 /**
 41  
  * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
 42  
  * @author Olivier Lamy
 43  
  * @version $Id: HgChangeLogCommand.java 1328509 2012-04-20 21:13:09Z olamy $
 44  
  */
 45  0
 public class HgChangeLogCommand
 46  
     extends AbstractChangeLogCommand
 47  
     implements Command
 48  
 {
 49  
     /**
 50  
      * {@inheritDoc}
 51  
      */
 52  
     protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository scmProviderRepository,
 53  
                                                           ScmFileSet fileSet, Date startDate, Date endDate,
 54  
                                                           ScmBranch branch, String datePattern )
 55  
         throws ScmException
 56  
     {
 57  0
         SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
 58  0
         StringBuilder dateInterval = new StringBuilder();
 59  
         // TRICK: Mercurial 1.9.3 don't accept 1970-01-01
 60  0
         dateInterval.append(
 61  
             dateFormat.format( startDate == null ? new Date( 1000L * 60 * 60 * 24 ) : startDate ) ); // From 2. Jan 1970
 62  0
         dateInterval.append( " to " );
 63  0
         dateInterval.append( dateFormat.format( endDate == null ? new Date() : endDate ) ); // Upto now
 64  
 
 65  0
         String[] cmd = new String[]{ HgCommandConstants.LOG_CMD, HgCommandConstants.VERBOSE_OPTION,
 66  
             HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.DATE_OPTION, dateInterval.toString() };
 67  0
         HgChangeLogConsumer consumer = new HgChangeLogConsumer( getLogger(), datePattern );
 68  0
         ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), cmd );
 69  
 
 70  0
         List<ChangeSet> logEntries = consumer.getModifications();
 71  0
         ChangeLogSet changeLogSet = new ChangeLogSet( logEntries, startDate, endDate );
 72  0
         return new ChangeLogScmResult( changeLogSet, result );
 73  
     }
 74  
 
 75  
     @Override
 76  
     protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 77  
                                                           ScmVersion startVersion, ScmVersion endVersion,
 78  
                                                           String datePattern )
 79  
         throws ScmException
 80  
     {
 81  0
         StringBuilder revisionInterval = new StringBuilder();
 82  0
         if ( startVersion != null )
 83  
         {
 84  0
             revisionInterval.append( startVersion.getName() );
 85  
         }
 86  0
         revisionInterval.append( ":" );
 87  0
         if ( endVersion != null )
 88  
         {
 89  0
             revisionInterval.append( endVersion.getName() );
 90  
         }
 91  
 
 92  0
         String[] cmd = new String[]{ HgCommandConstants.LOG_CMD, HgCommandConstants.VERBOSE_OPTION,
 93  
             HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.REVISION_OPTION, revisionInterval.toString() };
 94  0
         HgChangeLogConsumer consumer = new HgChangeLogConsumer( getLogger(), datePattern );
 95  0
         ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), cmd );
 96  
 
 97  0
         List<ChangeSet> logEntries = consumer.getModifications();
 98  0
         Date startDate = null;
 99  0
         Date endDate = null;
 100  0
         if ( !logEntries.isEmpty() )
 101  
         {
 102  0
             startDate = logEntries.get( 0 ).getDate();
 103  0
             endDate = logEntries.get( logEntries.size() - 1 ).getDate();
 104  
         }
 105  0
         ChangeLogSet changeLogSet = new ChangeLogSet( logEntries, startDate, endDate );
 106  0
         changeLogSet.setStartVersion( startVersion );
 107  0
         changeLogSet.setEndVersion( endVersion );
 108  0
         return new ChangeLogScmResult( changeLogSet, result );
 109  
     }
 110  
 }