001    package org.apache.maven.scm.provider.cvslib.command.mkdir;
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.util.ArrayList;
024    import java.util.List;
025    
026    import org.apache.maven.scm.CommandParameter;
027    import org.apache.maven.scm.CommandParameters;
028    import org.apache.maven.scm.ScmException;
029    import org.apache.maven.scm.ScmFile;
030    import org.apache.maven.scm.ScmFileSet;
031    import org.apache.maven.scm.ScmFileStatus;
032    import org.apache.maven.scm.ScmResult;
033    import org.apache.maven.scm.command.Command;
034    import org.apache.maven.scm.command.mkdir.AbstractMkdirCommand;
035    import org.apache.maven.scm.command.mkdir.MkdirScmResult;
036    import org.apache.maven.scm.provider.ScmProviderRepository;
037    
038    /**
039     * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
040     * @version $Id$
041     */
042    public abstract class AbstractCvsMkdirCommand
043        extends AbstractMkdirCommand
044    {
045        /** {@inheritDoc} */
046        protected MkdirScmResult executeMkdirCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
047                                                      boolean createInLocal )
048            throws ScmException
049        {
050            CommandParameters parameters = new CommandParameters();
051    
052            parameters.setString( CommandParameter.MESSAGE, message == null ? "" : message );
053    
054            parameters.setString( CommandParameter.BINARY, "false" );
055    
056            // just invoke add command
057            Command cmd = getAddCommand();
058            cmd.setLogger( getLogger() );
059    
060            ScmResult addResult = cmd.execute( repository, fileSet, parameters );
061    
062            if ( !addResult.isSuccess() )
063            {
064                return new MkdirScmResult( addResult.getCommandLine().toString(), "The cvs command failed.",
065                                           addResult.getCommandOutput(), false );
066            }
067            
068            List<ScmFile> addedFiles = new ArrayList<ScmFile>();
069            
070            for (File file : fileSet.getFileList()) 
071            {
072                ScmFile scmFile = new ScmFile( file.getPath(), ScmFileStatus.ADDED );
073                addedFiles.add( scmFile );
074            }
075    
076            return new MkdirScmResult( addResult.getCommandLine().toString(), addedFiles );
077        }
078    
079        protected abstract Command getAddCommand();
080    }