Coverage Report - org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate
 
Classes in this File Line Coverage Branch Coverage Complexity
ConsumerWantsFilePredicate
0%
0/33
0%
0/18
0
 
 1  
 package org.apache.maven.archiva.repository.scanner.functors;
 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.util.List;
 23  
 
 24  
 import org.apache.commons.collections.Predicate;
 25  
 import org.apache.commons.io.FilenameUtils;
 26  
 import org.apache.maven.archiva.common.utils.BaseFile;
 27  
 import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
 28  
 import org.codehaus.plexus.util.SelectorUtils;
 29  
 
 30  
 /**
 31  
  * ConsumerWantsFilePredicate 
 32  
  *
 33  
  * @version $Id: ConsumerWantsFilePredicate.java 825431 2009-10-15 08:18:29Z jzurbano $
 34  
  */
 35  0
 public class ConsumerWantsFilePredicate
 36  
     implements Predicate
 37  
 {
 38  
     private BaseFile basefile;
 39  
 
 40  0
     private boolean isCaseSensitive = true;
 41  
 
 42  0
     private int wantedFileCount = 0;
 43  
 
 44  0
     private long changesSince = 0;
 45  
 
 46  
     public boolean evaluate( Object object )
 47  
     {
 48  0
         boolean satisfies = false;
 49  
 
 50  0
         if ( object instanceof RepositoryContentConsumer )
 51  
         {
 52  0
             RepositoryContentConsumer consumer = (RepositoryContentConsumer) object;
 53  0
             if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) )
 54  
             {
 55  0
                 satisfies = true;
 56  
                 
 57  
                 // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid
 58  0
                 wantedFileCount++;
 59  
 
 60  0
                 if ( !consumer.isProcessUnmodified() )
 61  
                 {
 62  
                     // Timestamp finished points to the last successful scan, not this current one.
 63  0
                     if ( basefile.lastModified() < changesSince )
 64  
                     {
 65  
                         // Skip file as no change has occurred.
 66  0
                         satisfies = false;
 67  
                     }
 68  
                 }
 69  
             }
 70  
         }
 71  
 
 72  0
         return satisfies;
 73  
     }
 74  
 
 75  
     public BaseFile getBasefile()
 76  
     {
 77  0
         return basefile;
 78  
     }
 79  
 
 80  
     public int getWantedFileCount()
 81  
     {
 82  0
         return wantedFileCount;
 83  
     }
 84  
 
 85  
     public boolean isCaseSensitive()
 86  
     {
 87  0
         return isCaseSensitive;
 88  
     }
 89  
 
 90  
     public void setBasefile( BaseFile basefile )
 91  
     {
 92  0
         this.basefile = basefile;
 93  0
         this.wantedFileCount = 0;
 94  0
     }
 95  
 
 96  
     public void setCaseSensitive( boolean isCaseSensitive )
 97  
     {
 98  0
         this.isCaseSensitive = isCaseSensitive;
 99  0
     }
 100  
 
 101  
     private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
 102  
     {
 103  
         // Test excludes first.
 104  0
         List<String> excludes = consumer.getExcludes();
 105  0
         if ( excludes != null )
 106  
         {
 107  0
             for ( String pattern : excludes )
 108  
             {
 109  0
                 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
 110  
                 {
 111  
                     // Definately does NOT WANT FILE.
 112  0
                     return false;
 113  
                 }
 114  
             }
 115  
         }
 116  
 
 117  
         // Now test includes.
 118  0
         for ( String pattern : consumer.getIncludes() )
 119  
         {
 120  0
             if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
 121  
             {
 122  
                 // Specifically WANTS FILE.
 123  0
                 return true;
 124  
             }
 125  
         }
 126  
 
 127  
         // Not included, and Not excluded?  Default to EXCLUDE.
 128  0
         return false;
 129  
     }
 130  
 
 131  
     public void setChangesSince( long changesSince )
 132  
     {
 133  0
         this.changesSince = changesSince;
 134  0
     }
 135  
 }