Revision: 8468
Author: con...@google.com
Date: Tue Aug  3 08:08:39 2010
Log: Rollback r8440 changes again

Review by: rchan...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8468

Added:
 /trunk/dev/core/src/com/google/gwt/dev/cfg/PublicOracle.java
Modified:
 /trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java
 /trunk/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java
 /trunk/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java
 /trunk/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java
 /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java
/trunk/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java
 /trunk/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java
/trunk/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java

=======================================
--- /dev/null
+++ /trunk/dev/core/src/com/google/gwt/dev/cfg/PublicOracle.java Tue Aug 3 08:08:39 2010
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.dev.cfg;
+
+import com.google.gwt.dev.resource.Resource;
+
+/**
+ * Abstracts the process of querying for public files.
+ *
+ * @deprecated with no replacement, just use {...@link ModuleDef} directly
+ */
+...@deprecated
+public interface PublicOracle {
+
+  /**
+   * Finds a file on the public path.
+   *
+ * @param partialPath a file path relative to the root of any public package + * @return the url of the file, or <code>null</code> if no such file exists
+   */
+  Resource findPublicFile(String partialPath);
+
+  /**
+   * Returns all available public files.
+   *
+ * @return an array containing the partial path to each available public file
+   */
+  String[] getAllPublicFiles();
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java Tue Aug 3 08:08:39 2010
@@ -28,7 +28,6 @@
 import com.google.gwt.dev.resource.impl.DefaultFilters;
 import com.google.gwt.dev.resource.impl.PathPrefix;
 import com.google.gwt.dev.resource.impl.PathPrefixSet;
-import com.google.gwt.dev.resource.impl.ResourceFilter;
 import com.google.gwt.dev.resource.impl.ResourceOracleImpl;
 import com.google.gwt.dev.util.Empty;
 import com.google.gwt.dev.util.Util;
@@ -52,13 +51,8 @@
* Represents a module specification. In principle, this could be built without
  * XML for unit tests.
  */
-public class ModuleDef {
-
- private static final ResourceFilter NON_JAVA_RESOURCES = new ResourceFilter() {
-    public boolean allows(String path) {
-      return !path.endsWith(".java") && !path.endsWith(".class");
-    }
-  };
+...@suppresswarnings("deprecation")
+public class ModuleDef implements PublicOracle {

private static final Comparator<Map.Entry<String, ?>> REV_NAME_CMP = new Comparator<Map.Entry<String, ?>>() { public int compare(Map.Entry<String, ?> entry1, Map.Entry<String, ?> entry2) {
@@ -121,7 +115,6 @@
private final Map<String, String> servletClassNamesByPath = new HashMap<String, String>();

   private PathPrefixSet sourcePrefixSet = new PathPrefixSet();
-
   private final Styles styles = new Styles();

   public ModuleDef(String name) {
@@ -334,8 +327,8 @@
       PathPrefixSet pathPrefixes = lazySourceOracle.getPathPrefixes();
       PathPrefixSet newPathPrefixes = new PathPrefixSet();
       for (PathPrefix pathPrefix : pathPrefixes.values()) {
-        newPathPrefixes.add(new PathPrefix(pathPrefix.getPrefix(),
-            NON_JAVA_RESOURCES, pathPrefix.shouldReroot()));
+        newPathPrefixes.add(new PathPrefix(pathPrefix.getPrefix(), null,
+            pathPrefix.shouldReroot()));
       }
       lazyResourcesOracle.setPathPrefixes(newPathPrefixes);
       lazyResourcesOracle.refresh(TreeLogger.NULL);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java Tue Aug 3 08:08:39 2010
@@ -27,15 +27,37 @@
  * <code>com/google/gwt/blah.txt</code>.
  *
  * <p>
- * The identity of the returned sets and maps will change when the underlying
- * module is refreshed.
+ * The identity of the returned sets and maps will change exactly when the
+ * underlying module is refreshed.
  * </p>
+ *
+ * <p>
+ * Even when the identity of a returned set changes, the identity of any
+ * contained {...@link Resource} values is guaranteed to differ from a previous
+ * result exactly when that particular resource becomes invalid.
+ * </p>
+ *
+ * <p>
+ * A resource could become invalid for various reasons, including:
+ * <ul>
+ * <li>the underlying file was deleted or modified</li>
+ * <li>another file with the same logical name superceded it on the classpath</li> + * <li>the underlying module changed to exclude this file or supercede it with
+ * another file</li>
+ * </ul>
+ * </p>
+ *
+ * <p>
+ * After a refresh, a client can reliably detect changes by checking which of
+ * its cached resource is still contained in the new result of
+ * {...@link #getResources()}.
+ * </p>
  */
 public interface ResourceOracle {

   /**
* Frees up all existing resources and transient internal state. All returned
-   * collections will be empty after this call until this ResourceOracle is
+   * collections will be empty after this call until this ResoruceOracle is
    * refreshed.
    */
   void clear();
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java Tue Aug 3 08:08:39 2010
@@ -27,5 +27,7 @@
    * within this package.
    */
   public abstract ClassPathEntry getClassPathEntry();
+
+  public abstract boolean isStale();
 }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java Mon Aug 2 13:26:01 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java Tue Aug 3 08:08:39 2010
@@ -23,7 +23,7 @@
 import java.util.Map;

 /**
- * A {...@link ClassPathEntry} for a directory on the file system.
+ * TODO(bruce): write me.
  */
 public class DirectoryClassPathEntry extends ClassPathEntry {

@@ -41,20 +41,10 @@
         TreeLogger.DEBUG, "Including file: $0");
   }

-  /**
-   * Absolute directory.
-   */
   private final File dir;

-  private final String location;
-
-  /**
-   * @param dir an absolute directory
-   */
   public DirectoryClassPathEntry(File dir) {
-    assert (dir.isAbsolute());
     this.dir = dir;
-    this.location = dir.toURI().toString();
   }

   @Override
@@ -67,7 +57,7 @@

   @Override
   public String getLocation() {
-    return location;
+    return dir.getAbsoluteFile().toURI().toString();
   }

   /**
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java Mon Aug 2 13:26:01 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java Tue Aug 3 08:08:39 2010
@@ -28,6 +28,7 @@
   private final String abstractPathName;
   private final DirectoryClassPathEntry classPathEntry;
   private final File file;
+  private final long modificationSeconds;

   public FileResource(DirectoryClassPathEntry classPathEntry,
       String abstractPathName, File file) {
@@ -35,6 +36,7 @@
     this.classPathEntry = classPathEntry;
     this.abstractPathName = abstractPathName;
     this.file = file;
+    this.modificationSeconds = lastModifiedSeconds(file);
   }

   @Override
@@ -49,13 +51,28 @@

   @Override
   public String getLocation() {
-    return file.toURI().toString();
+    return file.getAbsoluteFile().toURI().toString();
   }

   @Override
   public String getPath() {
     return abstractPathName;
   }
+
+  @Override
+  public boolean isStale() {
+    if (!file.exists()) {
+      // File was deleted. Always stale.
+      return true;
+    }
+
+    long currentModificationSeconds = lastModifiedSeconds(file);
+    /*
+ * We use != instead of > because the point is to reflect what's actually on
+     * the file system, not to worry about freshness per se.
+     */
+    return (currentModificationSeconds != modificationSeconds);
+  }

   @Override
   public InputStream openContents() {
@@ -70,4 +87,9 @@
   public boolean wasRerooted() {
     return false;
   }
-}
+
+  private long lastModifiedSeconds(File file) {
+    return file.lastModified() / 1000;
+  }
+
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java Tue Aug 3 08:08:39 2010
@@ -41,6 +41,8 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.Map.Entry;
+import java.util.jar.JarFile;
+import java.util.zip.ZipFile;

 /**
  * The normal implementation of {...@link ResourceOracle}.
@@ -101,6 +103,11 @@
     public String getPath() {
       return path;
     }
+
+    @Override
+    public boolean isStale() {
+      return resource.isStale();
+    }

     @Override
     public InputStream openContents() {
@@ -163,16 +170,20 @@
       if (f.isDirectory()) {
         return new DirectoryClassPathEntry(f);
       } else if (f.isFile() && lowerCaseFileName.endsWith(".jar")) {
-        return new ZipFileClassPathEntry(f);
+        return new ZipFileClassPathEntry(new JarFile(f));
       } else if (f.isFile() && lowerCaseFileName.endsWith(".zip")) {
-        return new ZipFileClassPathEntry(f);
+        return new ZipFileClassPathEntry(new ZipFile(f));
       } else {
         // It's a file ending in neither jar nor zip, speculatively try to
         // open as jar/zip anyway.
         try {
-          return new ZipFileClassPathEntry(f);
+          return new ZipFileClassPathEntry(new JarFile(f));
         } catch (Exception ignored) {
         }
+        try {
+          return new ZipFileClassPathEntry(new ZipFile(f));
+        } catch (Exception ignored) {
+        }
         logger.log(TreeLogger.TRACE, "Unexpected entry in classpath; " + f
             + " is neither a directory nor an archive (.jar or .zip)");
         return null;
@@ -247,6 +258,8 @@

   private Set<Resource> exposedResources = Collections.emptySet();

+  private Map<String, ResourceData> internalMap = Collections.emptyMap();
+
   private PathPrefixSet pathPrefixSet = new PathPrefixSet();

   /**
@@ -282,6 +295,7 @@
     exposedPathNames = Collections.emptySet();
     exposedResourceMap = Collections.emptyMap();
     exposedResources = Collections.emptySet();
+    internalMap = Collections.emptyMap();
   }

   public Set<String> getPathNames() {
@@ -348,10 +362,40 @@
         }
       }
     }
+
+    /*
+ * Update the newInternalMap to preserve identity for any resources that
+     * have not changed; also record whether or not there are ANY changes.
+     *
+ * There's definitely a change if the sizes don't match; even if the sizes + * do match, every new resource must match an old resource for there to be
+     * no changes.
+     */
+    boolean didChange = internalMap.size() != newInternalMap.size();
+ for (Map.Entry<String, ResourceData> entry : newInternalMap.entrySet()) {
+      String resourcePath = entry.getKey();
+      ResourceData newData = entry.getValue();
+      ResourceData oldData = internalMap.get(resourcePath);
+      if (shouldUseNewResource(logger, oldData, newData)) {
+        didChange = true;
+      } else {
+        if (oldData.resource != newData.resource) {
+          newInternalMap.put(resourcePath, oldData);
+        }
+      }
+    }
+
+    if (!didChange) {
+      // Nothing to do, keep the same identities.
+      SpeedTracerLogger.end(CompilerEventType.RESOURCE_ORACLE);
+      return;
+    }
+
+    internalMap = newInternalMap;

     Map<String, Resource> externalMap = new HashMap<String, Resource>();
     Set<Resource> externalSet = new HashSet<Resource>();
-    for (Entry<String, ResourceData> entry : newInternalMap.entrySet()) {
+    for (Entry<String, ResourceData> entry : internalMap.entrySet()) {
       String path = entry.getKey();
       ResourceData data = entry.getValue();
       externalMap.put(path, data.resource);
@@ -373,4 +417,31 @@
   List<ClassPathEntry> getClassPath() {
     return classPath;
   }
-}
+
+ private boolean shouldUseNewResource(TreeLogger logger, ResourceData oldData,
+      ResourceData newData) {
+    AbstractResource newResource = newData.resource;
+    String resourcePath = newResource.getPath();
+    if (oldData != null) {
+      // Test 1: Is the resource found in a different location than before?
+      AbstractResource oldResource = oldData.resource;
+ if (oldResource.getClassPathEntry() == newResource.getClassPathEntry()) {
+        // Test 2: Has the resource changed since we last found it?
+        if (!oldResource.isStale()) {
+          // The resource has not changed.
+          return false;
+        } else {
+          Messages.RESOURCE_BECAME_INVALID_BECAUSE_IT_IS_STALE.log(logger,
+              resourcePath, null);
+        }
+      } else {
+        Messages.RESOURCE_BECAME_INVALID_BECAUSE_IT_MOVED.log(logger,
+            resourcePath, null);
+      }
+    } else {
+      Messages.NEW_RESOURCE_FOUND.log(logger, resourcePath, null);
+    }
+
+    return true;
+  }
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java Tue Aug 3 08:08:39 2010
@@ -23,12 +23,10 @@
 import com.google.gwt.dev.util.msg.Message1String;

 import java.io.File;
-import java.io.IOException;
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.Set;
 import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
 import java.util.zip.ZipFile;

 /**
@@ -57,8 +55,8 @@
   }

   private static class ZipFileSnapshot {
-    private final Map<AbstractResource, PathPrefix> cachedAnswers;
     private final int prefixSetSize;
+    private final Map<AbstractResource, PathPrefix> cachedAnswers;

     ZipFileSnapshot(int prefixSetSize,
         Map<AbstractResource, PathPrefix> cachedAnswers) {
@@ -74,14 +72,11 @@
    */
private final Map<PathPrefixSet, ZipFileSnapshot> cachedSnapshots = new IdentityHashMap<PathPrefixSet, ZipFileSnapshot>();

-  private final String location;
-
+  private String cachedLocation;
   private final ZipFile zipFile;

- public ZipFileClassPathEntry(File zipFile) throws ZipException, IOException {
-    assert zipFile.isAbsolute();
-    this.zipFile = new ZipFile(zipFile);
-    this.location = zipFile.toURI().toString();
+  public ZipFileClassPathEntry(ZipFile zipFile) {
+    this.zipFile = zipFile;
   }

   /**
@@ -106,7 +101,10 @@

   @Override
   public String getLocation() {
-    return location;
+    if (cachedLocation == null) {
+      cachedLocation = new File(zipFile.getName()).toURI().toString();
+    }
+    return cachedLocation;
   }

   public ZipFile getZipFile() {
@@ -129,7 +127,7 @@
         continue;
       }
       ZipFileResource zipResource = new ZipFileResource(this,
-          zipEntry.getName(), zipEntry.getTime());
+          zipEntry.getName());
       results.add(zipResource);
       Messages.READ_ZIP_ENTRY.log(logger, zipEntry.getName(), null);
     }
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java Tue Aug 3 08:08:39 2010
@@ -27,13 +27,10 @@

   private final ZipFileClassPathEntry classPathEntry;
   private final String path;
-  private long lastModified;
-
-  public ZipFileResource(ZipFileClassPathEntry classPathEntry, String path,
-      long lastModified) {
+
+ public ZipFileResource(ZipFileClassPathEntry classPathEntry, String path) {
     this.classPathEntry = classPathEntry;
     this.path = path;
-    this.lastModified = lastModified;
   }

   @Override
@@ -43,7 +40,7 @@

   @Override
   public long getLastModified() {
-    return lastModified;
+    return getEntry().getTime();
   }

   @Override
@@ -60,10 +57,19 @@
     return path;
   }

+  /**
+ * Since we don't dynamically reload zips during a run, zip-based resources
+   * cannot become stale.
+   */
+  @Override
+  public boolean isStale() {
+    return false;
+  }
+
   @Override
   public InputStream openContents() {
     try {
- return classPathEntry.getZipFile().getInputStream(new ZipEntry(path));
+      return classPathEntry.getZipFile().getInputStream(getEntry());
     } catch (IOException e) {
       // The spec for this method says it can return null.
       return null;
@@ -74,4 +80,8 @@
   public boolean wasRerooted() {
     return false;
   }
-}
+
+  private ZipEntry getEntry() {
+    return classPathEntry.getZipFile().getEntry(path);
+  }
+}
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java Tue Aug 3 08:08:39 2010
@@ -194,7 +194,8 @@
   protected ClassPathEntry getClassPathEntry1AsJar() throws IOException,
       URISyntaxException {
File file = findJarFile("com/google/gwt/dev/resource/impl/testdata/cpe1.jar");
-    return new ExcludeSvnClassPathEntry(new ZipFileClassPathEntry(file));
+ return new ExcludeSvnClassPathEntry(new ZipFileClassPathEntry(new JarFile(
+        file)));
   }

   protected ClassPathEntry getClassPathEntry1AsMock() {
@@ -210,7 +211,8 @@
protected ClassPathEntry getClassPathEntry2AsJar() throws URISyntaxException,
       IOException {
File file = findJarFile("com/google/gwt/dev/resource/impl/testdata/cpe2.jar");
-    return new ExcludeSvnClassPathEntry(new ZipFileClassPathEntry(file));
+ return new ExcludeSvnClassPathEntry(new ZipFileClassPathEntry(new JarFile(
+        file)));
   }

   protected ClassPathEntry getClassPathEntry2AsMock() {
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java Tue Aug 3 08:08:39 2010
@@ -24,7 +24,7 @@

 public class FileResourceTest extends TestCase {

-  public void testBasic() {
+  public void testDeletion() {
     File f = null;
     try {
f = File.createTempFile("com.google.gwt.dev.javac.impl.FileResourceTest",
@@ -45,9 +45,22 @@
      * simple filename.
      */
     assertEquals(f.getName(), r.getPath());
+
+    // Shouldn't be stale yet.
+    assertFalse(r.isStale());
+
+    /*
+ * Touch the file at more than one second to ensure there's a noticeable
+     * difference on every platform.
+     */
+    // Ignore failure of setLastModified
+    f.setLastModified(f.lastModified() + 1500);
+
+    // Should be stale now.
+    assertTrue(r.isStale());
   }

-  public void testDeletion() {
+  public void testModification() {
     File f = null;
     try {
f = File.createTempFile("com.google.gwt.dev.javac.impl.FileResourceTest",
@@ -69,9 +82,15 @@
      */
     assertEquals(f.getName(), r.getPath());

+    // Shouldn't be stale yet.
+    assertFalse(r.isStale());
+
     // Delete the file.
     f.delete();

+    // Should be stale now.
+    assertTrue(r.isStale());
+
     // Get can't contents anymore, either.
     assertNull(r.openContents());
   }
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java Tue Aug 3 08:08:39 2010
@@ -48,6 +48,11 @@
   public String getPath() {
     return path;
   }
+
+  @Override
+  public boolean isStale() {
+    return isStale;
+  }

   @Override
   public InputStream openContents() {
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java Tue Aug 3 08:08:39 2010
@@ -20,8 +20,6 @@

 import java.util.Map;

-import static com.google.gwt.dev.resource.impl.ResourceOracleImplTest.assertResourcesEqual;
-
 /**
  * Tests {...@link ResourceOracleImpl} using the real class path.
  *
@@ -58,7 +56,6 @@
       });

   private final TreeLogger logger = createTestTreeLogger();
-
   private final ResourceOracleImpl resourceOracle = new ResourceOracleImpl(
       logger);

@@ -83,12 +80,12 @@

     // Plain refresh should have no effect.
     resourceOracle.refresh(logger);
-    assertResourcesEqual(resourceMap, resourceOracle.getResourceMap());
+    assertSame(resourceMap, resourceOracle.getResourceMap());

     // Setting same path entries should have no effect.
     resourceOracle.setPathPrefixes(pathPrefixSet);
     resourceOracle.refresh(logger);
-    assertResourcesEqual(resourceMap, resourceOracle.getResourceMap());
+    assertSame(resourceMap, resourceOracle.getResourceMap());

     // Setting identical path entries should have no effect.
     pathPrefixSet = new PathPrefixSet();
@@ -96,16 +93,18 @@
     pathPrefixSet.add(THIS_CLASS_PREFIX);
     resourceOracle.setPathPrefixes(pathPrefixSet);
     resourceOracle.refresh(logger);
-    assertResourcesEqual(resourceMap, resourceOracle.getResourceMap());
+    assertSame(resourceMap, resourceOracle.getResourceMap());

     // Setting identical result should have no effect.
     pathPrefixSet.add(JUNIT_PREFIX_DUP);
     resourceOracle.refresh(logger);
-    assertResourcesEqual(resourceMap, resourceOracle.getResourceMap());
+    assertSame(resourceMap, resourceOracle.getResourceMap());

     // Actually change the working set.
     pathPrefixSet.add(THIS_CLASS_PREFIX_PLUS);
     resourceOracle.refresh(logger);
-    assertEquals(3, resourceOracle.getResourceMap().size());
+    Map<String, Resource> newResourceMap = resourceOracle.getResourceMap();
+    assertNotSame(resourceMap, newResourceMap);
+    assertEquals(3, newResourceMap.size());
   }
 }
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java Sat Jul 31 10:16:08 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java Tue Aug 3 08:08:39 2010
@@ -20,7 +20,6 @@
 import com.google.gwt.util.tools.Utility;

 import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -30,8 +29,6 @@
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -120,9 +117,9 @@
     }

     public void assertSameCollections(ResourceOracleSnapshot other) {
-      assertResourcesEqual(resourceMap, other.resourceMap);
-      assertResourcesEqual(resources, other.resources);
-      assertEquals(pathNames, other.pathNames);
+      assertSame(resourceMap, other.resourceMap);
+      assertSame(resources, other.resources);
+      assertSame(pathNames, other.pathNames);
     }

     public AbstractResource findResourceWithPath(String path) {
@@ -134,30 +131,12 @@
       return null;
     }
   }
-
-  public static void assertResourcesEqual(Collection<Resource> expected,
-      Collection<Resource> actual) {
-    Set<String> expectedLocs = new HashSet<String>();
-    for (Resource resource : expected) {
-      expectedLocs.add(resource.getLocation());
-    }
-    Set<String> actualLocs = new HashSet<String>();
-    for (Resource resource : actual) {
-      actualLocs.add(resource.getLocation());
-    }
-    assertEquals(expectedLocs, actualLocs);
-  }
-
-  public static void assertResourcesEqual(Map<String, Resource> expected,
-      Map<String, Resource> actual) {
-    assertResourcesEqual(expected.values(), actual.values());
-  }

   public void testCachingOfJarResources() throws IOException,
       URISyntaxException {
     TreeLogger logger = createTestTreeLogger();
- File jarFile = findJarFile("com/google/gwt/dev/resource/impl/testdata/cpe1.jar");
-    ClassPathEntry cpe1jar = new ZipFileClassPathEntry(jarFile);
+    ClassPathEntry cpe1jar = new ZipFileClassPathEntry(new JarFile(
+ findJarFile("com/google/gwt/dev/resource/impl/testdata/cpe1.jar")));

     // test basic caching
     PathPrefixSet pps1 = new PathPrefixSet();
@@ -197,8 +176,8 @@
     ClassPathEntry cpe1jar = getClassPathEntry1AsJar();
     ClassPathEntry cpe2jar = getClassPathEntry2AsJar();

-    ClassPathEntry[] cp12 = new ClassPathEntry[]{cpe1jar, cpe2jar};
-    ClassPathEntry[] cp21 = new ClassPathEntry[]{cpe2jar, cpe1jar};
+    ClassPathEntry[] cp12 = new ClassPathEntry[] {cpe1jar, cpe2jar};
+    ClassPathEntry[] cp21 = new ClassPathEntry[] {cpe2jar, cpe1jar};
     String resKeyNormal = "org/example/bar/client/BarClient2.txt";
     String resKeyReroot = "/BarClient2.txt";
     PathPrefix pathPrefixNormal = new PathPrefix("org/example/bar/client",
@@ -235,8 +214,8 @@
     ClassPathEntry cpe1jar = getClassPathEntry1AsJar();
     ClassPathEntry cpe2jar = getClassPathEntry2AsJar();

-    ClassPathEntry[] cp12 = new ClassPathEntry[]{cpe1jar, cpe2jar};
-    ClassPathEntry[] cp21 = new ClassPathEntry[]{cpe2jar, cpe1jar};
+    ClassPathEntry[] cp12 = new ClassPathEntry[] {cpe1jar, cpe2jar};
+    ClassPathEntry[] cp21 = new ClassPathEntry[] {cpe2jar, cpe1jar};

     String keyReroot = "/BarClient1.txt";

@@ -285,7 +264,7 @@
     TreeLogger logger = createTestTreeLogger();
URL cpe1 = findJarUrl("com/google/gwt/dev/resource/impl/testdata/cpe1.jar"); URL cpe2 = findJarUrl("com/google/gwt/dev/resource/impl/testdata/cpe2.jar");
-    URLClassLoader classLoader = new URLClassLoader(new URL[]{
+    URLClassLoader classLoader = new URLClassLoader(new URL[] {
         cpe1, cpe2, cpe2, cpe1, cpe2,}, null);
ResourceOracleImpl oracle = new ResourceOracleImpl(logger, classLoader);
     List<ClassPathEntry> classPath = oracle.getClassPath();
@@ -382,7 +361,7 @@
     PathPrefix pp1 = new PathPrefix("org/example/bar/client", null, false);
     PathPrefix pp2 = new PathPrefix("org/example/bar", null, false);
testResourceInCPE(logger, "org/example/bar/client/BarClient2.txt", cpe1,
-        new ClassPathEntry[]{cpe1, cpe2}, pp1, pp2);
+        new ClassPathEntry[] {cpe1, cpe2}, pp1, pp2);
   }

   /**
@@ -403,15 +382,15 @@

// Ensure the translatable overrides the basic despite swapping CPE order.
     testResourceInCPE(logger, "java/lang/Object.java", cpe2,
-        new ClassPathEntry[]{cpe1, cpe2}, pp1, pp2);
+        new ClassPathEntry[] {cpe1, cpe2}, pp1, pp2);
     testResourceInCPE(logger, "java/lang/Object.java", cpe2,
-        new ClassPathEntry[]{cpe2, cpe1}, pp1, pp2);
+        new ClassPathEntry[] {cpe2, cpe1}, pp1, pp2);

// Ensure the translatable overrides the basic despite swapping PPS order.
     testResourceInCPE(logger, "java/lang/Object.java", cpe2,
-        new ClassPathEntry[]{cpe1, cpe2}, pp2, pp1);
+        new ClassPathEntry[] {cpe1, cpe2}, pp2, pp1);
     testResourceInCPE(logger, "java/lang/Object.java", cpe2,
-        new ClassPathEntry[]{cpe2, cpe1}, pp2, pp1);
+        new ClassPathEntry[] {cpe2, cpe1}, pp2, pp1);
   }

   /**

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to