1 package org.apache.maven.shared.io.scan;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
33
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 this( 0, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
51 }
52
53 public StaleResourceScanner( long lastUpdatedWithinMsecs )
54 {
55 this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
56 }
57
58 public StaleResourceScanner( long lastUpdatedWithinMsecs, Set sourceIncludes, Set sourceExcludes )
59 {
60 this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs;
61
62 this.sourceIncludes = sourceIncludes;
63
64 this.sourceExcludes = sourceExcludes;
65 }
66
67
68
69
70
71 public Set getIncludedSources( File sourceDir, File targetDir )
72 throws InclusionScanException
73 {
74 List srcMappings = getSourceMappings();
75
76 if ( srcMappings.isEmpty() )
77 {
78 return Collections.EMPTY_SET;
79 }
80
81 String[] potentialIncludes = scanForSources( sourceDir, sourceIncludes, sourceExcludes );
82
83 Set matchingSources = new HashSet();
84
85 for ( int i = 0; i < potentialIncludes.length; i++ )
86 {
87 String path = potentialIncludes[i];
88
89 File sourceFile = new File( sourceDir, path );
90
91 staleSourceFileTesting: for ( Iterator patternIt = srcMappings.iterator(); patternIt.hasNext(); )
92 {
93 SourceMapping mapping = (SourceMapping) patternIt.next();
94
95 Set targetFiles = mapping.getTargetFiles( targetDir, path );
96
97
98
99
100 for ( Iterator targetIt = targetFiles.iterator(); targetIt.hasNext(); )
101 {
102 File targetFile = (File) targetIt.next();
103
104 if ( !targetFile.exists()
105 || ( targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified() ) )
106 {
107 matchingSources.add( sourceFile );
108 break staleSourceFileTesting;
109 }
110 }
111 }
112 }
113
114 return matchingSources;
115 }
116 }