001    package 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    
022    import org.apache.maven.scm.CommandParameter;
023    import org.apache.maven.scm.CommandParameters;
024    import org.apache.maven.scm.ScmBranchParameters;
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.command.AbstractCommand;
029    import org.apache.maven.scm.provider.ScmProviderRepository;
030    import 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     * @version $Id: AbstractBranchCommand.java 892494 2009-12-19 18:40:43Z olamy $
036     */
037    public 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 = parameters.getScmBranchParameters( CommandParameter.SCM_BRANCH_PARAMETERS );
069            
070            String message = parameters.getString( CommandParameter.MESSAGE, "[maven-scm] copy for branch " + branchName );
071            
072            if (StringUtils.isBlank( scmBranchParameters.getMessage()) && StringUtils.isNotBlank( message ) ) 
073            {
074                scmBranchParameters.setMessage( message );
075            }
076            
077            return executeBranchCommand( repository, fileSet, branchName, scmBranchParameters );
078        }
079    }