001 package org.apache.torque.util;
002
003 import java.io.File;
004 import java.util.List;
005
006 import org.apache.commons.logging.Log;
007 import org.apache.commons.logging.LogFactory;
008
009 public class ChangeDetector {
010
011 private static final Log log = LogFactory.getLog(ChangeDetector.class);
012 File controlFile;
013 List<File> files;
014
015 public ChangeDetector() {
016 this(null, null);
017 }
018
019 public ChangeDetector(File controlFile, List<File> files) {
020 super();
021 this.controlFile = controlFile;
022 this.files = files;
023 }
024
025 /**
026 * Return true if any file in the list of files has a last modified timestamp newer than the control file or if the
027 * control file does not exist
028 */
029 public boolean isChanged() {
030 if (!getControlFile().exists()) {
031 log.debug("File " + getControlFile().getAbsolutePath() + " does not exist. Returning true");
032 return true;
033 }
034 long lastModified = getControlFile().lastModified();
035 for (File file : getFiles()) {
036 if (file.lastModified() > lastModified) {
037 log.debug("File " + file.getAbsolutePath() + " was modified after " + getControlFile().getAbsolutePath() + " was last modified");
038 return true;
039 }
040 }
041 log.debug("No files were modified.");
042 return false;
043 }
044
045 public File getControlFile() {
046 return controlFile;
047 }
048
049 public void setControlFile(File controlFile) {
050 this.controlFile = controlFile;
051 }
052
053 public List<File> getFiles() {
054 return files;
055 }
056
057 public void setFiles(List<File> files) {
058 this.files = files;
059 }
060 }