001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixxml.targets;
020:
021: import java.util.Iterator;
022: import java.util.TreeSet;
023:
024: import de.schlund.pfixxml.resources.DocrootResource;
025:
026: /**
027: * Dependency referencing a static file on the filesystem
028: *
029: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
030: */
031: public class AuxDependencyFile extends AbstractAuxDependency {
032: private DocrootResource path;
033:
034: private long last_lastModTime = -1;
035:
036: protected int hashCode;
037:
038: public AuxDependencyFile(DocrootResource path) {
039: this .type = DependencyType.FILE;
040: this .path = path;
041: this .hashCode = (type.getTag() + ":" + path.toString())
042: .hashCode();
043: }
044:
045: /**
046: * Returns path to the file containing the referenced include part
047: *
048: * @return path to the include file
049: */
050: public DocrootResource getPath() {
051: return path;
052: }
053:
054: public long getModTime() {
055: if (path.exists() && path.canRead() && path.isFile()) {
056: if (last_lastModTime == 0) {
057: // We change from the file being checked once to not exist to "it exists now".
058: // so we need to make sure that all targets using it will be rebuild.
059: TreeSet<Target> targets = TargetDependencyRelation
060: .getInstance().getAffectedTargets(this );
061: for (Iterator<Target> i = targets.iterator(); i
062: .hasNext();) {
063: VirtualTarget target = (VirtualTarget) i.next();
064: target.setForceUpdate();
065: }
066: }
067: last_lastModTime = path.lastModified();
068: return last_lastModTime;
069: } else {
070: if (last_lastModTime > 0) {
071: // The file existed when last check has been made,
072: // so make sure each target using it is being rebuild
073: TreeSet<Target> targets = TargetDependencyRelation
074: .getInstance().getAffectedTargets(this );
075: for (Iterator<Target> i = targets.iterator(); i
076: .hasNext();) {
077: VirtualTarget target = (VirtualTarget) i.next();
078: target.setForceUpdate();
079: }
080: }
081: last_lastModTime = 0;
082: return 0;
083: }
084: }
085:
086: public boolean equals(Object obj) {
087: if (obj instanceof AuxDependencyFile) {
088: return (this .compareTo((AuxDependency) obj) == 0);
089: } else {
090: return false;
091: }
092: }
093:
094: public int compareTo(AuxDependency o) {
095: int comp;
096:
097: comp = super .compareTo(o);
098: if (comp != 0) {
099: return comp;
100: }
101:
102: AuxDependencyFile a = (AuxDependencyFile) o;
103: return path.compareTo(a.path);
104: }
105:
106: public int hashCode() {
107: return this .hashCode;
108: }
109:
110: public String toString() {
111: return "[AUX/" + getType() + " " + getPath().getRelativePath()
112: + "]";
113: }
114:
115: }
|