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.List;
25
26 import org.apache.maven.scm.ScmException;
27 import org.apache.maven.scm.ScmFile;
28 import org.apache.maven.scm.ScmFileSet;
29 import org.apache.maven.scm.ScmFileStatus;
30 import org.apache.maven.scm.ScmResult;
31 import org.apache.maven.scm.ScmTagParameters;
32 import org.apache.maven.scm.command.tag.AbstractTagCommand;
33 import org.apache.maven.scm.command.tag.TagScmResult;
34 import org.apache.maven.scm.provider.ScmProviderRepository;
35 import org.apache.maven.scm.provider.tfs.TfsScmProviderRepository;
36 import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer;
37 import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer;
38
39
40
41
42
43 public class TfsTagCommand
44 extends AbstractTagCommand
45 {
46
47 protected ScmResult executeTagCommand( ScmProviderRepository r, ScmFileSet f, String tag, String message )
48 throws ScmException
49 {
50 return executeTagCommand( r, f, tag, new ScmTagParameters( message ) );
51 }
52
53 protected ScmResult executeTagCommand( ScmProviderRepository r, ScmFileSet f, String tag,
54 ScmTagParameters scmTagParameters )
55 throws ScmException
56 {
57 TfsCommand command = createCommand( r, f, tag, scmTagParameters );
58
59 StringStreamConsumer out = new StringStreamConsumer();
60 ErrorStreamConsumer err = new ErrorStreamConsumer();
61
62 int status = command.execute( out, err );
63 if ( status != 0 || err.hasBeenFed() )
64 {
65 return new TagScmResult( command.getCommandString(), "Error code for TFS label command - " + status,
66 err.getOutput(), false );
67 }
68 List<ScmFile> files = new ArrayList<ScmFile>( f.getFileList().size() );
69 for ( File file : f.getFileList() )
70 {
71 files.add( new ScmFile( file.getPath(), ScmFileStatus.TAGGED ) );
72 }
73 return new TagScmResult( command.getCommandString(), files );
74
75 }
76
77 public TfsCommand createCommand( ScmProviderRepository r, ScmFileSet f, String tag,
78 ScmTagParameters scmTagParameters )
79 {
80 TfsScmProviderRepository tfsRepo = (TfsScmProviderRepository) r;
81 String url = tfsRepo.getServerPath();
82
83 TfsCommand command = new TfsCommand( "label", r, f, getLogger() );
84 command.addArgument( tag );
85 command.addArgument( url );
86 command.addArgument( "-recursive" );
87 command.addArgument( "-child:replace" );
88 String message = scmTagParameters.getMessage();
89 if ( message != null && !message.equals( "" ) )
90 {
91 command.addArgument( "-comment:" + message );
92 }
93 return command;
94 }
95
96 }