001package org.apache.maven.scm.provider.cvslib.command.diff;
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.diff.AbstractDiffCommand;
026import org.apache.maven.scm.command.diff.DiffScmResult;
027import org.apache.maven.scm.provider.ScmProviderRepository;
028import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
029import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
030import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
031import org.codehaus.plexus.util.StringUtils;
032import org.codehaus.plexus.util.cli.Commandline;
033
034/**
035 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
036 *
037 */
038public abstract class AbstractCvsDiffCommand
039    extends AbstractDiffCommand
040    implements CvsCommand
041{
042    /** {@inheritDoc} */
043    protected DiffScmResult executeDiffCommand( ScmProviderRepository repo, ScmFileSet fileSet,
044                                                ScmVersion startRevision, ScmVersion endRevision )
045        throws ScmException
046    {
047        CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
048
049        Commandline cl = CvsCommandUtils.getBaseCommand( "diff", repository, fileSet );
050
051        cl.createArg().setValue( "-u" );
052
053        if ( isSupportNewFileParameter() )
054        {
055            cl.createArg().setValue( "-N" );
056        }
057
058        if ( startRevision != null && StringUtils.isNotEmpty( startRevision.getName() ) )
059        {
060            cl.createArg().setValue( "-r" );
061            cl.createArg().setValue( startRevision.getName() );
062        }
063
064        if ( endRevision != null && StringUtils.isNotEmpty( endRevision.getName() ) )
065        {
066            cl.createArg().setValue( "-r" );
067            cl.createArg().setValue( endRevision.getName() );
068        }
069
070        if ( getLogger().isInfoEnabled() )
071        {
072            getLogger().info( "Executing: " + cl );
073            getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
074        }
075
076        return executeCvsCommand( cl );
077    }
078
079    protected abstract DiffScmResult executeCvsCommand( Commandline cl )
080        throws ScmException;
081
082    protected boolean isSupportNewFileParameter()
083    {
084        return true;
085    }
086}