1 29 30 package com.caucho.vfs; 31 32 import java.util.logging.Level ; 33 import java.util.logging.Logger ; 34 35 38 public class Depend implements PersistentDependency { 39 private static final Logger log 40 = Logger.getLogger(Depend.class.getName()); 41 42 Path _source; 43 long _lastModified; 44 long _length; 45 46 boolean _requireSource = true; 47 boolean _isDigestModified; 48 49 54 public Depend(Path source, long lastModified, long length) 55 { 56 _source = source; 57 _lastModified = lastModified; 58 _length = length; 59 } 60 61 66 public Depend(Path source) 67 { 68 72 73 _source = source; 74 _lastModified = source.getLastModified(); 75 _length = source.getLength(); 76 } 77 78 84 public Depend(Path source, long digest) 85 { 86 this(source, digest, true); 87 } 88 89 95 public Depend(Path source, long digest, boolean requireSource) 96 { 97 _source = source; 98 99 long newDigest = source.getCrc64(); 100 101 _requireSource = requireSource; 102 103 if (newDigest == digest) { 104 } 105 else if (! requireSource && newDigest == -1) { 106 } 107 else if (newDigest == -1) { 108 if (log.isLoggable(Level.FINE)) 109 log.fine(_source.getNativePath() + " source is deleted."); 110 111 _isDigestModified = true; 112 } 113 else { 114 118 119 _isDigestModified = true; 120 } 121 122 _lastModified = _source.getLastModified(); 123 _length = _source.getLength(); 124 } 125 126 129 public Path getPath() 130 { 131 return _source; 132 } 133 134 137 public long getLastModified() 138 { 139 return _source.getLastModified(); 140 } 141 142 145 public long getLength() 146 { 147 return _source.getLength(); 148 } 149 150 153 public boolean getRequireSource() 154 { 155 return _requireSource; 156 } 157 158 161 public void setRequireSource(boolean requireSource) 162 { 163 _requireSource = requireSource; 164 } 165 166 171 public boolean isModified() 172 { 173 if (_isDigestModified) { 174 if (log.isLoggable(Level.FINE)) 175 log.fine(_source.getNativePath() + " digest is modified."); 176 177 return true; 178 } 179 180 long sourceLastModified = _source.getLastModified(); 181 long sourceLength = _source.getLength(); 182 183 if (! _requireSource && sourceLastModified == 0) 185 return false; 186 else if (sourceLength != _length) { 188 if (log.isLoggable(Level.FINE)) 189 log.fine(_source.getNativePath() + " length is modified (" + 190 _length + " -> " + sourceLength + ")"); 191 192 return true; 193 } 194 else if (sourceLastModified != _lastModified) { 196 if (log.isLoggable(Level.FINE)) 197 log.fine(_source.getNativePath() + " time is modified."); 198 199 return true; 200 } 201 else 202 return false; 203 } 204 205 208 public long getDigest() 209 { 210 return _source.getCrc64(); 211 } 212 213 217 public boolean equals(Object obj) 218 { 219 if (! (obj instanceof Depend)) 220 return false; 221 222 Depend depend = (Depend) obj; 223 224 return _source.equals(depend._source); 225 } 226 227 230 public String getJavaCreateString() 231 { 232 return ("new com.caucho.vfs.Depend(com.caucho.vfs.Vfs.lookup(\"" + 233 _source.getPath() + "\"), " + _source.getCrc64() + "L)"); 234 } 235 236 239 public String toString() 240 { 241 return ("Depend[" + _source + " " + _lastModified + " " + 242 (_source.getLastModified() - _lastModified) + "]"); 243 } 244 } 245 | Popular Tags |