1 package org.apache.maven.scm.provider.tfs.command;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
57 dir.add( f.getBasedir() );
58 iter = dir.iterator();
59 }
60 TfsCommand command = null;
61
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 {
72 return new ChangeLogScmResult( command.getCommandString(), "Error code for TFS changelog command - "
73 + status, err.getOutput(), false );
74 }
75 changeLogs.addAll( out.getLogs() );
76 }
77 return new ChangeLogScmResult( command.getCommandString(), new ChangeLogSet( changeLogs, startDate, endDate ) );
78
79 }
80
81 protected TfsCommand createCommand( ScmProviderRepository r, ScmFileSet f, File file )
82 {
83 TfsCommand command = new TfsCommand( "history", r, f, getLogger() );
84 command.addArgument( "-format:detailed" );
85 command.addArgument( file.getName() );
86 return command;
87 }
88 }
89