Coverage Report - org.apache.maven.scm.provider.bazaar.command.tag.BazaarTagCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
BazaarTagCommand
0 %
0/23
0 %
0/16
14
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 
 20  
 package org.apache.maven.scm.provider.bazaar.command.tag;
 21  
 
 22  
 import java.io.File;
 23  
 
 24  
 import org.apache.maven.scm.ScmException;
 25  
 import org.apache.maven.scm.ScmFileSet;
 26  
 import org.apache.maven.scm.ScmFileStatus;
 27  
 import org.apache.maven.scm.ScmResult;
 28  
 import org.apache.maven.scm.ScmTagParameters;
 29  
 import org.apache.maven.scm.command.tag.AbstractTagCommand;
 30  
 import org.apache.maven.scm.command.tag.TagScmResult;
 31  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 32  
 import org.apache.maven.scm.provider.bazaar.BazaarUtils;
 33  
 import org.apache.maven.scm.provider.bazaar.command.BazaarConstants;
 34  
 import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer;
 35  
 import org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository;
 36  
 import org.codehaus.plexus.util.StringUtils;
 37  
 
 38  
 /**
 39  
  * @author <a href="mailto:johan.walles@gmail.com">Johan Walles</a>
 40  
  * @version $Id: BazaarTagCommand.java 952830 2010-06-08 21:39:49Z olamy $
 41  
  */
 42  0
 public class BazaarTagCommand extends AbstractTagCommand {
 43  
     protected ScmResult executeTagCommand( ScmProviderRepository repository,
 44  
             ScmFileSet fileSet, String tagName,
 45  
             ScmTagParameters scmTagParameters ) throws ScmException
 46  
     {
 47  0
         if ( tagName == null || StringUtils.isEmpty( tagName.trim() ) ) {
 48  0
             throw new ScmException( "tag name must be specified" );
 49  
         }
 50  
         
 51  0
         if ( !fileSet.getFileList().isEmpty() ) {
 52  0
             throw new ScmException( "tagging specific files is not allowed" );
 53  
         }
 54  
         
 55  
         // Perform the tagging operation
 56  0
         File bazaarRoot = fileSet.getBasedir();
 57  0
         BazaarConsumer consumer = new BazaarConsumer( getLogger() );
 58  0
         String[] tagCmd = new String[] { BazaarConstants.TAG_CMD, tagName };
 59  0
         ScmResult tagResult = BazaarUtils.execute( consumer, getLogger(), bazaarRoot, tagCmd );
 60  0
         if ( !tagResult.isSuccess() ) {
 61  0
             return new TagScmResult( null, tagResult );
 62  
         }
 63  
 
 64  
         // Do "bzr ls -R -r tag:tagName" to get a list of the tagged files
 65  0
         BazaarLsConsumer lsConsumer = 
 66  
             new BazaarLsConsumer( getLogger(), bazaarRoot, ScmFileStatus.TAGGED );
 67  0
         String[] lsCmd = new String[] {
 68  
                                        BazaarConstants.LS_CMD,
 69  
                                        BazaarConstants.RECURSIVE_OPTION,
 70  
                                        BazaarConstants.REVISION_OPTION,
 71  
                                        "tag:" + tagName
 72  
                                        };
 73  0
         ScmResult lsResult = BazaarUtils.execute(lsConsumer, getLogger(), bazaarRoot, lsCmd);
 74  0
         if ( !lsResult.isSuccess() ) {
 75  0
             return new TagScmResult( null, lsResult );
 76  
         }
 77  
         
 78  
         // Push new tags to parent branch if any
 79  0
         BazaarScmProviderRepository bazaarRepository = (BazaarScmProviderRepository) repository;
 80  0
         if ( !bazaarRepository.getURI().equals( fileSet.getBasedir().getAbsolutePath() ) && repository.isPushChanges() )
 81  
         {
 82  0
             String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, bazaarRepository.getURI() };
 83  0
             ScmResult pushResult =
 84  
                 BazaarUtils.execute( new BazaarConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), pushCmd );
 85  0
             if ( !pushResult.isSuccess() ) {
 86  0
                 return new TagScmResult( null, pushResult );
 87  
             }
 88  
         }
 89  
         
 90  0
         return new TagScmResult( lsConsumer.getListedFiles(), tagResult );
 91  
     }
 92  
 }