View Javadoc
1   package org.apache.maven.scm.provider.jazz.command.checkout;
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.ScmBranch;
23  import org.apache.maven.scm.ScmException;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmTag;
26  import org.apache.maven.scm.ScmVersion;
27  import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
28  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
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.consumer.ErrorConsumer;
33  import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
34  import org.codehaus.plexus.util.StringUtils;
35  
36  //
37  // The Maven SCM plugin "checkout" goal is equivalent to the RTC "load" command.
38  //
39  // See the following links for additional information on the RTC "load" command:
40  // RTC 2.0.0.2:
41  // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_load.html
42  // RTC 3.0:
43  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_load.html
44  // RTC 3.0.1:
45  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_load.html
46  //
47  
48  /**
49   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
50   */
51  public class JazzCheckOutCommand
52      extends AbstractCheckOutCommand
53  {
54      /**
55       * {@inheritDoc}
56       */
57      protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
58                                                          ScmVersion scmVersion, boolean recursive )
59          throws ScmException
60      {
61          // TODO - Figure out how this recursive boolean impacts Jazz SCM "checkout" (load).
62  
63          if ( getLogger().isDebugEnabled() )
64          {
65              getLogger().debug( "Executing checkout command..." );
66          }
67  
68          JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
69  
70          JazzScmCommand checkoutCmd = createJazzLoadCommand( jazzRepo, fileSet, scmVersion );
71          JazzCheckOutConsumer checkoutConsumer = new JazzCheckOutConsumer( repo, getLogger() );
72          ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
73  
74          int status = checkoutCmd.execute( checkoutConsumer, errConsumer );
75          if ( status != 0 || errConsumer.hasBeenFed() )
76          {
77              return new CheckOutScmResult( checkoutCmd.getCommandString(),
78                                            "Error code for Jazz SCM checkout (load) command - " + status,
79                                            errConsumer.getOutput(), false );
80          }
81  
82          return new CheckOutScmResult( checkoutCmd.getCommandString(), checkoutConsumer.getCheckedOutFiles() );
83      }
84  
85      public JazzScmCommand createJazzLoadCommand( JazzScmProviderRepository repo, ScmFileSet fileSet,
86                                                   ScmVersion scmVersion )
87      {
88          JazzScmCommand command =
89              new JazzScmCommand( JazzConstants.CMD_LOAD, JazzConstants.ARG_FORCE, repo, fileSet, getLogger() );
90  
91          if ( fileSet != null )
92          {
93              command.addArgument( JazzConstants.ARG_LOCAL_WORKSPACE_PATH );
94              command.addArgument( fileSet.getBasedir().getAbsolutePath() );
95          }
96  
97          // This works in tandem with the Tag Command.
98          // Currently, RTC can not check out directly from a snapshot.
99          // So, as a work around, the Tag Command creates a workspace name of the same name as the snapshot.
100         // The functionality here (in using the ScmTag or ScmBranch) assumes that the workspace has been
101         // created as a part of the Tag Command. 
102 
103         String workspace = repo.getRepositoryWorkspace();
104         if ( scmVersion != null && StringUtils.isNotEmpty( scmVersion.getName() ) )
105         {
106             // Just in case we ever do something different for Tags (snapshots) and Branches (streams)
107             if ( scmVersion instanceof ScmTag )
108             {
109                 workspace = scmVersion.getName();
110             }
111             else if ( scmVersion instanceof ScmBranch )
112             {
113                 workspace = scmVersion.getName();
114             }
115         }
116 
117         command.addArgument( workspace );
118 
119         return command;
120     }
121 }