View Javadoc

1   package org.apache.maven.scm.provider.jazz.command.update;
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.ScmVersion;
26  import org.apache.maven.scm.command.changelog.ChangeLogCommand;
27  import org.apache.maven.scm.command.update.AbstractUpdateCommand;
28  import org.apache.maven.scm.command.update.UpdateScmResult;
29  import org.apache.maven.scm.provider.ScmProviderRepository;
30  import org.apache.maven.scm.provider.jazz.command.JazzConstants;
31  import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
32  import org.apache.maven.scm.provider.jazz.command.changelog.JazzChangeLogCommand;
33  import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
34  
35  //
36  // The Maven SCM Plugin "update" goal is equivalent to the RTC "accept" command.
37  //
38  // NOTE: What is not clear from the docs, is that the accept command will also
39  // update the sandbox with the changes that have been accepted into the repository.
40  // However, I have checked with Rational Support, and this is indeed the expected
41  // behaviour. This may come from the fact that you can accept changes into a
42  // repository workspace, without having a sandbox loaded; though this makes no
43  // sense to us from a maven usage context (as we only work in a sandbox).
44  //
45  // See the following links for additional information on the RTC "create snapshot" command:
46  // RTC 2.0.0.2:
47  // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
48  // RTC 3.0:
49  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
50  // RTC 3.0.1:
51  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
52  //
53  
54  /**
55   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
56   */
57  public class JazzUpdateCommand
58      extends AbstractUpdateCommand
59  {
60      /**
61       * {@inheritDoc}
62       */
63      protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
64          throws ScmException
65      {
66          if ( getLogger().isDebugEnabled() )
67          {
68              getLogger().debug( "Executing update command..." );
69          }
70  
71          JazzUpdateConsumer updateConsumer = new JazzUpdateConsumer( repo, getLogger() );
72          ErrorConsumer err = new ErrorConsumer( getLogger() );
73  
74          JazzScmCommand updateCmd = createAcceptCommand( repo, fileSet );
75          int status = updateCmd.execute( updateConsumer, err );
76  
77          if ( status != 0 || err.hasBeenFed() )
78          {
79              return new UpdateScmResult( updateCmd.getCommandString(),
80                                          "Error code for Jazz SCM update command - " + status, err.getOutput(), false );
81          }
82  
83          if ( getLogger().isDebugEnabled() )
84          {
85              if ( !updateConsumer.getUpdatedFiles().isEmpty() )
86              {
87                  getLogger().debug( "Iterating over \"Update\" results" );
88                  for ( ScmFile file : updateConsumer.getUpdatedFiles() )
89                  {
90                      getLogger().debug( file.getPath() + " : " + file.getStatus() );
91                  }
92              }
93              else
94              {
95                  getLogger().debug( "There are no updated files" );
96              }
97          }
98  
99          // Now, just (re)load the workspace into the sand box.
100         // We can use the checkout directory for this.
101         return new UpdateScmResult( updateCmd.getCommandString(), updateConsumer.getUpdatedFiles() );
102     }
103 
104     public JazzScmCommand createAcceptCommand( ScmProviderRepository repo, ScmFileSet fileSet )
105     {
106         JazzScmCommand command = new JazzScmCommand( JazzConstants.CMD_ACCEPT, repo, fileSet, getLogger() );
107 
108         command.addArgument( JazzConstants.ARG_FLOW_COMPONENTS );
109 
110         return command;
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     protected ChangeLogCommand getChangeLogCommand()
117     {
118         JazzChangeLogCommand command = new JazzChangeLogCommand();
119 
120         command.setLogger( getLogger() );
121 
122         return command;
123     }
124 
125 }