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 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10130 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java index cd301ad..1b27534 100644 --- a/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java +++ b/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
@@ -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(); @@ -101,6 +103,11 @@ } @Override + public String getResourcePath() { + return resourcePath; + } + + @Override @Deprecated public String getSource() { return sourceToken.readString();
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java b/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java index ce7f5b9..2605eef 100644 --- a/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java +++ b/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
@@ -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);
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java index c7f162d..1d28d64 100644 --- a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java +++ b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
@@ -286,10 +286,19 @@ * 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. */ @Deprecated
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java b/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java index e8e965c..80bf41d 100644 --- a/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java +++ b/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java
@@ -182,6 +182,11 @@ return getLocationFor(generatedUnit); } + @Override + public String getResourcePath() { + return Shared.toPath(generatedUnit.getTypeName()); + } + @Deprecated @Override public String getSource() {
diff --git a/dev/core/src/com/google/gwt/dev/javac/MemoryUnitCache.java b/dev/core/src/com/google/gwt/dev/javac/MemoryUnitCache.java index aa2f8c7..f7c4bbf 100644 --- a/dev/core/src/com/google/gwt/dev/javac/MemoryUnitCache.java +++ b/dev/core/src/com/google/gwt/dev/javac/MemoryUnitCache.java
@@ -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()); } }
diff --git a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java index 543bce3..1277409 100644 --- a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java +++ b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
@@ -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); } }
diff --git a/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java index e7a7833..7866424 100644 --- a/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java +++ b/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java
@@ -63,6 +63,11 @@ return sourceFile.getLocation(); } + @Override + public String getResourcePath() { + return sourceFile.getPath(); + } + @Deprecated @Override public String getSource() {
diff --git a/dev/core/src/com/google/gwt/dev/javac/UnitCache.java b/dev/core/src/com/google/gwt/dev/javac/UnitCache.java index f368ab5..6b1c654 100644 --- a/dev/core/src/com/google/gwt/dev/javac/UnitCache.java +++ b/dev/core/src/com/google/gwt/dev/javac/UnitCache.java
@@ -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.
diff --git a/dev/core/test/com/google/gwt/dev/javac/MemoryUnitCacheTest.java b/dev/core/test/com/google/gwt/dev/javac/MemoryUnitCacheTest.java index 485749b..702a7a2 100644 --- a/dev/core/test/com/google/gwt/dev/javac/MemoryUnitCacheTest.java +++ b/dev/core/test/com/google/gwt/dev/javac/MemoryUnitCacheTest.java
@@ -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()); - } }
diff --git a/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java b/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java index 7ae24fe..eff8fa9 100644 --- a/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java +++ b/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java
@@ -71,6 +71,11 @@ } @Override + public String getResourcePath() { + return Shared.toPath(typeName); + } + + @Override public String getSource() { return source; }
diff --git a/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java b/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java index 27908ed..0f032d8 100644 --- a/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java +++ b/dev/core/test/com/google/gwt/dev/javac/PersistentUnitCacheTest.java
@@ -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());