Revision: 9921
Author: [email protected]
Date: Thu Mar 31 08:40:20 2011
Log: Remove newly-output PersistentUnitCache file if nothing was
written to it.
In the case where you re-run a compile/startup without changing any code,
we produce an empty cache file each time. This change removes the file on
exit if we never wrote anything to it.
http://gwt-code-reviews.appspot.com/1396804/
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9921
Modified:
/trunk/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
/trunk/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
Tue Mar 29 11:29:33 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
Thu Mar 31 08:40:20 2011
@@ -184,7 +184,8 @@
logger.log(TreeLogger.ERROR, "Error creating cache " +
currentCacheFile
+ ". Disabling cache.", ex);
}
- int unitsWritten = 0;
+ int recentUnitsWritten = 0;
+ int totalUnitsWritten = 0;
try {
while (true) {
UnitWriteMessage msg = null;
@@ -202,9 +203,9 @@
try {
if (msg != null) {
if (msg == UnitWriteMessage.DELETE_OLD_CACHE_FILES) {
- logger.log(TreeLogger.TRACE, "Wrote " + unitsWritten
+ logger.log(TreeLogger.TRACE, "Wrote " + recentUnitsWritten
+ " units to persistent cache.");
- unitsWritten = 0;
+ recentUnitsWritten = 0;
deleteOldCacheFiles(logger, currentCacheFile);
} else if (msg == UnitWriteMessage.SHUTDOWN_THREAD) {
stream.flush();
@@ -214,7 +215,8 @@
CompilationUnit unit = msg.unitCacheEntry.getUnit();
assert unit != null;
stream.writeObject(unit);
- unitsWritten++;
+ recentUnitsWritten++;
+ totalUnitsWritten++;
}
}
@@ -234,6 +236,10 @@
// Paranoia - close all streams
Utility.close(bstream);
Utility.close(fstream);
+ if (totalUnitsWritten == 0) {
+ // Remove useless empty output.
+ currentCacheFile.delete();
+ }
shutDownLatch.countDown();
logger.log(TreeLogger.TRACE, "Shutting down PersistentUnitCache
thread");
}
=======================================
---
/trunk/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java
Wed Mar 30 06:55:27 2011
+++
/trunk/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java
Thu Mar 31 08:40:20 2011
@@ -153,14 +153,14 @@
assertEquals(foo2.getContentId(), result.getContentId());
cache.cleanup(logger);
- // Now there should be 2 files.
+ // We didn't write anything, still 1 file.
cache.shutdown();
- assertNumCacheFiles(unitCacheDir, 2);
+ assertNumCacheFiles(unitCacheDir, 1);
// keep making more files
MockCompilationUnit lastUnit = null;
assertTrue(PersistentUnitCache.CACHE_FILE_THRESHOLD > 3);
- for (int i = 3; i < PersistentUnitCache.CACHE_FILE_THRESHOLD; ++i) {
+ for (int i = 2; i < PersistentUnitCache.CACHE_FILE_THRESHOLD; ++i) {
cache = new PersistentUnitCache(logger, cacheDir);
lastUnit = new MockCompilationUnit("com.example.Foo", "Foo Source" +
i);
cache.add(lastUnit);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors