001    /**
002     * Copyright 2004-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.torque.util;
017    
018    import java.io.File;
019    import java.util.List;
020    
021    import org.apache.commons.logging.Log;
022    import org.apache.commons.logging.LogFactory;
023    
024    public class ChangeDetector {
025    
026            private static final Log log = LogFactory.getLog(ChangeDetector.class);
027            File controlFile;
028            List<File> files;
029    
030            public ChangeDetector() {
031                    this(null, null);
032            }
033    
034            public ChangeDetector(File controlFile, List<File> files) {
035                    super();
036                    this.controlFile = controlFile;
037                    this.files = files;
038            }
039    
040            /**
041             * Return true if any file in the list of files has a last modified timestamp newer than the control file or if the
042             * control file does not exist
043             */
044            public boolean isChanged() {
045                    if (!getControlFile().exists()) {
046                            log.debug("File " + getControlFile().getAbsolutePath() + " does not exist.  Returning true");
047                            return true;
048                    }
049                    long lastModified = getControlFile().lastModified();
050                    for (File file : getFiles()) {
051                            if (file.lastModified() > lastModified) {
052                                    log.debug("File " + file.getAbsolutePath() + " was modified after " + getControlFile().getAbsolutePath() + " was last modified");
053                                    return true;
054                            }
055                    }
056                    log.debug("No files were modified.");
057                    return false;
058            }
059    
060            public File getControlFile() {
061                    return controlFile;
062            }
063    
064            public void setControlFile(File controlFile) {
065                    this.controlFile = controlFile;
066            }
067    
068            public List<File> getFiles() {
069                    return files;
070            }
071    
072            public void setFiles(List<File> files) {
073                    this.files = files;
074            }
075    }