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 java.io.File;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Set;
27
28 import org.apache.maven.shared.io.scan.mapping.SourceMapping;
29
30
31
32
33
34 public class StaleResourceScanner
35 extends AbstractResourceInclusionScanner
36 {
37 private final long lastUpdatedWithinMsecs;
38
39 private final Set<String> sourceIncludes;
40
41 private final Set<String> sourceExcludes;
42
43
44
45
46
47
48
49
50 public StaleResourceScanner()
51 {
52 this( 0, Collections.singleton( "**/*" ), Collections.<String>emptySet() );
53 }
54
55
56
57
58 public StaleResourceScanner( long lastUpdatedWithinMsecs )
59 {
60 this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.<String>emptySet() );
61 }
62
63
64
65
66
67
68 public StaleResourceScanner( long lastUpdatedWithinMsecs, Set<String> sourceIncludes, Set<String> sourceExcludes )
69 {
70 this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs;
71
72 this.sourceIncludes = sourceIncludes;
73
74 this.sourceExcludes = sourceExcludes;
75 }
76
77
78
79
80
81
82 public Set<File> getIncludedSources( File sourceDir, File targetDir )
83 throws InclusionScanException
84 {
85 List<SourceMapping> srcMappings = getSourceMappings();
86
87 if ( srcMappings.isEmpty() )
88 {
89 return Collections.<File>emptySet();
90 }
91
92 String[] potentialIncludes = scanForSources( sourceDir, sourceIncludes, sourceExcludes );
93
94 Set<File> matchingSources = new HashSet<File>();
95
96 for ( int i = 0; i < potentialIncludes.length; i++ )
97 {
98 String path = potentialIncludes[i];
99
100 File sourceFile = new File( sourceDir, path );
101
102 staleSourceFileTesting: for ( SourceMapping mapping : srcMappings )
103 {
104 Set<File> targetFiles = mapping.getTargetFiles( targetDir, path );
105
106
107
108
109 for ( File targetFile : targetFiles )
110 {
111 if ( !targetFile.exists()
112 || ( targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified() ) )
113 {
114 matchingSources.add( sourceFile );
115 break staleSourceFileTesting;
116 }
117 }
118 }
119 }
120
121 return matchingSources;
122 }
123 }