Coverage Report - org.apache.maven.scm.provider.vss.commands.changelog.VssHistoryCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
VssHistoryCommand
58 %
20/34
30 %
3/10
5
 
 1  
 package org.apache.maven.scm.provider.vss.commands.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.ScmBranch;
 23  
 import org.apache.maven.scm.ScmException;
 24  
 import org.apache.maven.scm.ScmFileSet;
 25  
 import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
 26  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 27  
 import org.apache.maven.scm.command.changelog.ChangeLogSet;
 28  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 29  
 import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils;
 30  
 import org.apache.maven.scm.provider.vss.commands.VssConstants;
 31  
 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
 32  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 33  
 import org.codehaus.plexus.util.cli.Commandline;
 34  
 
 35  
 import java.text.SimpleDateFormat;
 36  
 import java.util.Date;
 37  
 import java.util.Locale;
 38  
 
 39  
 /**
 40  
  * @author <a href="mailto:triek@thrx.de">Thorsten Riek</a>
 41  
  * @author Olivier Lamy
 42  
  * @version $Id: VssHistoryCommand.java 1054408 2011-01-02 14:05:25Z olamy $
 43  
  */
 44  1
 public class VssHistoryCommand
 45  
     extends AbstractChangeLogCommand
 46  
 {
 47  
     /** {@inheritDoc} */
 48  
     protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 49  
                                                           Date startDate, Date endDate, ScmBranch branch,
 50  
                                                           String datePattern )
 51  
         throws ScmException
 52  
     {
 53  0
         VssScmProviderRepository repo = (VssScmProviderRepository) repository;
 54  
 
 55  0
         Commandline cl = buildCmdLine( repo, fileSet, startDate, endDate );
 56  
 
 57  0
         if ( getLogger().isInfoEnabled() )
 58  
         {
 59  0
             getLogger().info( "Executing: " + cl );
 60  0
             getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
 61  
         }
 62  
 
 63  0
         VssChangeLogConsumer consumer = new VssChangeLogConsumer( repo, datePattern, getLogger() );
 64  
 
 65  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 66  
 
 67  0
         int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
 68  
 
 69  0
         if ( exitCode != 0 )
 70  
         {
 71  0
             return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false );
 72  
         }
 73  
 
 74  0
         return new ChangeLogScmResult( cl.toString(),
 75  
                                        new ChangeLogSet( consumer.getModifications(), startDate, endDate ) );
 76  
     }
 77  
 
 78  
     public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate )
 79  
         throws ScmException
 80  
     {
 81  1
         Commandline command = new Commandline();
 82  
 
 83  1
         command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
 84  
 
 85  
         try
 86  
         {
 87  1
             command.addSystemEnvironment();
 88  
         }
 89  0
         catch ( Exception e )
 90  
         {
 91  0
             throw new ScmException( "Can't add system environment.", e );
 92  1
         }
 93  
 
 94  1
         command.addEnvironment( "SSDIR", repo.getVssdir() );
 95  
 
 96  1
         String ssDir = VssCommandLineUtils.getSsDir();
 97  
 
 98  1
         command.setExecutable( ssDir + VssConstants.SS_EXE );
 99  
 
 100  1
         command.createArg().setValue( VssConstants.COMMAND_HISTORY );
 101  
 
 102  1
         command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
 103  
 
 104  
         //User identification to get access to vss repository
 105  1
         if ( repo.getUserPassword() != null )
 106  
         {
 107  1
             command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
 108  
         }
 109  
 
 110  
         //Display the history of an entire project list
 111  1
         command.createArg().setValue( VssConstants.FLAG_RECURSION );
 112  
 
 113  
         //Ignore: Do not ask for input under any circumstances.
 114  1
         command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
 115  
 
 116  
         //Display only versions that fall within specified data range.
 117  1
         if ( startDate != null )
 118  
         {
 119  1
             if ( endDate == null )
 120  
             {
 121  0
                 endDate = new Date(); // = now
 122  
             }
 123  
 
 124  1
             SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy", Locale.ENGLISH );
 125  1
             String dateRange = sdf.format( endDate ) + "~" + sdf.format( startDate );
 126  1
             command.createArg().setValue( VssConstants.FLAG_VERSION_DATE + dateRange );
 127  
         }
 128  1
         return command;
 129  
     }
 130  
 }