View Javadoc

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  	private static final Log log = LogFactory.getLog(ChangeDetector.class);
12  	File controlFile;
13  	List<File> files;
14  
15  	public ChangeDetector() {
16  		this(null, null);
17  	}
18  
19  	public ChangeDetector(File controlFile, List<File> files) {
20  		super();
21  		this.controlFile = controlFile;
22  		this.files = files;
23  	}
24  
25  	/**
26  	 * Return true if any file in the list of files has a last modified timestamp newer than the control file or if the
27  	 * control file does not exist
28  	 */
29  	public boolean isChanged() {
30  		if (!getControlFile().exists()) {
31  			log.debug("File " + getControlFile().getAbsolutePath() + " does not exist.  Returning true");
32  			return true;
33  		}
34  		long lastModified = getControlFile().lastModified();
35  		for (File file : getFiles()) {
36  			if (file.lastModified() > lastModified) {
37  				log.debug("File " + file.getAbsolutePath() + " was modified after " + getControlFile().getAbsolutePath() + " was last modified");
38  				return true;
39  			}
40  		}
41  		log.debug("No files were modified.");
42  		return false;
43  	}
44  
45  	public File getControlFile() {
46  		return controlFile;
47  	}
48  
49  	public void setControlFile(File controlFile) {
50  		this.controlFile = controlFile;
51  	}
52  
53  	public List<File> getFiles() {
54  		return files;
55  	}
56  
57  	public void setFiles(List<File> files) {
58  		this.files = files;
59  	}
60  }