View Javadoc
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   *
42   */
43  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          List<ChangeSet> changeLogs = new ArrayList<ChangeSet>();
52          Iterator<File> iter = f.getFileList().iterator();
53          if ( !iter.hasNext() )
54          {
55              List<File> dir = new ArrayList<File>();
56              // No files to iterate
57              dir.add( f.getBasedir() );
58              iter = dir.iterator();
59          }
60          TfsCommand command = null;
61          // tf history takes only one file arg
62          while ( iter.hasNext() )
63          {
64              TfsChangeLogConsumer out = new TfsChangeLogConsumer( getLogger() );
65              ErrorStreamConsumer err = new ErrorStreamConsumer();
66  
67              command = createCommand( r, f, ( (File) iter.next() ) );
68              int status = command.execute( out, err );
69  
70              if ( status != 0 || ( !out.hasBeenFed() && err.hasBeenFed() ) )
71                  return new ChangeLogScmResult( command.getCommandString(), "Error code for TFS changelog command - "
72                      + status, err.getOutput(), false );
73              changeLogs.addAll( out.getLogs() );
74          }
75          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          TfsCommand command = new TfsCommand( "history", r, f, getLogger() );
82          command.addArgument( "-format:detailed" );
83          command.addArgument( file.getName() );
84          return command;
85      }
86  }
87