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  /**
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          //[SCM-753] support TFS checkin-policies - TFS returns error, that can be ignored.
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              // handle TFS-policies (by adding "/override:";Auto-Build: Version Update";)
82              command.addArgument( "/override:checkin_policy" );
83          }
84  
85          return command;
86      }
87  
88  }