001 package org.apache.maven.scm.provider.cvslib.command.checkin;
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.io.IOException;
024 import java.util.List;
025
026 import org.apache.maven.scm.ScmException;
027 import org.apache.maven.scm.ScmFileSet;
028 import org.apache.maven.scm.ScmVersion;
029 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
030 import org.apache.maven.scm.command.checkin.CheckInScmResult;
031 import org.apache.maven.scm.provider.ScmProviderRepository;
032 import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
033 import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
034 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
035 import org.codehaus.plexus.util.FileUtils;
036 import org.codehaus.plexus.util.StringUtils;
037 import org.codehaus.plexus.util.cli.Commandline;
038
039 /**
040 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
041 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
042 * @author Olivier Lamy
043 *
044 */
045 public abstract class AbstractCvsCheckInCommand
046 extends AbstractCheckInCommand
047 implements CvsCommand
048 {
049 /** {@inheritDoc} */
050 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
051 ScmVersion version )
052 throws ScmException
053 {
054 CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
055
056 Commandline cl = CvsCommandUtils.getBaseCommand( "commit", repository, fileSet, false );
057
058 if ( version != null && !StringUtils.isEmpty( version.getName() ) )
059 {
060 cl.createArg().setValue( "-r" + version.getName() );
061 }
062
063 cl.createArg().setValue( "-R" );
064
065 cl.createArg().setValue( "-F" );
066
067 File messageFile;
068
069 try
070 {
071 messageFile = File.createTempFile( "scm-commit-message", ".txt" );
072
073 FileUtils.fileWrite( messageFile.getAbsolutePath(), message );
074 }
075 catch ( IOException ex )
076 {
077 throw new ScmException( "Error while making a temporary commit message file." );
078 }
079
080 cl.createArg().setValue( messageFile.getAbsolutePath() );
081
082 List<File> files = fileSet.getFileList();
083
084 for ( File f : files )
085 {
086 cl.createArg().setValue( f.getPath().replace( '\\', '/' ) );
087 }
088
089 if ( getLogger().isInfoEnabled() )
090 {
091 getLogger().info( "Executing: " + cl );
092 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
093 }
094
095 CheckInScmResult result = executeCvsCommand( cl, repository, messageFile );
096
097 try
098 {
099 FileUtils.forceDelete( messageFile );
100 }
101 catch ( IOException ex )
102 {
103 // ignore
104 }
105
106 return result;
107 }
108
109 protected abstract CheckInScmResult executeCvsCommand( Commandline cl, CvsScmProviderRepository repository,
110 File messageFile )
111 throws ScmException;
112 }