001package org.apache.maven.scm.command.branch;
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.CommandParameter;
023import org.apache.maven.scm.CommandParameters;
024import org.apache.maven.scm.ScmBranchParameters;
025import org.apache.maven.scm.ScmException;
026import org.apache.maven.scm.ScmFileSet;
027import org.apache.maven.scm.ScmResult;
028import org.apache.maven.scm.command.AbstractCommand;
029import org.apache.maven.scm.provider.ScmProviderRepository;
030import org.codehaus.plexus.util.StringUtils;
031
032/**
033 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
034 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
035 *
036 */
037public abstract class AbstractBranchCommand
038    extends AbstractCommand
039{
040    protected abstract ScmResult executeBranchCommand( ScmProviderRepository repository, ScmFileSet fileSet,
041                                                       String branchName, String message )
042        throws ScmException;
043    
044    /**
045     * default impl to provide backward comp
046     * @since 1.3
047     * @param repository
048     * @param fileSet
049     * @param branchName
050     * @param scmBranchParameters
051     * @return
052     * @throws ScmException
053     */
054    protected ScmResult executeBranchCommand( ScmProviderRepository repository, ScmFileSet fileSet, String branchName,
055                                              ScmBranchParameters scmBranchParameters )
056        throws ScmException
057    {
058        return executeBranchCommand( repository, fileSet, branchName, scmBranchParameters.getMessage() );
059    }
060
061    /** {@inheritDoc} */
062    public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
063                                     CommandParameters parameters )
064        throws ScmException
065    {
066        String branchName = parameters.getString( CommandParameter.BRANCH_NAME );
067
068        ScmBranchParameters scmBranchParameters =
069            parameters.getScmBranchParameters( CommandParameter.SCM_BRANCH_PARAMETERS );
070        
071        String message = parameters.getString( CommandParameter.MESSAGE, "[maven-scm] copy for branch " + branchName );
072        
073        if ( StringUtils.isBlank( scmBranchParameters.getMessage() ) && StringUtils.isNotBlank( message ) )
074        {
075            scmBranchParameters.setMessage( message );
076        }
077        
078        return executeBranchCommand( repository, fileSet, branchName, scmBranchParameters );
079    }
080}