001    package 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    
022    import java.io.File;
023    import java.util.Iterator;
024    
025    import org.apache.maven.scm.ScmException;
026    import org.apache.maven.scm.ScmFileSet;
027    import org.apache.maven.scm.ScmResult;
028    import org.apache.maven.scm.ScmTagParameters;
029    import org.apache.maven.scm.command.tag.AbstractTagCommand;
030    import org.apache.maven.scm.command.tag.TagScmResult;
031    import org.apache.maven.scm.provider.ScmProviderRepository;
032    import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
033    import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
034    import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
035    import org.apache.maven.scm.provider.cvslib.util.CvsUtil;
036    import org.apache.maven.scm.providers.cvslib.settings.Settings;
037    import 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     * @version $Id: AbstractCvsTagCommand.java 1056959 2011-01-09 15:02:55Z olamy $
043     */
044    public 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    }