View Javadoc
1   package org.apache.maven.scm.provider.jazz.command.edit;
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 java.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.scm.ScmException;
26  import org.apache.maven.scm.ScmFileSet;
27  import org.apache.maven.scm.ScmResult;
28  import org.apache.maven.scm.command.edit.AbstractEditCommand;
29  import org.apache.maven.scm.command.edit.EditScmResult;
30  import org.apache.maven.scm.provider.ScmProviderRepository;
31  import org.apache.maven.scm.provider.jazz.command.JazzConstants;
32  import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
33  import org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer;
34  import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
35  
36  // In RTC the need to 'edit' or 'lock' a file is not required. It is actually encouraged to not 
37  // lock 'text' based files and to only lock binary file types.
38  //
39  // The Maven SCM plugin "edit" goal has been implemented by using the RTC "lock acquire/release" commands. 
40  //
41  // See the following links for additional information on the RTC "lock acquire" command:
42  // RTC 2.0.0.2:
43  // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
44  // RTC 3.0:
45  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
46  // RTC 3.0.1:
47  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
48  //
49  // See the following links for additional information on the RTC "lock release" command:
50  // RTC 2.0.0.2:
51  // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
52  // RTC 3.0:
53  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
54  // RTC 3.0.1:
55  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
56  //
57  
58  /**
59   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
60   */
61  public class JazzEditCommand
62      extends AbstractEditCommand
63  {
64      /**
65       * {@inheritDoc}
66       */
67      protected ScmResult executeEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
68          throws ScmException
69      {
70          if ( getLogger().isDebugEnabled() )
71          {
72              getLogger().debug( "Executing edit command..." );
73          }
74  
75          DebugLoggerConsumer editConsumer = new DebugLoggerConsumer( getLogger() );
76          ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
77  
78          JazzScmCommand editCmd = createEditCommand( repo, fileSet );
79          int status = editCmd.execute( editConsumer, errConsumer );
80  
81          if ( status != 0 || errConsumer.hasBeenFed() )
82          {
83              return new EditScmResult( editCmd.getCommandString(), "Error code for Jazz SCM edit command - " + status,
84                                        errConsumer.getOutput(), false );
85          }
86  
87          return new EditScmResult( editCmd.getCommandString(), "Successfully Completed.", editConsumer.getOutput(),
88                                    true );
89      }
90  
91      protected JazzScmCommand createEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
92      {
93          JazzScmCommand command =
94              new JazzScmCommand( JazzConstants.CMD_LOCK, JazzConstants.CMD_SUB_ACQUIRE, repo, fileSet, getLogger() );
95  
96          List<File> files = fileSet.getFileList();
97          if ( files != null && !files.isEmpty() )
98          {
99              for ( File file : files )
100             {
101                 command.addArgument( file.getPath() ); // Lock only the files specified
102             }
103         }
104         else
105         {
106             command.addArgument( "." ); // Lock all files
107         }
108         return command;
109     }
110 }