001    package org.apache.maven.scm.provider.cvslib.cvsjava.command.add;
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.add.AddScmResult;
027    import org.apache.maven.scm.provider.cvslib.command.add.AbstractCvsAddCommand;
028    import org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsConnection;
029    import org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener;
030    import org.codehaus.plexus.util.cli.Commandline;
031    
032    /**
033     * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
034     * @version $Id: CvsJavaAddCommand.java 1054126 2010-12-31 15:18:11Z olamy $
035     */
036    public class CvsJavaAddCommand
037        extends AbstractCvsAddCommand
038    {
039        /** {@inheritDoc} */
040        protected AddScmResult executeCvsCommand( Commandline cl, List<ScmFile> addedFiles )
041            throws ScmException
042        {
043            CvsLogListener logListener = new CvsLogListener();
044    
045            try
046            {
047                boolean isSuccess = CvsConnection.processCommand( cl.getArguments(),
048                                                                  cl.getWorkingDirectory().getAbsolutePath(), logListener,
049                                                                  getLogger() );
050    
051                // TODO: actually it may have partially succeeded - should we cvs update the files and parse "A " responses?
052                if ( !isSuccess )
053                {
054                    return new AddScmResult( cl.toString(), "The cvs command failed.", logListener.getStdout().toString(),
055                                             false );
056                }
057    
058                return new AddScmResult( cl.toString(), addedFiles );
059            }
060            catch ( Exception e )
061            {
062                e.printStackTrace();
063                return new AddScmResult( cl.toString(), "The cvs command failed.", logListener.getStdout().toString(),
064                                         false );
065            }
066        }
067    }