Revision: 10130
Author: zun...@google.com
Date: Tue May 3 08:35:13 2011
Log: Discards the jar file name in the resource location. It isn't
necessary, and
will cause detritus to build up in the cache if a resource changes from
being
in one jar to another or moves in/out of a .jar file.
Review at http://gwt-code-reviews.appspot.com/1428805
http://code.google.com/p/google-web-toolkit/source/detail?r=10130
Modified:
/trunk/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java
/trunk/dev/core/src/com/google/gwt/dev/javac/MemoryUnitCache.java
/trunk/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
/trunk/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java
/trunk/dev/core/src/com/google/gwt/dev/javac/UnitCache.java
/trunk/dev/core/test/com/google/gwt/dev/javac/MemoryUnitCacheTest.java
/trunk/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java
/trunk/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
Fri Mar 25 16:48:01 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
Tue May 3 08:35:13 2011
@@ -31,6 +31,7 @@
private final ContentId contentId;
private final Dependencies dependencies;
private final String resourceLocation;
+ private final String resourcePath;
private final List<JsniMethod> jsniMethods;
private final long lastModified;
private final MethodArgNamesLookup methodArgNamesLookup;
@@ -55,6 +56,7 @@
this.contentId = unit.getContentId();
this.dependencies = unit.getDependencies();
this.resourceLocation = unit.getResourceLocation();
+ this.resourcePath = unit.getResourcePath();
this.jsniMethods = unit.getJsniMethods();
this.lastModified = unit.getLastModified();
this.methodArgNamesLookup = unit.getMethodArgs();
@@ -99,6 +101,11 @@
public String getResourceLocation() {
return resourceLocation;
}
+
+ @Override
+ public String getResourcePath() {
+ return resourcePath;
+ }
@Override
@Deprecated
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
Thu Apr 28 09:54:26 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
Tue May 3 08:35:13 2011
@@ -393,7 +393,7 @@
ResourceCompilationUnitBuilder builder =
new ResourceCompilationUnitBuilder(typeName, resource);
- CompilationUnit cachedUnit = unitCache.find(resource.getLocation());
+ CompilationUnit cachedUnit = unitCache.find(resource.getPath());
if (cachedUnit != null) {
if (cachedUnit.getLastModified() == resource.getLastModified()) {
cachedUnits.put(builder, cachedUnit);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Tue
Apr 26 08:02:24 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Tue
May 3 08:35:13 2011
@@ -286,9 +286,18 @@
* virtual location (in the case of generators or mock data) where the
source
* for this unit originated. This should be unique for each unit
compiled to
* create a module.
+ *
+ * @see {@link com.google.gwt.dev.resource.Resource#getLocation()}
*/
public abstract String getResourceLocation();
+ /**
+ * Returns the full abstract path of the resource.
+ *
+ * @see {@link com.google.gwt.dev.resource.Resource#getPath()}
+ */
+ public abstract String getResourcePath();
+
/**
* Returns the source code for this unit.
*/
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java
Fri Mar 25 16:48:01 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java
Tue May 3 08:35:13 2011
@@ -181,6 +181,11 @@
public String getResourceLocation() {
return getLocationFor(generatedUnit);
}
+
+ @Override
+ public String getResourcePath() {
+ return Shared.toPath(generatedUnit.getTypeName());
+ }
@Deprecated
@Override
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/MemoryUnitCache.java Thu
Mar 24 15:47:57 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/MemoryUnitCache.java Tue
May 3 08:35:13 2011
@@ -26,7 +26,7 @@
/**
* This cache stores {@link CompilationUnit} instances in a Map.
*
- * Only one unit is cached per resource location. If the contentId of the
unit
+ * Only one unit is cached per resource path. If the contentId of the unit
* changes, the old unit is discarded and replaced with the new unit.
*/
class MemoryUnitCache implements UnitCache {
@@ -72,7 +72,7 @@
* References to all {@link CompilationUnit} objects loaded from the
* persistent store, and any new ones added to the store as well.
*
- * The key is resource location.
+ * The key is resource path.
*/
@SuppressWarnings("unchecked")
protected final Map<String, UnitCacheEntry> unitMap = Collections
@@ -91,12 +91,12 @@
*/
public void add(CompilationUnit newUnit) {
UnitCacheEntry newEntry = new UnitCacheEntry(newUnit,
UnitOrigin.RUN_TIME);
- String resourceLocation = newUnit.getResourceLocation();
- UnitCacheEntry oldEntry = unitMap.get(resourceLocation);
+ String resourcePath = newUnit.getResourcePath();
+ UnitCacheEntry oldEntry = unitMap.get(resourcePath);
if (oldEntry != null) {
remove(oldEntry.getUnit());
}
- unitMap.put(resourceLocation, newEntry);
+ unitMap.put(resourcePath, newEntry);
unitMapByContentId.put(newUnit.getContentId(), newEntry);
}
@@ -115,8 +115,8 @@
return null;
}
- public CompilationUnit find(String resourceLocation) {
- UnitCacheEntry entry = unitMap.get(resourceLocation);
+ public CompilationUnit find(String resourcePath) {
+ UnitCacheEntry entry = unitMap.get(resourcePath);
if (entry != null) {
return entry.getUnit();
}
@@ -124,7 +124,7 @@
}
public void remove(CompilationUnit unit) {
- unitMap.remove(unit.getResourceLocation());
+ unitMap.remove(unit.getResourcePath());
unitMapByContentId.remove(unit.getContentId());
}
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
Thu Apr 28 09:54:26 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
Tue May 3 08:35:13 2011
@@ -78,7 +78,7 @@
* uses lots of heap and takes 5-10 seconds. Once the PersistentUnitCache
is
* created, it starts eagerly loading the cache in a background
thread).</li>
*
- * <li>Although units logged to disk with the same resource Location are
+ * <li>Although units logged to disk with the same resource path are
* eventually cleaned up, the most recently compiled unit stays in the
cache
* forever. This means that stale units that are no longer referenced will
never
* be purged, unless by some external action (e.g. ant clean).</li>
@@ -346,7 +346,7 @@
unitCacheMapLoader.await();
super.add(newUnit);
addCount.getAndIncrement();
- unitWriteQueue.add(new
UnitWriteMessage(unitMap.get(newUnit.getResourceLocation())));
+ unitWriteQueue.add(new
UnitWriteMessage(unitMap.get(newUnit.getResourcePath())));
}
/**
@@ -397,9 +397,9 @@
}
@Override
- public CompilationUnit find(String resourceLocation) {
+ public CompilationUnit find(String resourcePath) {
unitCacheMapLoader.await();
- return super.find(resourceLocation);
+ return super.find(resourcePath);
}
/**
@@ -491,13 +491,13 @@
break;
}
UnitCacheEntry entry = new UnitCacheEntry(unit,
UnitOrigin.PERSISTENT);
- UnitCacheEntry oldEntry =
unitMap.get(unit.getResourceLocation());
+ UnitCacheEntry oldEntry =
unitMap.get(unit.getResourcePath());
if (oldEntry != null && unit.getLastModified() >
oldEntry.getUnit().getLastModified()) {
super.remove(oldEntry.getUnit());
- unitMap.put(unit.getResourceLocation(), entry);
+ unitMap.put(unit.getResourcePath(), entry);
unitMapByContentId.put(unit.getContentId(), entry);
} else if (oldEntry == null) {
- unitMap.put(unit.getResourceLocation(), entry);
+ unitMap.put(unit.getResourcePath(), entry);
unitMapByContentId.put(unit.getContentId(), entry);
}
}
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java
Fri Mar 25 16:48:01 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java
Tue May 3 08:35:13 2011
@@ -62,6 +62,11 @@
public String getResourceLocation() {
return sourceFile.getLocation();
}
+
+ @Override
+ public String getResourcePath() {
+ return sourceFile.getPath();
+ }
@Deprecated
@Override
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/UnitCache.java Thu Mar 24
15:47:57 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/UnitCache.java Tue May 3
08:35:13 2011
@@ -40,11 +40,11 @@
CompilationUnit find(ContentId contentId);
/**
- * Lookup a {@link CompilationUnit} by resource location.
+ * Lookup a {@link CompilationUnit} by resource path.
*
- * @see {@link CompilationUnit#getResourceLocation()}
+ * @see {@link CompilationUnit#getResourcePath()}
*/
- CompilationUnit find(String resourceLocation);
+ CompilationUnit find(String resourcePath);
/**
* Remove a {@link CompilationUnit} from the cache.
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/javac/MemoryUnitCacheTest.java
Tue Apr 5 03:08:39 2011
+++ /trunk/dev/core/test/com/google/gwt/dev/javac/MemoryUnitCacheTest.java
Tue May 3 08:35:13 2011
@@ -42,10 +42,10 @@
assertEquals("com.example.Bar", result.getTypeName());
// Find by type name
- result = cache.find("/mock/com/example/Foo.java");
+ result = cache.find("com/example/Foo.java");
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
- result = cache.find("/mock/com/example/Bar.java");
+ result = cache.find("com/example/Bar.java");
assertNotNull(result);
assertEquals("com.example.Bar", result.getTypeName());
cache.cleanup(logger); // should be a no-op
@@ -58,7 +58,7 @@
result = cache.find(foo2.getContentId());
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
- result = cache.find("/mock/com/example/Foo.java");
+ result = cache.find("com/example/Foo.java");
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
assertEquals(foo2.getContentId(), result.getContentId());
@@ -67,23 +67,7 @@
cache.remove(bar1);
result = cache.find(bar1.getContentId());
assertNull(result);
- result = cache.find("/mock/com/example.Bar");
+ result = cache.find("com/example.Bar");
assertNull(result);
}
-
- public void testUnitsWithSameTypeName() {
- MemoryUnitCache cache = new MemoryUnitCache();
- CompilationUnit result;
-
- MockCompilationUnit foo1 = new
MockCompilationUnit("com.example.Foo", "source1", "location1");
- cache.add(foo1);
- MockCompilationUnit foo2 = new
MockCompilationUnit("com.example.Foo", "source2", "location2");
- cache.add(foo2);
- result = cache.find("location1");
- assertEquals("com.example.Foo", result.getTypeName());
- assertEquals(foo1.getContentId(), result.getContentId());
- result = cache.find("location2");
- assertEquals("com.example.Foo", result.getTypeName());
- assertEquals(foo2.getContentId(), result.getContentId());
- }
-}
+}
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java
Tue Apr 5 03:08:39 2011
+++ /trunk/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java
Tue May 3 08:35:13 2011
@@ -69,6 +69,11 @@
public String getResourceLocation() {
return resourceLocation;
}
+
+ @Override
+ public String getResourcePath() {
+ return Shared.toPath(typeName);
+ }
@Override
public String getSource() {
=======================================
---
/trunk/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java
Tue Apr 12 07:43:39 2011
+++
/trunk/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java
Tue May 3 08:35:13 2011
@@ -130,10 +130,10 @@
assertEquals("com.example.Bar", result.getTypeName());
// Find by type name
- result = cache.find("/mock/com/example/Foo.java");
+ result = cache.find("com/example/Foo.java");
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
- result = cache.find("/mock/com/example/Bar.java");
+ result = cache.find("com/example/Bar.java");
assertNotNull(result);
assertEquals("com.example.Bar", result.getTypeName());
@@ -145,7 +145,7 @@
result = cache.find(foo2.getContentId());
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
- result = cache.find("/mock/com/example/Foo.java");
+ result = cache.find("com/example/Foo.java");
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
assertEquals(foo2.getContentId(), result.getContentId());
@@ -160,11 +160,11 @@
// Fire up the cache again. It be pre-populated.
// Search by type name
cache = new PersistentUnitCache(logger, cacheDir);
- result = cache.find("/mock/com/example/Foo.java");
+ result = cache.find("com/example/Foo.java");
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
assertEquals(foo2.getContentId(), result.getContentId());
- result = cache.find("/mock/com/example/Bar.java");
+ result = cache.find("com/example/Bar.java");
assertNotNull(result);
assertEquals("com.example.Bar", result.getTypeName());
assertEquals(bar1.getContentId(), result.getContentId());
@@ -211,12 +211,12 @@
assertEquals("com.example.Bar", result.getTypeName());
assertEquals(bar1.getContentId(), result.getContentId());
- result = cache.find("/mock/com/example/Foo.java");
+ result = cache.find("com/example/Foo.java");
assertNotNull(result);
assertEquals("com.example.Foo", result.getTypeName());
assertEquals(lastUnit.getContentId(), result.getContentId());
- result = cache.find("/mock/com/example/Bar.java");
+ result = cache.find("com/example/Bar.java");
assertNotNull(result);
assertEquals("com.example.Bar", result.getTypeName());
assertEquals(bar1.getContentId(), result.getContentId());
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors