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 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  public class TfsCheckInCommand
34      extends AbstractCheckInCommand
35  {
36      private static final String TFS_CHECKIN_POLICIES_ERROR = "TF10139";
37  
38      protected CheckInScmResult executeCheckInCommand( ScmProviderRepository r, ScmFileSet f, String m, ScmVersion v )
39          throws ScmException
40      {
41          TfsCommand command = createCommand( r, f, m );
42          FileListConsumer fileConsumer = new FileListConsumer();
43          ErrorStreamConsumer err = new ErrorStreamConsumer();
44  
45          int status = command.execute( fileConsumer, err );
46          getLogger().debug( "status of checkin command is= " + status + "; err= " + err.getOutput() );
47  
48          //[SCM-753] support TFS checkin-policies - TFS returns error, that can be ignored.
49          if ( err.hasBeenFed() && err.getOutput().startsWith( TFS_CHECKIN_POLICIES_ERROR ) )
50          {
51              getLogger().debug( "exclusion: got error " + TFS_CHECKIN_POLICIES_ERROR
52                                     + " due to checkin policies. Ignoring it..." );
53          }
54  
55          if ( status != 0 || ( err.hasBeenFed() && !err.getOutput().startsWith( TFS_CHECKIN_POLICIES_ERROR ) ) )
56          {
57              getLogger().error( "ERROR in command: " + command.getCommandString()
58                                     + "; Error code for TFS checkin command - " + status );
59              return new CheckInScmResult( command.getCommandString(), "Error code for TFS checkin command - " + status,
60                                           err.getOutput(), false );
61          }
62          return new CheckInScmResult( command.getCommandString(), fileConsumer.getFiles() );
63      }
64  
65      public TfsCommand createCommand( ScmProviderRepository r, ScmFileSet f, String m )
66      {
67          TfsCommand command = new TfsCommand( "checkin", r, f, getLogger() );
68          command.addArgument( "-noprompt" );
69          if ( StringUtils.isNotBlank( m ) )
70          {
71              command.addArgument( "-comment:" + m );
72          }
73          command.addArgument( f );
74  
75          TfsScmProviderRepository tfsScmProviderRepo = (TfsScmProviderRepository) r;
76          if ( tfsScmProviderRepo.isUseCheckinPolicies() )
77          {
78              // handle TFS-policies (by adding "/override:";Auto-Build: Version Update";)
79              command.addArgument( "/override:checkin_policy" );
80          }
81  
82          return command;
83      }
84  
85  }