001package org.apache.maven.scm.provider.cvslib.command.export;
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.ScmFileSet;
024import org.apache.maven.scm.ScmVersion;
025import org.apache.maven.scm.command.export.AbstractExportCommand;
026import org.apache.maven.scm.command.export.ExportScmResult;
027import org.apache.maven.scm.provider.ScmProviderRepository;
028import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
029import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
030import org.codehaus.plexus.util.StringUtils;
031import org.codehaus.plexus.util.cli.Commandline;
032
033/**
034 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
035 *
036 */
037public abstract class AbstractCvsExportCommand
038    extends AbstractExportCommand
039{
040    /** {@inheritDoc} */
041    protected ExportScmResult executeExportCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version,
042                                                    String outputDirectory )
043        throws ScmException
044    {
045        CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
046
047        Commandline cl = CvsCommandUtils.getBaseCommand( "export", repository, fileSet );
048
049        if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
050        {
051            cl.createArg().setValue( "-r" + version.getName() );
052        }
053        else
054        {
055            cl.createArg().setValue( "-rHEAD" );
056        }
057
058        if ( StringUtils.isNotEmpty( outputDirectory ) )
059        {
060            cl.createArg().setValue( "-d" );
061
062            cl.createArg().setValue( outputDirectory );
063        }
064
065        cl.createArg().setValue( repository.getModule() );
066
067        if ( getLogger().isInfoEnabled() )
068        {
069            getLogger().info( "Executing: " + cl );
070            getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
071        }
072
073        return executeCvsCommand( cl );
074    }
075
076    protected abstract ExportScmResult executeCvsCommand( Commandline cl )
077        throws ScmException;
078}