001 package org.apache.maven.scm.provider.jazz.command.edit;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.io.File;
023 import java.util.List;
024
025 import org.apache.maven.scm.ScmException;
026 import org.apache.maven.scm.ScmFileSet;
027 import org.apache.maven.scm.ScmResult;
028 import org.apache.maven.scm.command.edit.AbstractEditCommand;
029 import org.apache.maven.scm.command.edit.EditScmResult;
030 import org.apache.maven.scm.provider.ScmProviderRepository;
031 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
032 import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
033 import org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer;
034 import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
035
036 // In RTC the need to 'edit' or 'lock' a file is not required. It is actually encouraged to not
037 // lock 'text' based files and to only lock binary file types.
038 //
039 // The Maven SCM plugin "edit" goal has been implemented by using the RTC "lock acquire/release" commands.
040 //
041 // See the following links for additional information on the RTC "lock acquire" command:
042 // RTC 2.0.0.2:
043 // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
044 // RTC 3.0:
045 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
046 // RTC 3.0.1:
047 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
048 //
049 // See the following links for additional information on the RTC "lock release" command:
050 // RTC 2.0.0.2:
051 // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
052 // RTC 3.0:
053 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
054 // RTC 3.0.1:
055 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
056 //
057
058 /**
059 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
060 */
061 public class JazzEditCommand
062 extends AbstractEditCommand
063 {
064 /**
065 * {@inheritDoc}
066 */
067 protected ScmResult executeEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
068 throws ScmException
069 {
070 if ( getLogger().isDebugEnabled() )
071 {
072 getLogger().debug( "Executing edit command..." );
073 }
074
075 DebugLoggerConsumer editConsumer = new DebugLoggerConsumer( getLogger() );
076 ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
077
078 JazzScmCommand editCmd = createEditCommand( repo, fileSet );
079 int status = editCmd.execute( editConsumer, errConsumer );
080
081 if ( status != 0 || errConsumer.hasBeenFed() )
082 {
083 return new EditScmResult( editCmd.getCommandString(), "Error code for Jazz SCM edit command - " + status,
084 errConsumer.getOutput(), false );
085 }
086
087 return new EditScmResult( editCmd.getCommandString(), "Successfully Completed.", editConsumer.getOutput(),
088 true );
089 }
090
091 protected JazzScmCommand createEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
092 {
093 JazzScmCommand command =
094 new JazzScmCommand( JazzConstants.CMD_LOCK, JazzConstants.CMD_SUB_ACQUIRE, repo, fileSet, getLogger() );
095
096 List<File> files = fileSet.getFileList();
097 if ( files != null && !files.isEmpty() )
098 {
099 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 }