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