Coverage Report - org.apache.maven.scm.provider.cvslib.command.checkin.AbstractCvsCheckInCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractCvsCheckInCommand
0 %
0/24
0 %
0/8
4,5
 
 1  
 package org.apache.maven.scm.provider.cvslib.command.checkin;
 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.io.IOException;
 24  
 import java.util.List;
 25  
 
 26  
 import org.apache.maven.scm.ScmException;
 27  
 import org.apache.maven.scm.ScmFileSet;
 28  
 import org.apache.maven.scm.ScmVersion;
 29  
 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
 30  
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
 31  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 32  
 import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
 33  
 import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
 34  
 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
 35  
 import org.codehaus.plexus.util.FileUtils;
 36  
 import org.codehaus.plexus.util.StringUtils;
 37  
 import org.codehaus.plexus.util.cli.Commandline;
 38  
 
 39  
 /**
 40  
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
 41  
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 42  
  * @author Olivier Lamy
 43  
  * @version $Id: AbstractCvsCheckInCommand.java 1054455 2011-01-02 18:40:29Z olamy $
 44  
  */
 45  0
 public abstract class AbstractCvsCheckInCommand
 46  
     extends AbstractCheckInCommand
 47  
     implements CvsCommand
 48  
 {
 49  
     /** {@inheritDoc} */
 50  
     protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
 51  
                                                       ScmVersion version )
 52  
         throws ScmException
 53  
     {
 54  0
         CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
 55  
 
 56  0
         Commandline cl = CvsCommandUtils.getBaseCommand( "commit", repository, fileSet, false );
 57  
 
 58  0
         if ( version != null && !StringUtils.isEmpty( version.getName() ) )
 59  
         {
 60  0
             cl.createArg().setValue( "-r" + version.getName() );
 61  
         }
 62  
 
 63  0
         cl.createArg().setValue( "-R" );
 64  
 
 65  0
         cl.createArg().setValue( "-F" );
 66  
 
 67  
         File messageFile;
 68  
 
 69  
         try
 70  
         {
 71  0
             messageFile = File.createTempFile( "scm-commit-message", ".txt" );
 72  
 
 73  0
             FileUtils.fileWrite( messageFile.getAbsolutePath(), message );
 74  
         }
 75  0
         catch ( IOException ex )
 76  
         {
 77  0
             throw new ScmException( "Error while making a temporary commit message file." );
 78  0
         }
 79  
 
 80  0
         cl.createArg().setValue( messageFile.getAbsolutePath() );
 81  
 
 82  0
         List<File> files = fileSet.getFileList();
 83  
 
 84  0
         for ( File f : files )
 85  
         {
 86  0
             cl.createArg().setValue( f.getPath().replace( '\\', '/' ) );
 87  
         }
 88  
 
 89  0
         if ( getLogger().isInfoEnabled() )
 90  
         {
 91  0
             getLogger().info( "Executing: " + cl );
 92  0
             getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
 93  
         }
 94  
 
 95  0
         CheckInScmResult result = executeCvsCommand( cl, repository, messageFile );
 96  
 
 97  
         try
 98  
         {
 99  0
             FileUtils.forceDelete( messageFile );
 100  
         }
 101  0
         catch ( IOException ex )
 102  
         {
 103  
             // ignore
 104  0
         }
 105  
 
 106  0
         return result;
 107  
     }
 108  
 
 109  
     protected abstract CheckInScmResult executeCvsCommand( Commandline cl, CvsScmProviderRepository repository,
 110  
                                                            File messageFile )
 111  
         throws ScmException;
 112  
 }