001package org.apache.maven.scm.provider.cvslib.cvsexe.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
022import org.apache.maven.scm.ScmException;
023import org.apache.maven.scm.command.checkin.CheckInScmResult;
024import org.apache.maven.scm.provider.cvslib.command.checkin.AbstractCvsCheckInCommand;
025import org.apache.maven.scm.provider.cvslib.command.checkin.CvsCheckInConsumer;
026import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
027import org.codehaus.plexus.util.FileUtils;
028import org.codehaus.plexus.util.cli.CommandLineException;
029import org.codehaus.plexus.util.cli.CommandLineUtils;
030import org.codehaus.plexus.util.cli.Commandline;
031
032import java.io.File;
033import java.io.IOException;
034
035/**
036 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
037 *
038 */
039public class CvsExeCheckInCommand
040    extends AbstractCvsCheckInCommand
041{
042    /** {@inheritDoc} */
043    protected CheckInScmResult executeCvsCommand( Commandline cl, CvsScmProviderRepository repository,
044                                                  File messageFile )
045        throws ScmException
046    {
047        CvsCheckInConsumer consumer = new CvsCheckInConsumer( repository.getPath(), getLogger() );
048
049        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
050
051        int exitCode;
052
053        try
054        {
055            exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
056        }
057        catch ( CommandLineException ex )
058        {
059            throw new ScmException( "Error while executing command.", ex );
060        }
061
062        try
063        {
064            FileUtils.forceDelete( messageFile );
065        }
066        catch ( IOException ex )
067        {
068            // ignore
069        }
070
071        if ( exitCode != 0 )
072        {
073            return new CheckInScmResult( cl.toString(), "The cvs command failed.", stderr.getOutput(), false );
074        }
075
076        return new CheckInScmResult( cl.toString(), consumer.getCheckedInFiles() );
077    }
078}