From: Peter S. <sch...@us...> - 2006-01-24 16:26:29
|
Update of /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17184/Plb/src/java/net/sf/plb4jedit/plb Modified Files: PlbPlugin.java Include.java IncludeCache.java Log Message: update includes if they changed in cache Index: IncludeCache.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/IncludeCache.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IncludeCache.java 22 Nov 2004 08:35:51 -0000 1.2 +++ IncludeCache.java 24 Jan 2006 16:26:20 -0000 1.3 @@ -2,6 +2,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.util.Date; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; @@ -17,6 +18,7 @@ public class IncludeCache { private static int MAX_ENTRY = 1000; Map cache; + Map cacheEntryTimes; /** singleton instance of this instance */ private static IncludeCache instance; @@ -24,6 +26,7 @@ private IncludeCache() { // TODO handle MAX_ENTRY cache = new WeakHashMap(MAX_ENTRY); + cacheEntryTimes = new WeakHashMap(MAX_ENTRY); } /** @@ -52,28 +55,34 @@ IOException { if (cache.containsKey(absolutePath)) { - return (Include) cache.get(absolutePath); - } else { - Include inc = new Include(absolutePath); - Log.log(Log.DEBUG, this, "add entry no " + cache.size() + " " - + absolutePath); - cache.put(absolutePath, inc); + Include inc = (Include) cache.get(absolutePath); + Date entryTime = (Date)cacheEntryTimes.get(inc); + if (inc.getFile().lastModified() > entryTime.getTime()) { + inc = newEntry(absolutePath); + } return inc; + } else { + return newEntry(absolutePath); } } + + private Include newEntry(String absolutePath) throws FileNotFoundException, IOException { + Include inc = new Include(absolutePath); + Log.log(Log.DEBUG, this, "add entry no " + cache.size() + " " + + absolutePath); + cache.put(absolutePath, inc); + cacheEntryTimes.put(inc,new Date()); + return inc; + } public Include getBySource(PlbSource source) throws FileNotFoundException, IOException { - if (cache.containsKey(source.getPath())) { - return (Include) cache.get(source.getPath()); - } else { - Include inc = new Include(source); - Log.log(Log.DEBUG, this, "add entry no " + cache.size() + " " - + source.getPath()); - cache.put(source.getPath(), inc); - return inc; + if (source == null || source.getPath() == null || source.getPath().length() == 0) { + Log.log(Log.ERROR, this, "invalid source argument " + source); + throw new IllegalArgumentException("invalid source argument " + source); } + return getByPath(source.getPath()); } /** @@ -93,5 +102,10 @@ public int getSize() { return cache.size(); } + + public void clear() { + cache.clear(); + cacheEntryTimes.clear(); + } } \ No newline at end of file Index: PlbPlugin.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/PlbPlugin.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- PlbPlugin.java 24 Jan 2006 14:38:16 -0000 1.6 +++ PlbPlugin.java 24 Jan 2006 16:26:20 -0000 1.7 @@ -197,6 +197,7 @@ max = level; } } + jEdit.getActiveView().getStatus().setMessage("max level = " + max); return max; } @@ -232,9 +233,7 @@ sdata = SideKickParsedData.getParsedData(view); if (sdata == null || !(sdata instanceof PlbParsedData)) { view.getStatus().setMessage("Buffer not parsed. Parse first."); - Log - .log(Log.DEBUG, jEdit.getPlugin("Plb"), - " no parsed data?!"); + Log.log(Log.DEBUG, jEdit.getPlugin("Plb")," no parsed data?!"); return null; } } Index: Include.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/Include.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Include.java 28 Jun 2005 07:01:12 -0000 1.4 +++ Include.java 24 Jan 2006 16:26:20 -0000 1.5 @@ -48,6 +48,7 @@ IOException { inc = new File(absolutePath); + if (!inc.exists()) { throw new FileNotFoundException("not a valid include " + absolutePath); @@ -56,18 +57,6 @@ scan(source); } - protected Include(PlbSource source) throws FileNotFoundException, - IOException - { - inc = new File(source.getPath()); - if (!inc.exists()) { - throw new FileNotFoundException("not a valid include " - + source.getPath()); - } - - scan(source); - } - /** * gives access to Include Instances via an IncludeCache. * |