1 4 5 9 10 package org.openlaszlo.cm; 11 12 import org.apache.log4j.*; 13 import java.io.*; 14 import java.util.*; 15 import org.openlaszlo.server.LPS; 16 import org.openlaszlo.utils.ChainedException; 17 18 26 class DependencyTracker implements java.io.Serializable { 27 private static Logger mLogger = Logger.getLogger(DependencyTracker.class); 28 29 31 private static class FileInfo implements java.io.Serializable { 32 33 private String mPathname; 34 35 private long mLastMod; 36 37 private boolean mCanRead; 38 39 private long mLength; 40 41 44 FileInfo(String pathname) { 45 mPathname = pathname; 46 File file = new File(pathname); 47 if (file.isDirectory()) { 51 file = new File(pathname + File.separator + "library.lzx"); 52 } 53 mLastMod = ((long)(file.lastModified() / 1000L)) * 1000L; 55 mCanRead = file.canRead(); 56 mLength = file.length(); 58 } 59 60 65 boolean isUpToDate(FileInfo info) { 66 return this.mLastMod == info.mLastMod 67 && this.mCanRead == info.mCanRead 68 && this.mLength == info.mLength; 69 } 70 }; 71 72 73 private final Vector mDependencies = new Vector(); 74 private Properties mProperties; 75 private String mWebappPath; 76 77 DependencyTracker(Properties properties) { 78 this.mProperties = properties; 79 this.mWebappPath = LPS.HOME(); } 81 82 85 void addFile(File file) { 86 mLogger.debug("addFile Path is " + file.getPath()); 87 FileInfo fi = new FileInfo(file.getPath()); 88 try { 89 fi.mPathname = file.getCanonicalPath(); 90 } catch (java.io.IOException e) { 91 throw new ChainedException(e); 92 } 93 mDependencies.add(fi); 94 } 95 96 97 101 void copyFiles(DependencyTracker t, File omitMe) { 102 try { 103 for (Iterator e = t.mDependencies.iterator(); e.hasNext(); ) { 104 FileInfo f = (FileInfo)e.next(); 105 if (! f.mPathname.equals(omitMe.getCanonicalPath())) { 106 mDependencies.add(f); 107 } 108 } 109 } catch (java.io.IOException e) { 110 throw new ChainedException(e); 111 } 112 } 113 114 115 119 void updateWebappPath() { 120 String webappPath = LPS.HOME(); if (webappPath.equals(mWebappPath)) 122 return; 123 mLogger.debug("updating webappPath from: " + mWebappPath); 124 mLogger.debug("updating webappPath to: " + webappPath); 125 for (Iterator e = mDependencies.iterator(); e.hasNext(); ) { 126 FileInfo saved = (FileInfo) e.next(); 127 if (saved.mPathname.startsWith(mWebappPath)) { 128 mLogger.debug("updating dependencies from: " + saved.mPathname); 129 saved.mPathname = webappPath + 130 saved.mPathname.substring(mWebappPath.length()); 131 mLogger.debug("updating dependencies to : " + saved.mPathname); 132 } 133 } 134 mWebappPath = webappPath; 135 } 136 137 142 boolean isUpToDate(Properties properties) { 143 Iterator e; 144 145 { 147 if (mProperties.size() != properties.size()) { 148 mLogger.debug("my size " + mProperties.size()); 149 mLogger.debug("new size " + properties.size()); 150 return false; 151 } 152 153 for (e = mProperties.keySet().iterator(); e.hasNext(); ) { 154 String key = (String ) e.next(); 155 String val0 = mProperties.getProperty(key); 156 String val1 = properties.getProperty(key); 157 158 if (val1 == null || ! val0.equals(val1)) { 160 mLogger.debug("Missing or changed property: " + val0); 161 return false; 162 } 163 } 164 } 165 166 for (e = mDependencies.iterator(); e.hasNext(); ) { 167 FileInfo saved = (FileInfo) e.next(); 168 FileInfo current = new FileInfo(saved.mPathname); 169 if (!saved.isUpToDate(current)) { 170 mLogger.debug(saved.mPathname + " has changed"); 171 mLogger.debug("was " + saved.mLastMod); 172 mLogger.debug(" is " + current.mLastMod); 173 return false; 174 } 175 } 176 return true; 177 } 178 } 179 | Popular Tags |