View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  	 * Return true if any file in the list of files has a last modified timestamp newer than the control file or if the
42  	 * control file does not exist
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  }