001package org.apache.maven.scm.provider.cvslib.command.tag;
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 java.io.File;
023import java.util.Iterator;
024
025import org.apache.maven.scm.ScmException;
026import org.apache.maven.scm.ScmFileSet;
027import org.apache.maven.scm.ScmResult;
028import org.apache.maven.scm.ScmTagParameters;
029import org.apache.maven.scm.command.tag.AbstractTagCommand;
030import org.apache.maven.scm.command.tag.TagScmResult;
031import org.apache.maven.scm.provider.ScmProviderRepository;
032import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
033import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
034import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
035import org.apache.maven.scm.provider.cvslib.util.CvsUtil;
036import org.apache.maven.scm.providers.cvslib.settings.Settings;
037import org.codehaus.plexus.util.cli.Commandline;
038
039/**
040 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
041 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
042 *
043 */
044public abstract class AbstractCvsTagCommand
045    extends AbstractTagCommand
046    implements CvsCommand
047{
048    
049    public ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag, String message )
050        throws ScmException
051    {
052        return executeTagCommand( repo, fileSet, tag, new ScmTagParameters( message ) );
053    }
054
055    /** {@inheritDoc} */
056    public ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag,
057                                        ScmTagParameters scmTagParameters )
058        throws ScmException
059    {
060        CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
061
062        Commandline cl = CvsCommandUtils.getBaseCommand( "tag", repository, fileSet, false );
063
064        Settings settings = CvsUtil.getSettings();
065        if ( settings.isUseForceTag() )
066        {
067            cl.createArg().setValue( "-F" );
068        }
069
070        cl.createArg().setValue( "-c" );
071
072        cl.createArg().setValue( tag );
073
074        if ( fileSet.getFileList() != null && !fileSet.getFileList().isEmpty() )
075        {
076            for ( Iterator<File> it = fileSet.getFileList().iterator(); it.hasNext(); )
077            {
078                File fileName = it.next();
079                cl.createArg().setValue( fileName.toString() );
080            }
081        }
082
083        if ( getLogger().isInfoEnabled() )
084        {
085            getLogger().info( "Executing: " + cl );
086            getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
087        }
088
089        return executeCvsCommand( cl );
090    }
091
092    protected abstract TagScmResult executeCvsCommand( Commandline cl )
093        throws ScmException;
094}