View Javadoc

1   package org.apache.maven.scm.provider.jazz.command.unedit;
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.unedit.AbstractUnEditCommand;
29  import org.apache.maven.scm.command.unedit.UnEditScmResult;
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 JazzUnEditCommand
62      extends AbstractUnEditCommand
63  {
64      /**
65       * {@inheritDoc}
66       */
67      protected ScmResult executeUnEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
68          throws ScmException
69      {
70          if ( getLogger().isDebugEnabled() )
71          {
72              getLogger().debug( "Executing unedit command..." );
73          }
74  
75          DebugLoggerConsumer uneditConsumer = new DebugLoggerConsumer( getLogger() );
76          ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
77  
78          JazzScmCommand uneditCmd = createUneditCommand( repo, fileSet );
79          int status = uneditCmd.execute( uneditConsumer, errConsumer );
80  
81          if ( status != 0 || errConsumer.hasBeenFed() )
82          {
83              return new UnEditScmResult( uneditCmd.getCommandString(),
84                                          "Error code for Jazz SCM unedit command - " + status, errConsumer.getOutput(),
85                                          false );
86          }
87  
88          return new UnEditScmResult( uneditCmd.getCommandString(), "Successfully Completed.", uneditConsumer.getOutput(),
89                                      true );
90      }
91  
92      public JazzScmCommand createUneditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
93      {
94          JazzScmCommand command =
95              new JazzScmCommand( JazzConstants.CMD_LOCK, JazzConstants.CMD_SUB_RELEASE, repo, fileSet, getLogger() );
96  
97          List<File> files = fileSet.getFileList();
98          if ( files != null && !files.isEmpty() )
99          {
100             for ( File file : files )
101             {
102                 command.addArgument( file.getPath() ); // Un-Lock only the files specified
103             }
104         }
105         else
106         {
107             command.addArgument( "." ); // Un-Lock all files
108         }
109 
110         return command;
111     }
112 }