Rollback r8440 changes again Review by: rchandia@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8468 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java b/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java index 0f323d3..4add18c 100644 --- a/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java +++ b/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java
@@ -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);
diff --git a/dev/core/src/com/google/gwt/dev/cfg/PublicOracle.java b/dev/core/src/com/google/gwt/dev/cfg/PublicOracle.java new file mode 100644 index 0000000..fe4093a --- /dev/null +++ b/dev/core/src/com/google/gwt/dev/cfg/PublicOracle.java
@@ -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(); +}
diff --git a/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java b/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java index f23ea9c..0fe3eca 100644 --- a/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java +++ b/dev/core/src/com/google/gwt/dev/resource/ResourceOracle.java
@@ -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();
diff --git a/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java b/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java index 84b7155..99c9fd9 100644 --- a/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java +++ b/dev/core/src/com/google/gwt/dev/resource/impl/AbstractResource.java
@@ -27,5 +27,7 @@ * within this package. */ public abstract ClassPathEntry getClassPathEntry(); + + public abstract boolean isStale(); }
diff --git a/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java b/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java index 0359a1b..0eac9e1 100644 --- a/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java +++ b/dev/core/src/com/google/gwt/dev/resource/impl/DirectoryClassPathEntry.java
@@ -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(); } /**
diff --git a/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java b/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java index 317e89e..ea1a669 100644 --- a/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java +++ b/dev/core/src/com/google/gwt/dev/resource/impl/FileResource.java
@@ -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,7 +51,7 @@ @Override public String getLocation() { - return file.toURI().toString(); + return file.getAbsoluteFile().toURI().toString(); } @Override @@ -58,6 +60,21 @@ } @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() { try { return new FileInputStream(file); @@ -70,4 +87,9 @@ public boolean wasRerooted() { return false; } + + private long lastModifiedSeconds(File file) { + return file.lastModified() / 1000; + } + }
diff --git a/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java b/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java index 18bdf48..a38691c 100644 --- a/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java +++ b/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java
@@ -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}. @@ -103,6 +105,11 @@ } @Override + public boolean isStale() { + return resource.isStale(); + } + + @Override public InputStream openContents() { return resource.openContents(); } @@ -163,14 +170,18 @@ 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 @@ -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() { @@ -349,9 +363,39 @@ } } + /* + * 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; + } }
diff --git a/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java b/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java index 5194594..c05b979 100644 --- a/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java +++ b/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java
@@ -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); }
diff --git a/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java b/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java index ec8d796..602bd3a 100644 --- a/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java +++ b/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java
@@ -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); + } }
diff --git a/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java b/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java index 872acb7..2b18497 100644 --- a/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java +++ b/dev/core/test/com/google/gwt/dev/resource/impl/AbstractResourceOrientedTestBase.java
@@ -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() {
diff --git a/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java b/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java index 673c65d..43dfe33 100644 --- a/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java +++ b/dev/core/test/com/google/gwt/dev/resource/impl/FileResourceTest.java
@@ -24,29 +24,6 @@ public class FileResourceTest extends TestCase { - public void testBasic() { - File f = null; - try { - f = File.createTempFile("com.google.gwt.dev.javac.impl.FileResourceTest", - ".tmp"); - f.deleteOnExit(); - Util.writeStringAsFile(f, "contents 1"); - } catch (IOException e) { - fail("Failed to create test file"); - } - - File dir = f.getParentFile(); - DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(dir); - FileResource r = new FileResource(cpe, f.getName(), f); - assertEquals(f.getAbsoluteFile().toURI().toString(), r.getLocation()); - - /* - * In this case, there's no subdirectory, so the path should match the - * simple filename. - */ - assertEquals(f.getName(), r.getPath()); - } - public void testDeletion() { File f = null; try { @@ -69,9 +46,51 @@ */ 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() { + File f = null; + try { + f = File.createTempFile("com.google.gwt.dev.javac.impl.FileResourceTest", + ".tmp"); + f.deleteOnExit(); + Util.writeStringAsFile(f, "contents 1"); + } catch (IOException e) { + fail("Failed to create test file"); + } + + File dir = f.getParentFile(); + DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(dir); + FileResource r = new FileResource(cpe, f.getName(), f); + assertEquals(f.getAbsoluteFile().toURI().toString(), r.getLocation()); + + /* + * In this case, there's no subdirectory, so the path should match the + * simple filename. + */ + 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()); }
diff --git a/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java b/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java index ba2b8b2..775d555 100644 --- a/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java +++ b/dev/core/test/com/google/gwt/dev/resource/impl/MockAbstractResource.java
@@ -50,6 +50,11 @@ } @Override + public boolean isStale() { + return isStale; + } + + @Override public InputStream openContents() { Assert.fail("Not implemented"); return null;
diff --git a/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java b/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java index e322887..2d228bc 100644 --- a/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java +++ b/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplRealClasspathTest.java
@@ -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()); } }
diff --git a/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java b/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java index c67e316..788449a 100644 --- a/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java +++ b/dev/core/test/com/google/gwt/dev/resource/impl/ResourceOracleImplTest.java
@@ -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) { @@ -135,29 +132,11 @@ } } - 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); } /**