View Javadoc
1   package org.apache.maven.scm.provider.jazz.command.status;
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.ScmFile;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.command.status.AbstractStatusCommand;
26  import org.apache.maven.scm.command.status.StatusScmResult;
27  import org.apache.maven.scm.provider.ScmProviderRepository;
28  import org.apache.maven.scm.provider.jazz.command.JazzConstants;
29  import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
30  import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
31  
32  //
33  // See the following links for additional information on the RTC "status" command:
34  // RTC 2.0.0.2:
35  // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_status.html
36  // RTC 3.0:
37  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_status.html
38  // RTC 3.0.1:
39  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_status.html
40  //
41  
42  /**
43   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
44   */
45  public class JazzStatusCommand
46      extends AbstractStatusCommand
47  {
48      /**
49       * {@inheritDoc}
50       */
51      public StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet )
52          throws ScmException
53      {
54          if ( getLogger().isDebugEnabled() )
55          {
56              getLogger().debug( "Executing status command..." );
57          }
58  
59          JazzStatusConsumer statusConsumer = new JazzStatusConsumer( repo, getLogger() );
60          ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
61  
62          JazzScmCommand statusCmd = createStatusCommand( repo, fileSet );
63          int status = statusCmd.execute( statusConsumer, errConsumer );
64          if ( status != 0 || errConsumer.hasBeenFed() )
65          {
66              return new StatusScmResult( statusCmd.getCommandString(),
67                                          "Error code for Jazz SCM status command - " + status, errConsumer.getOutput(),
68                                          false );
69          }
70  
71          if ( getLogger().isDebugEnabled() )
72          {
73              if ( !statusConsumer.getChangedFiles().isEmpty() )
74              {
75                  getLogger().debug( "Iterating over \"Status\" results" );
76                  for ( ScmFile file : statusConsumer.getChangedFiles() )
77                  {
78                      getLogger().debug( file.getPath() + " : " + file.getStatus() );
79                  }
80              }
81              else
82              {
83                  getLogger().debug( "There are no differences" );
84              }
85          }
86  
87          return new StatusScmResult( statusCmd.getCommandString(), statusConsumer.getChangedFiles() );
88      }
89  
90      public JazzScmCommand createStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet )
91      {
92          JazzScmCommand command =
93              new JazzScmCommand( JazzConstants.CMD_STATUS, null, repo, false, fileSet, getLogger() );
94  
95          command.addArgument( JazzConstants.ARG_STATUS_WIDE_PRINT_OUT );
96          return command;
97      }
98  }