Coverage Report - org.apache.maven.scm.provider.tfs.command.TfsChangeLogCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
TfsChangeLogCommand
22 %
5/22
0 %
0/10
4
 
 1  
 package org.apache.maven.scm.provider.tfs.command;
 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.File;
 23  
 import java.util.ArrayList;
 24  
 import java.util.Date;
 25  
 import java.util.Iterator;
 26  
 import java.util.List;
 27  
 
 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.ScmFileSet;
 32  
 import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
 33  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 34  
 import org.apache.maven.scm.command.changelog.ChangeLogSet;
 35  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 36  
 import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer;
 37  
 import org.apache.maven.scm.provider.tfs.command.consumer.TfsChangeLogConsumer;
 38  
 
 39  
 /**
 40  
  * @author Olivier Lamy
 41  
  * @version $id$
 42  
  */
 43  1
 public class TfsChangeLogCommand
 44  
     extends AbstractChangeLogCommand
 45  
 {
 46  
 
 47  
     protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository r, ScmFileSet f, Date startDate,
 48  
                                                           Date endDate, ScmBranch branch, String datePattern )
 49  
         throws ScmException
 50  
     {
 51  0
         List<ChangeSet> changeLogs = new ArrayList<ChangeSet>();
 52  0
         Iterator<File> iter = f.getFileList().iterator();
 53  0
         if ( !iter.hasNext() )
 54  
         {
 55  0
             List<File> dir = new ArrayList<File>();
 56  
             // No files to iterate
 57  0
             dir.add( f.getBasedir() );
 58  0
             iter = dir.iterator();
 59  
         }
 60  0
         TfsCommand command = null;
 61  
         // tf history takes only one file arg
 62  0
         while ( iter.hasNext() )
 63  
         {
 64  0
             TfsChangeLogConsumer out = new TfsChangeLogConsumer( getLogger() );
 65  0
             ErrorStreamConsumer err = new ErrorStreamConsumer();
 66  
 
 67  0
             command = createCommand( r, f, ( (File) iter.next() ) );
 68  0
             int status = command.execute( out, err );
 69  
 
 70  0
             if ( status != 0 || ( !out.hasBeenFed() && err.hasBeenFed() ) )
 71  0
                 return new ChangeLogScmResult( command.getCommandString(), "Error code for TFS changelog command - "
 72  
                     + status, err.getOutput(), false );
 73  0
             changeLogs.addAll( out.getLogs() );
 74  0
         }
 75  0
         return new ChangeLogScmResult( command.getCommandString(), new ChangeLogSet( changeLogs, startDate, endDate ) );
 76  
 
 77  
     }
 78  
 
 79  
     protected TfsCommand createCommand( ScmProviderRepository r, ScmFileSet f, File file )
 80  
     {
 81  1
         TfsCommand command = new TfsCommand( "history", r, f, getLogger() );
 82  1
         command.addArgument( "-format:detailed" );
 83  1
         command.addArgument( file.getName() );
 84  1
         return command;
 85  
     }
 86  
 }
 87