Coverage Report - org.apache.maven.scm.provider.local.command.changelog.LocalChangeLogCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalChangeLogCommand
0 %
0/44
0 %
0/26
20
 
 1  
 package org.apache.maven.scm.provider.local.command.changelog;
 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.io.IOException;
 24  
 import java.util.ArrayList;
 25  
 import java.util.Date;
 26  
 import java.util.List;
 27  
 
 28  
 import org.apache.maven.scm.ChangeFile;
 29  
 import org.apache.maven.scm.ChangeSet;
 30  
 import org.apache.maven.scm.ScmBranch;
 31  
 import org.apache.maven.scm.ScmException;
 32  
 import org.apache.maven.scm.ScmFileSet;
 33  
 import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
 34  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 35  
 import org.apache.maven.scm.command.changelog.ChangeLogSet;
 36  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 37  
 import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
 38  
 import org.codehaus.plexus.util.FileUtils;
 39  
 
 40  
 /**
 41  
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
 42  
  * @author Olivier Lamy
 43  
  * @version $Id: LocalChangeLogCommand.java 1054408 2011-01-02 14:05:25Z olamy $
 44  
  */
 45  0
 public class LocalChangeLogCommand
 46  
     extends AbstractChangeLogCommand
 47  
 {
 48  
     /** {@inheritDoc} */
 49  
     protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 50  
                                                           Date startDate, Date endDate, ScmBranch branch,
 51  
                                                           String datePattern )
 52  
         throws ScmException
 53  
     {
 54  0
         LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
 55  
 
 56  0
         if ( branch != null )
 57  
         {
 58  0
             throw new ScmException( "The local scm doesn't support tags." );
 59  
         }
 60  
 
 61  0
         File root = new File( repo.getRoot() );
 62  
 
 63  0
         String module = repo.getModule();
 64  
 
 65  0
         File source = new File( root, module );
 66  
 
 67  0
         File baseDestination = fileSet.getBasedir();
 68  
 
 69  0
         if ( !baseDestination.exists() )
 70  
         {
 71  0
             throw new ScmException(
 72  
                 "The working directory doesn't exist (" + baseDestination.getAbsolutePath() + ")." );
 73  
         }
 74  
 
 75  0
         if ( !root.exists() )
 76  
         {
 77  0
             throw new ScmException( "The base directory doesn't exist (" + root.getAbsolutePath() + ")." );
 78  
         }
 79  
 
 80  0
         if ( !source.exists() )
 81  
         {
 82  0
             throw new ScmException( "The module directory doesn't exist (" + source.getAbsolutePath() + ")." );
 83  
         }
 84  
 
 85  0
         List<ChangeSet> changeLogList = new ArrayList<ChangeSet>();
 86  
 
 87  
         try
 88  
         {
 89  0
             File repoRoot = new File( repo.getRoot(), repo.getModule() );
 90  
 
 91  0
             List<File> files = fileSet.getFileList();
 92  
 
 93  0
             if ( files.isEmpty() )
 94  
             {
 95  
                 @SuppressWarnings( "unchecked" )
 96  0
                 List<File> fileList = FileUtils.getFiles( baseDestination, "**", null, false );
 97  0
                 files = fileList;
 98  
             }
 99  
 
 100  0
             for ( File file : files )
 101  
             {
 102  
 
 103  0
                 String path = file.getPath().replace( '\\', '/' );
 104  
 
 105  0
                 File repoFile = new File( repoRoot, path );
 106  
 
 107  0
                 file = new File( baseDestination, path );
 108  
 
 109  0
                 ChangeSet changeSet = new ChangeSet();
 110  
 
 111  0
                 int chop = repoRoot.getAbsolutePath().length();
 112  
 
 113  0
                 String fileName = "/" + repoFile.getAbsolutePath().substring( chop + 1 );
 114  
 
 115  0
                 changeSet.addFile( new ChangeFile( fileName, null ) );
 116  
 
 117  0
                 if ( repoFile.exists() )
 118  
                 {
 119  0
                     long lastModified = repoFile.lastModified();
 120  
 
 121  0
                     Date modifiedDate = new Date( lastModified );
 122  
 
 123  0
                     if ( startDate != null )
 124  
                     {
 125  0
                         if ( startDate.before( modifiedDate ) || startDate.equals( modifiedDate ) )
 126  
                         {
 127  0
                             if ( endDate != null )
 128  
                             {
 129  0
                                 if ( endDate.after( modifiedDate ) || endDate.equals( modifiedDate ) )
 130  
                                 {
 131  
                                     // nop
 132  
                                 }
 133  
                                 else
 134  
                                 {
 135  
                                     continue;
 136  
                                 }
 137  
                             }
 138  
                         }
 139  
                         else
 140  
                         {
 141  
                             continue;
 142  
                         }
 143  
                     }
 144  
 
 145  0
                     changeSet.setDate( modifiedDate );
 146  
 
 147  0
                     changeLogList.add( changeSet );
 148  0
                 }
 149  
                 else
 150  
                 {
 151  
                     // This file is deleted
 152  0
                     changeLogList.add( changeSet );
 153  
                 }
 154  0
             }
 155  
         }
 156  0
         catch ( IOException ex )
 157  
         {
 158  0
             throw new ScmException( "Error while getting change logs.", ex );
 159  0
         }
 160  
 
 161  0
         return new ChangeLogScmResult( null, new ChangeLogSet( changeLogList, startDate, endDate ) );
 162  
     }
 163  
 }