##### Coverage Report - org.apache.maven.shared.io.scan.StaleResourceScanner

Classes in this File | Line Coverage | Branch Coverage | Complexity
StaleResourceScanner |
0% | 0/27
0% | 0/6
| 2.5;2.5

1 |  |
     package org.apache.maven.shared.io.scan;
2 |  |
3 |  |
     /*
4 |  |
      * Copyright 2001-2005 The Apache Software Foundation.
5 |  |
      *
6 |  |
      * Licensed under the Apache License, Version 2.0 (the "License");
7 |  |
      * you may not use this file except in compliance with the License.
8 |  |
      * You may obtain a copy of the License at
9 |  |
      *
10 |  |
      *      http://www.apache.org/licenses/LICENSE-2.0
11 |  |
      *
12 |  |
      * Unless required by applicable law or agreed to in writing, software
13 |  |
      * distributed under the License is distributed on an "AS IS" BASIS,
14 |  |
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 |  |
      * See the License for the specific language governing permissions and
16 |  |
      * limitations under the License.
17 |  |
      */
18 |  |
19 |  |
     import org.apache.maven.shared.io.scan.mapping.SourceMapping;
20 |  |
21 |  |
     import java.io.File;
22 |  |
     import java.util.Collections;
23 |  |
     import java.util.HashSet;
24 |  |
     import java.util.Iterator;
25 |  |
     import java.util.List;
26 |  |
     import java.util.Set;
27 |  |
28 |  |
     /**
29 |  |
      * @author jdcasey
30 |  |
      * @version $Id: org.apache.maven.shared.io.scan.StaleResourceScanner.html 2271 2006-08-22 15:19:41Z joakime $
31 |  |
      */
32 |  |
     public class StaleResourceScanner
33 |  |
         extends AbstractResourceInclusionScanner
34 |  |
     {
35 |  |
         private final long lastUpdatedWithinMsecs;
36 |  |
37 |  |
         private final Set sourceIncludes;
38 |  |
39 |  |
         private final Set sourceExcludes;
40 |  |
41 |  |
         // ----------------------------------------------------------------------
42 |  |
         //
43 |  |
         // ----------------------------------------------------------------------
44 |  |
45 |  |
         public StaleResourceScanner()
46 |  |
         {
47 | 0 |
             this( 0, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
48 | 0 |
         }
49 |  |
50 |  |
         public StaleResourceScanner( long lastUpdatedWithinMsecs )
51 |  |
         {
52 | 0 |
             this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
53 | 0 |
         }
54 |  |
55 | 0 |
         public StaleResourceScanner( long lastUpdatedWithinMsecs, Set sourceIncludes, Set sourceExcludes )
56 |  |
         {
57 | 0 |
             this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs;
58 |  |
59 | 0 |
             this.sourceIncludes = sourceIncludes;
60 |  |
61 | 0 |
             this.sourceExcludes = sourceExcludes;
62 | 0 |
         }
63 |  |
64 |  |
         // ----------------------------------------------------------------------
65 |  |
         // SourceInclusionScanner Implementation
66 |  |
         // ----------------------------------------------------------------------
67 |  |
68 |  |
         public Set getIncludedSources( File sourceDir, File targetDir )
69 |  |
             throws InclusionScanException
70 |  |
         {
71 | 0 |
             List srcMappings = getSourceMappings();
72 |  |
73 | 0 |
             if ( srcMappings.isEmpty() )
74 |  |
             {
75 | 0 |
                 return Collections.EMPTY_SET;
76 |  |
             }
77 |  |
78 | 0 |
             String[] potentialIncludes = scanForSources( sourceDir, sourceIncludes, sourceExcludes );
79 |  |
80 | 0 |
             Set matchingSources = new HashSet();
81 |  |
82 | 0 |
             for ( int i = 0; i < potentialIncludes.length; i++ )
83 |  |
             {
84 | 0 |
                 String path = potentialIncludes[i];
85 |  |
86 | 0 |
                 File sourceFile = new File( sourceDir, path );
87 |  |
88 | 0 |
                 staleSourceFileTesting: for ( Iterator patternIt = srcMappings.iterator(); patternIt.hasNext(); )
89 |  |
                 {
90 | 0 |
                     SourceMapping mapping = (SourceMapping) patternIt.next();
91 |  |
92 | 0 |
                     Set targetFiles = mapping.getTargetFiles( targetDir, path );
93 |  |
94 |  |
                     // never include files that don't have corresponding target mappings.
95 |  |
                     // the targets don't have to exist on the filesystem, but the
96 |  |
                     // mappers must tell us to look for them.
97 | 0 |
                     for ( Iterator targetIt = targetFiles.iterator(); targetIt.hasNext(); )
98 |  |
                     {
99 | 0 |
                         File targetFile = (File) targetIt.next();
100 |  |
101 | 0 |
                         if ( !targetFile.exists()
102 | 0 |
                             || ( targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified() ) )
103 |  |
                         {
104 | 0 |
                             matchingSources.add( sourceFile );
105 | 0 |
                             break staleSourceFileTesting;
106 |  |
                         }
107 |  |
                     }
108 |  |
                 }
109 |  |
             }
110 |  |
111 | 0 |
             return matchingSources;
112 |  |
         }
113 |  |
     }