Coverage Report - org.apache.maven.scm.command.update.AbstractUpdateCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractUpdateCommand
0 %
0/27
0 %
0/22
5,333
 
 1  
 package org.apache.maven.scm.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 org.apache.maven.scm.ChangeSet;
 23  
 import org.apache.maven.scm.CommandParameter;
 24  
 import org.apache.maven.scm.CommandParameters;
 25  
 import org.apache.maven.scm.ScmException;
 26  
 import org.apache.maven.scm.ScmFile;
 27  
 import org.apache.maven.scm.ScmFileSet;
 28  
 import org.apache.maven.scm.ScmResult;
 29  
 import org.apache.maven.scm.ScmVersion;
 30  
 import org.apache.maven.scm.command.AbstractCommand;
 31  
 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
 32  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 33  
 import org.apache.maven.scm.command.changelog.ChangeLogSet;
 34  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 35  
 
 36  
 import java.util.ArrayList;
 37  
 import java.util.Date;
 38  
 import java.util.List;
 39  
 
 40  
 /**
 41  
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
 42  
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 43  
  * @version $Id: AbstractUpdateCommand.java 1294386 2012-02-27 23:09:33Z hboutemy $
 44  
  */
 45  0
 public abstract class AbstractUpdateCommand
 46  
     extends AbstractCommand
 47  
 {
 48  
     protected abstract UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 49  
                                                              ScmVersion scmVersion )
 50  
         throws ScmException;
 51  
 
 52  
     /** {@inheritDoc} */
 53  
     public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 54  
                                      CommandParameters parameters )
 55  
         throws ScmException
 56  
     {
 57  0
         ScmVersion scmVersion = parameters.getScmVersion( CommandParameter.SCM_VERSION, null );
 58  
 
 59  0
         boolean runChangelog = Boolean.valueOf(
 60  
             parameters.getString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, "true" ) ).booleanValue();
 61  
 
 62  0
         UpdateScmResult updateScmResult = executeUpdateCommand( repository, fileSet, scmVersion );
 63  
 
 64  0
         List<ScmFile> filesList = updateScmResult.getUpdatedFiles();
 65  
 
 66  0
         if ( !runChangelog )
 67  
         {
 68  0
             return updateScmResult;
 69  
         }
 70  
 
 71  0
         ChangeLogCommand changeLogCmd = getChangeLogCommand();
 72  
 
 73  0
         if ( filesList != null && filesList.size() > 0 && changeLogCmd != null )
 74  
         {
 75  0
             ChangeLogScmResult changeLogScmResult =
 76  
                 (ChangeLogScmResult) changeLogCmd.executeCommand( repository, fileSet, parameters );
 77  
 
 78  0
             List<ChangeSet> changes = new ArrayList<ChangeSet>();
 79  
 
 80  0
             ChangeLogSet changeLogSet = changeLogScmResult.getChangeLog();
 81  
 
 82  0
             if ( changeLogSet != null )
 83  
             {
 84  0
                 Date startDate = null;
 85  
 
 86  
                 try
 87  
                 {
 88  0
                     startDate = parameters.getDate( CommandParameter.START_DATE );
 89  
                 }
 90  0
                 catch ( ScmException e )
 91  
                 {
 92  
                     //Do nothing, startDate isn't define.
 93  0
                 }
 94  
 
 95  0
                 for ( ChangeSet change : changeLogSet.getChangeSets() )
 96  
                 {
 97  0
                     if ( startDate != null && change.getDate() != null )
 98  
                     {
 99  0
                         if ( startDate.after( change.getDate() ) )
 100  
                         {
 101  0
                             continue;
 102  
                         }
 103  
                     }
 104  
 
 105  0
                     for ( ScmFile currentFile : filesList )
 106  
                     {
 107  0
                         if ( change.containsFilename( currentFile.getPath() ) )
 108  
                         {
 109  0
                             changes.add( change );
 110  
 
 111  0
                             break;
 112  
                         }
 113  
                     }
 114  
                 }
 115  
             }
 116  
 
 117  0
             updateScmResult.setChanges( changes );
 118  
         }
 119  
 
 120  0
         return updateScmResult;
 121  
     }
 122  
 
 123  
     protected abstract ChangeLogCommand getChangeLogCommand();
 124  
 }