Coverage Report - org.apache.maven.scm.provider.bazaar.command.update.BazaarUpdateCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
BazaarUpdateCommand
0 %
0/28
0 %
0/10
4,5
 
 1  
 package org.apache.maven.scm.provider.bazaar.command.update;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.util.ArrayList;
 24  
 import java.util.Iterator;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 import org.apache.maven.scm.ChangeSet;
 29  
 import org.apache.maven.scm.ScmException;
 30  
 import org.apache.maven.scm.ScmFile;
 31  
 import org.apache.maven.scm.ScmFileSet;
 32  
 import org.apache.maven.scm.ScmFileStatus;
 33  
 import org.apache.maven.scm.ScmResult;
 34  
 import org.apache.maven.scm.ScmVersion;
 35  
 import org.apache.maven.scm.command.Command;
 36  
 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
 37  
 import org.apache.maven.scm.command.update.AbstractUpdateCommand;
 38  
 import org.apache.maven.scm.command.update.UpdateScmResult;
 39  
 import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
 40  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 41  
 import org.apache.maven.scm.provider.bazaar.BazaarUtils;
 42  
 import org.apache.maven.scm.provider.bazaar.command.BazaarConstants;
 43  
 import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer;
 44  
 import org.apache.maven.scm.provider.bazaar.command.changelog.BazaarChangeLogCommand;
 45  
 import org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer;
 46  
 import org.codehaus.plexus.util.StringUtils;
 47  
 
 48  
 /**
 49  
  * @author <a href="mailto:torbjorn@smorgrav.org">Torbj�rn Eikli Sm�rgrav</a>
 50  
  * @version $Id: BazaarUpdateCommand.java 1056980 2011-01-09 17:23:55Z olamy $
 51  
  */
 52  0
 public class BazaarUpdateCommand
 53  
     extends AbstractUpdateCommand
 54  
     implements Command
 55  
 {
 56  
 
 57  
     /** {@inheritDoc} */
 58  
     protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
 59  
         throws ScmException
 60  
     {
 61  
 
 62  0
         if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
 63  
         {
 64  0
             throw new ScmException( "This provider can't handle tags." );
 65  
         }
 66  
 
 67  0
         File workingDir = fileSet.getBasedir();
 68  
 
 69  
         // Update branch
 70  0
         String[] updateCmd = new String[] { BazaarConstants.PULL_CMD };
 71  0
         ScmResult updateResult = BazaarUtils.execute( new BazaarConsumer( getLogger() ), getLogger(), workingDir,
 72  
                                                       updateCmd );
 73  
 
 74  0
         if ( !updateResult.isSuccess() )
 75  
         {
 76  0
             return new UpdateScmResult( null, null, updateResult );
 77  
         }
 78  
 
 79  
         // Find changes from last revision
 80  0
         int currentRevision = BazaarUtils.getCurrentRevisionNumber( getLogger(), workingDir );
 81  0
         int previousRevision = currentRevision - 1;
 82  0
         String[] diffCmd =
 83  
             new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision };
 84  0
         BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer( getLogger(), workingDir );
 85  0
         ScmResult diffResult = BazaarUtils.execute( diffConsumer, getLogger(), workingDir, diffCmd );
 86  
 
 87  
         // Now translate between diff and update file status
 88  0
         List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
 89  0
         List<CharSequence> changes = new ArrayList<CharSequence>();
 90  0
         List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
 91  0
         Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
 92  0
         for ( Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); )
 93  
         {
 94  0
             ScmFile file = it.next();
 95  0
             changes.add( diffChanges.get( file ) );
 96  0
             if ( file.getStatus() == ScmFileStatus.MODIFIED )
 97  
             {
 98  0
                 updatedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.PATCHED ) );
 99  
             }
 100  
             else
 101  
             {
 102  0
                 updatedFiles.add( file );
 103  
             }
 104  0
         }
 105  
 
 106  0
         return new UpdateScmResultWithRevision( updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf( currentRevision ), diffResult );
 107  
     }
 108  
 
 109  
     /** {@inheritDoc} */
 110  
     protected ChangeLogCommand getChangeLogCommand()
 111  
     {
 112  0
         BazaarChangeLogCommand command = new BazaarChangeLogCommand();
 113  0
         command.setLogger( getLogger() );
 114  0
         return command;
 115  
     }
 116  
 }