Coverage Report - org.apache.maven.shared.io.scan.StaleResourceScanner
 
Classes in this File Line Coverage Branch Coverage Complexity
StaleResourceScanner
0 %
0/28
0 %
0/12
2,5
 
 1  
 package org.apache.maven.shared.io.scan;
 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.shared.io.scan.mapping.SourceMapping;
 23  
 
 24  
 import java.io.File;
 25  
 import java.util.Collections;
 26  
 import java.util.HashSet;
 27  
 import java.util.Iterator;
 28  
 import java.util.List;
 29  
 import java.util.Set;
 30  
 
 31  
 /**
 32  
  * @author jdcasey
 33  
  * @version $Id: StaleResourceScanner.java 595935 2007-11-17 11:39:34Z vsiveton $
 34  
  */
 35  
 public class StaleResourceScanner
 36  
     extends AbstractResourceInclusionScanner
 37  
 {
 38  
     private final long lastUpdatedWithinMsecs;
 39  
 
 40  
     private final Set sourceIncludes;
 41  
 
 42  
     private final Set sourceExcludes;
 43  
 
 44  
     // ----------------------------------------------------------------------
 45  
     //
 46  
     // ----------------------------------------------------------------------
 47  
 
 48  
     public StaleResourceScanner()
 49  
     {
 50  0
         this( 0, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
 51  0
     }
 52  
 
 53  
     public StaleResourceScanner( long lastUpdatedWithinMsecs )
 54  
     {
 55  0
         this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
 56  0
     }
 57  
 
 58  
     public StaleResourceScanner( long lastUpdatedWithinMsecs, Set sourceIncludes, Set sourceExcludes )
 59  0
     {
 60  0
         this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs;
 61  
 
 62  0
         this.sourceIncludes = sourceIncludes;
 63  
 
 64  0
         this.sourceExcludes = sourceExcludes;
 65  0
     }
 66  
 
 67  
     // ----------------------------------------------------------------------
 68  
     // SourceInclusionScanner Implementation
 69  
     // ----------------------------------------------------------------------
 70  
 
 71  
     public Set getIncludedSources( File sourceDir, File targetDir )
 72  
         throws InclusionScanException
 73  
     {
 74  0
         List srcMappings = getSourceMappings();
 75  
 
 76  0
         if ( srcMappings.isEmpty() )
 77  
         {
 78  0
             return Collections.EMPTY_SET;
 79  
         }
 80  
 
 81  0
         String[] potentialIncludes = scanForSources( sourceDir, sourceIncludes, sourceExcludes );
 82  
 
 83  0
         Set matchingSources = new HashSet();
 84  
 
 85  0
         for ( int i = 0; i < potentialIncludes.length; i++ )
 86  
         {
 87  0
             String path = potentialIncludes[i];
 88  
 
 89  0
             File sourceFile = new File( sourceDir, path );
 90  
 
 91  0
             staleSourceFileTesting: for ( Iterator patternIt = srcMappings.iterator(); patternIt.hasNext(); )
 92  
             {
 93  0
                 SourceMapping mapping = (SourceMapping) patternIt.next();
 94  
 
 95  0
                 Set targetFiles = mapping.getTargetFiles( targetDir, path );
 96  
 
 97  
                 // never include files that don't have corresponding target mappings.
 98  
                 // the targets don't have to exist on the filesystem, but the
 99  
                 // mappers must tell us to look for them.
 100  0
                 for ( Iterator targetIt = targetFiles.iterator(); targetIt.hasNext(); )
 101  
                 {
 102  0
                     File targetFile = (File) targetIt.next();
 103  
 
 104  0
                     if ( !targetFile.exists()
 105  
                         || ( targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified() ) )
 106  
                     {
 107  0
                         matchingSources.add( sourceFile );
 108  0
                         break staleSourceFileTesting;
 109  
                     }
 110  0
                 }
 111  0
             }
 112  
         }
 113  
 
 114  0
         return matchingSources;
 115  
     }
 116  
 }