001    package org.apache.maven.scm.provider.cvslib.cvsexe.command.remove;
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.util.List;
023    
024    import org.apache.maven.scm.ScmException;
025    import org.apache.maven.scm.ScmFile;
026    import org.apache.maven.scm.command.remove.RemoveScmResult;
027    import org.apache.maven.scm.provider.cvslib.command.remove.AbstractCvsRemoveCommand;
028    import org.codehaus.plexus.util.cli.CommandLineException;
029    import org.codehaus.plexus.util.cli.CommandLineUtils;
030    import org.codehaus.plexus.util.cli.Commandline;
031    
032    /**
033     * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
034     * @author Olivier Lamy
035     * @version $Id: CvsExeRemoveCommand.java 1056938 2011-01-09 14:27:54Z olamy $
036     */
037    public class CvsExeRemoveCommand
038        extends AbstractCvsRemoveCommand
039    {
040        /** {@inheritDoc} */
041        protected RemoveScmResult executeCvsCommand( Commandline cl, List<ScmFile> removedFiles )
042            throws ScmException
043        {
044            CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer();
045    
046            CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
047    
048            int exitCode;
049    
050            try
051            {
052                exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
053            }
054            catch ( CommandLineException ex )
055            {
056                throw new ScmException( "Error while executing command.", ex );
057            }
058    
059            // TODO: actually it may have partially succeeded - should we cvs update the files and parse "A " responses?
060            if ( exitCode != 0 )
061            {
062                return new RemoveScmResult( cl.toString(), "The cvs command failed.", stderr.getOutput(), false );
063            }
064    
065            return new RemoveScmResult( cl.toString(), removedFiles );
066        }
067    }