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 | 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 | |
|
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 | |
|
98 | |
|
99 | |
|
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 | |
} |