001package org.apache.maven.scm.provider.tfs.command; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023import java.util.ArrayList; 024import java.util.Date; 025import java.util.Iterator; 026import java.util.List; 027 028import org.apache.maven.scm.ChangeSet; 029import org.apache.maven.scm.ScmBranch; 030import org.apache.maven.scm.ScmException; 031import org.apache.maven.scm.ScmFileSet; 032import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand; 033import org.apache.maven.scm.command.changelog.ChangeLogScmResult; 034import org.apache.maven.scm.command.changelog.ChangeLogSet; 035import org.apache.maven.scm.provider.ScmProviderRepository; 036import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer; 037import org.apache.maven.scm.provider.tfs.command.consumer.TfsChangeLogConsumer; 038 039/** 040 * @author Olivier Lamy 041 * 042 */ 043public class TfsChangeLogCommand 044 extends AbstractChangeLogCommand 045{ 046 047 protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository r, ScmFileSet f, Date startDate, 048 Date endDate, ScmBranch branch, String datePattern ) 049 throws ScmException 050 { 051 List<ChangeSet> changeLogs = new ArrayList<ChangeSet>(); 052 Iterator<File> iter = f.getFileList().iterator(); 053 if ( !iter.hasNext() ) 054 { 055 List<File> dir = new ArrayList<File>(); 056 // No files to iterate 057 dir.add( f.getBasedir() ); 058 iter = dir.iterator(); 059 } 060 TfsCommand command = null; 061 // tf history takes only one file arg 062 while ( iter.hasNext() ) 063 { 064 TfsChangeLogConsumer out = new TfsChangeLogConsumer( getLogger() ); 065 ErrorStreamConsumer err = new ErrorStreamConsumer(); 066 067 command = createCommand( r, f, ( (File) iter.next() ) ); 068 int status = command.execute( out, err ); 069 070 if ( status != 0 || ( !out.hasBeenFed() && err.hasBeenFed() ) ) 071 { 072 return new ChangeLogScmResult( command.getCommandString(), "Error code for TFS changelog command - " 073 + status, err.getOutput(), false ); 074 } 075 changeLogs.addAll( out.getLogs() ); 076 } 077 return new ChangeLogScmResult( command.getCommandString(), new ChangeLogSet( changeLogs, startDate, endDate ) ); 078 079 } 080 081 protected TfsCommand createCommand( ScmProviderRepository r, ScmFileSet f, File file ) 082 { 083 TfsCommand command = new TfsCommand( "history", r, f, getLogger() ); 084 command.addArgument( "-format:detailed" ); 085 command.addArgument( file.getName() ); 086 return command; 087 } 088} 089