1 package org.codehaus.plexus.compiler.util.scan;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20 import java.util.Collections;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25 import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
26
27
28
29
30 public class StaleSourceScanner extends AbstractSourceInclusionScanner {
31 private final long lastUpdatedWithinMsecs;
32
33 private final Set<String> sourceIncludes;
34
35 private final Set<String> sourceExcludes;
36
37
38
39
40
41 public StaleSourceScanner() {
42 this(0, Collections.singleton("**/*"), Collections.emptySet());
43 }
44
45 public StaleSourceScanner(long lastUpdatedWithinMsecs) {
46 this(lastUpdatedWithinMsecs, Collections.singleton("**/*"), Collections.emptySet());
47 }
48
49 public StaleSourceScanner(long lastUpdatedWithinMsecs, Set<String> sourceIncludes, Set<String> sourceExcludes) {
50 this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs;
51
52 this.sourceIncludes = sourceIncludes;
53
54 this.sourceExcludes = sourceExcludes;
55 }
56
57
58
59
60
61 public Set<File> getIncludedSources(File sourceDir, File targetDir) throws InclusionScanException {
62 List<SourceMapping> srcMappings = getSourceMappings();
63
64 if (srcMappings.isEmpty()) {
65 return Collections.emptySet();
66 }
67
68 String[] potentialIncludes = scanForSources(sourceDir, sourceIncludes, sourceExcludes);
69
70 Set<File> matchingSources = new HashSet<>();
71
72 for (String path : potentialIncludes) {
73 File sourceFile = new File(sourceDir, path);
74
75 staleSourceFileTesting:
76 for (SourceMapping mapping : srcMappings) {
77 Set<File> targetFiles = mapping.getTargetFiles(targetDir, path);
78
79
80
81
82 for (File targetFile : targetFiles) {
83 if (!targetFile.exists()
84 || (targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified())) {
85 matchingSources.add(sourceFile);
86 break staleSourceFileTesting;
87 }
88 }
89 }
90 }
91
92 return matchingSources;
93 }
94 }