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 org.apache.maven.scm.ScmException;
23 import org.apache.maven.scm.ScmFileSet;
24 import org.apache.maven.scm.ScmVersion;
25 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
26 import org.apache.maven.scm.command.checkin.CheckInScmResult;
27 import org.apache.maven.scm.provider.ScmProviderRepository;
28 import org.apache.maven.scm.provider.tfs.TfsScmProviderRepository;
29 import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer;
30 import org.apache.maven.scm.provider.tfs.command.consumer.FileListConsumer;
31 import org.codehaus.plexus.util.StringUtils;
32
33
34
35
36 public class TfsCheckInCommand
37 extends AbstractCheckInCommand
38 {
39 private static final String TFS_CHECKIN_POLICIES_ERROR = "TF10139";
40
41 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository r, ScmFileSet f, String m, ScmVersion v )
42 throws ScmException
43 {
44 TfsCommand command = createCommand( r, f, m );
45 FileListConsumer fileConsumer = new FileListConsumer();
46 ErrorStreamConsumer err = new ErrorStreamConsumer();
47
48 int status = command.execute( fileConsumer, err );
49 getLogger().debug( "status of checkin command is= " + status + "; err= " + err.getOutput() );
50
51
52 if ( err.hasBeenFed() && err.getOutput().startsWith( TFS_CHECKIN_POLICIES_ERROR ) )
53 {
54 getLogger().debug( "exclusion: got error " + TFS_CHECKIN_POLICIES_ERROR
55 + " due to checkin policies. Ignoring it..." );
56 }
57
58 if ( status != 0 || ( err.hasBeenFed() && !err.getOutput().startsWith( TFS_CHECKIN_POLICIES_ERROR ) ) )
59 {
60 getLogger().error( "ERROR in command: " + command.getCommandString()
61 + "; Error code for TFS checkin command - " + status );
62 return new CheckInScmResult( command.getCommandString(), "Error code for TFS checkin command - " + status,
63 err.getOutput(), false );
64 }
65 return new CheckInScmResult( command.getCommandString(), fileConsumer.getFiles() );
66 }
67
68 public TfsCommand createCommand( ScmProviderRepository r, ScmFileSet f, String m )
69 {
70 TfsCommand command = new TfsCommand( "checkin", r, f, getLogger() );
71 command.addArgument( "-noprompt" );
72 if ( StringUtils.isNotBlank( m ) )
73 {
74 command.addArgument( "-comment:" + m );
75 }
76 command.addArgument( f );
77
78 TfsScmProviderRepository tfsScmProviderRepo = (TfsScmProviderRepository) r;
79 if ( tfsScmProviderRepo.isUseCheckinPolicies() )
80 {
81
82 command.addArgument( "/override:checkin_policy" );
83 }
84
85 return command;
86 }
87
88 }