Revision: 8453
Author: con...@google.com
Date: Sat Jul 31 10:16:08 2010
Log: Reintroduces changes from r8440

Review at http://gwt-code-reviews.appspot.com/707804

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

Deleted:
 /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

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/cfg/PublicOracle.java Thu Jul 29 12:27:21 2010
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java Sat Jul 31 10:16:08 2010
@@ -28,6 +28,7 @@
 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;
@@ -51,8 +52,13 @@
* Represents a module specification. In principle, this could be built without
  * XML for unit tests.
  */
-...@suppresswarnings("deprecation")
-public class ModuleDef implements PublicOracle {
+public class ModuleDef {
+
+ private static final ResourceFilter NON_JAVA_RESOURCES = new ResourceFilter() {
+    public boolean allows(String path) {
+      return !path.endsWith(".java") && !path.endsWith(".class");
+    }
+  };

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) {
@@ -115,6 +121,7 @@
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) {
@@ -327,8 +334,8 @@
       PathPrefixSet pathPrefixes = lazySourceOracle.getPathPrefixes();
       PathPrefixSet newPathPrefixes = new PathPrefixSet();
       for (PathPrefix pathPrefix : pathPrefixes.values()) {
-        newPathPrefixes.add(new PathPrefix(pathPrefix.getPrefix(), null,
-            pathPrefix.shouldReroot()));
+        newPathPrefixes.add(new PathPrefix(pathPrefix.getPrefix(),
+            NON_JAVA_RESOURCES, pathPrefix.shouldReroot()));
       }
       lazyResourcesOracle.setPathPrefixes(newPathPrefixes);
       lazyResourcesOracle.refresh(TreeLogger.NULL);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java Sat Jul 31 10:16:08 2010
@@ -27,37 +27,15 @@
  * <code>com/google/gwt/blah.txt</code>.
  *
  * <p>
- * The identity of the returned sets and maps will change exactly when the
- * underlying module is refreshed.
+ * The identity of the returned sets and maps will change 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 ResoruceOracle is
+   * collections will be empty after this call until this ResourceOracle is
    * refreshed.
    */
   void clear();
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java Sat Jul 31 10:16:08 2010
@@ -27,7 +27,5 @@
    * within this package.
    */
   public abstract ClassPathEntry getClassPathEntry();
-
-  public abstract boolean isStale();
 }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java Sat Jul 31 10:16:08 2010
@@ -23,7 +23,7 @@
 import java.util.Map;

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

@@ -41,10 +41,20 @@
         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
@@ -57,7 +67,7 @@

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

   /**
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java Sat Jul 31 10:16:08 2010
@@ -28,7 +28,6 @@
   private final String abstractPathName;
   private final DirectoryClassPathEntry classPathEntry;
   private final File file;
-  private final long modificationSeconds;

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

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

   @Override
   public String getLocation() {
-    return file.getAbsoluteFile().toURI().toString();
+    return file.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() {
@@ -87,9 +70,4 @@
   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 Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java Sat Jul 31 10:16:08 2010
@@ -41,8 +41,6 @@
 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}.
@@ -103,11 +101,6 @@
     public String getPath() {
       return path;
     }
-
-    @Override
-    public boolean isStale() {
-      return resource.isStale();
-    }

     @Override
     public InputStream openContents() {
@@ -170,20 +163,16 @@
       if (f.isDirectory()) {
         return new DirectoryClassPathEntry(f);
       } else if (f.isFile() && lowerCaseFileName.endsWith(".jar")) {
-        return new ZipFileClassPathEntry(new JarFile(f));
+        return new ZipFileClassPathEntry(f);
       } else if (f.isFile() && lowerCaseFileName.endsWith(".zip")) {
-        return new ZipFileClassPathEntry(new ZipFile(f));
+        return new ZipFileClassPathEntry(f);
       } else {
         // It's a file ending in neither jar nor zip, speculatively try to
         // open as jar/zip anyway.
         try {
-          return new ZipFileClassPathEntry(new JarFile(f));
+          return new ZipFileClassPathEntry(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;
@@ -258,8 +247,6 @@

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

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

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

   public Set<String> getPathNames() {
@@ -362,40 +348,10 @@
         }
       }
     }
-
-    /*
- * 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 : internalMap.entrySet()) {
+    for (Entry<String, ResourceData> entry : newInternalMap.entrySet()) {
       String path = entry.getKey();
       ResourceData data = entry.getValue();
       externalMap.put(path, data.resource);
@@ -417,31 +373,4 @@
   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 Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java Sat Jul 31 10:16:08 2010
@@ -23,10 +23,12 @@
 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;

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

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

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

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

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

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

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

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

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

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

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

   @Override
@@ -57,19 +60,10 @@
     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(getEntry());
+ return classPathEntry.getZipFile().getInputStream(new ZipEntry(path));
     } catch (IOException e) {
       // The spec for this method says it can return null.
       return null;
@@ -80,8 +74,4 @@
   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 Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java Sat Jul 31 10:16:08 2010
@@ -194,8 +194,7 @@
   protected ClassPathEntry getClassPathEntry1AsJar() throws IOException,
       URISyntaxException {
File file = findJarFile("com/google/gwt/dev/resource/impl/testdata/cpe1.jar"); - return new ExcludeSvnClassPathEntry(new ZipFileClassPathEntry(new JarFile(
-        file)));
+    return new ExcludeSvnClassPathEntry(new ZipFileClassPathEntry(file));
   }

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

   protected ClassPathEntry getClassPathEntry2AsMock() {
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java Sat Jul 31 10:16:08 2010
@@ -24,7 +24,7 @@

 public class FileResourceTest extends TestCase {

-  public void testDeletion() {
+  public void testBasic() {
     File f = null;
     try {
f = File.createTempFile("com.google.gwt.dev.javac.impl.FileResourceTest",
@@ -45,22 +45,9 @@
      * 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 testModification() {
+  public void testDeletion() {
     File f = null;
     try {
f = File.createTempFile("com.google.gwt.dev.javac.impl.FileResourceTest",
@@ -82,15 +69,9 @@
      */
     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 Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java Sat Jul 31 10:16:08 2010
@@ -48,11 +48,6 @@
   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 Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java Sat Jul 31 10:16:08 2010
@@ -20,6 +20,8 @@

 import java.util.Map;

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

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

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

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

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

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

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

     // Actually change the working set.
     pathPrefixSet.add(THIS_CLASS_PREFIX_PLUS);
     resourceOracle.refresh(logger);
-    Map<String, Resource> newResourceMap = resourceOracle.getResourceMap();
-    assertNotSame(resourceMap, newResourceMap);
-    assertEquals(3, newResourceMap.size());
+    assertEquals(3, resourceOracle.getResourceMap().size());
   }
 }
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java Thu Jul 29 12:27:21 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java Sat Jul 31 10:16:08 2010
@@ -20,6 +20,7 @@
 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;
@@ -29,6 +30,8 @@
 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;
@@ -117,9 +120,9 @@
     }

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

     public AbstractResource findResourceWithPath(String path) {
@@ -131,12 +134,30 @@
       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();
-    ClassPathEntry cpe1jar = new ZipFileClassPathEntry(new JarFile(
- findJarFile("com/google/gwt/dev/resource/impl/testdata/cpe1.jar"))); + File jarFile = findJarFile("com/google/gwt/dev/resource/impl/testdata/cpe1.jar");
+    ClassPathEntry cpe1jar = new ZipFileClassPathEntry(jarFile);

     // test basic caching
     PathPrefixSet pps1 = new PathPrefixSet();
@@ -176,8 +197,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",
@@ -214,8 +235,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";

@@ -264,7 +285,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();
@@ -361,7 +382,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);
   }

   /**
@@ -382,15 +403,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