1 | |
package org.apache.torque.util; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.apache.commons.logging.Log; |
7 | |
import org.apache.commons.logging.LogFactory; |
8 | |
|
9 | |
public class ChangeDetector { |
10 | |
|
11 | 0 | private static final Log log = LogFactory.getLog(ChangeDetector.class); |
12 | |
File controlFile; |
13 | |
List<File> files; |
14 | |
|
15 | |
public ChangeDetector() { |
16 | 0 | this(null, null); |
17 | 0 | } |
18 | |
|
19 | |
public ChangeDetector(File controlFile, List<File> files) { |
20 | 0 | super(); |
21 | 0 | this.controlFile = controlFile; |
22 | 0 | this.files = files; |
23 | 0 | } |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public boolean isChanged() { |
30 | 0 | if (!getControlFile().exists()) { |
31 | 0 | log.debug("File " + getControlFile().getAbsolutePath() + " does not exist. Returning true"); |
32 | 0 | return true; |
33 | |
} |
34 | 0 | long lastModified = getControlFile().lastModified(); |
35 | 0 | for (File file : getFiles()) { |
36 | 0 | if (file.lastModified() > lastModified) { |
37 | 0 | log.debug("File " + file.getAbsolutePath() + " was modified after " + getControlFile().getAbsolutePath() + " was last modified"); |
38 | 0 | return true; |
39 | |
} |
40 | |
} |
41 | 0 | log.debug("No files were modified."); |
42 | 0 | return false; |
43 | |
} |
44 | |
|
45 | |
public File getControlFile() { |
46 | 0 | return controlFile; |
47 | |
} |
48 | |
|
49 | |
public void setControlFile(File controlFile) { |
50 | 0 | this.controlFile = controlFile; |
51 | 0 | } |
52 | |
|
53 | |
public List<File> getFiles() { |
54 | 0 | return files; |
55 | |
} |
56 | |
|
57 | |
public void setFiles(List<File> files) { |
58 | 0 | this.files = files; |
59 | 0 | } |
60 | |
} |