@Deprecate Resource.getURL() which isn't generally safe, and removes all overrides.
Review by: bobv
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6699 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/resource/Resource.java b/dev/core/src/com/google/gwt/dev/resource/Resource.java
index 0a49ff6..94bfd51 100644
--- a/dev/core/src/com/google/gwt/dev/resource/Resource.java
+++ b/dev/core/src/com/google/gwt/dev/resource/Resource.java
@@ -16,6 +16,7 @@
package com.google.gwt.dev.resource;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
/**
@@ -37,8 +38,9 @@
public abstract long getLastModified();
/**
- * Returns the user-relevant location of the resource. No programmatic
- * assumptions should be made about the return value.
+ * Returns the URL-like location of the resource. The returned value should
+ * generally reflect a unique resource in the system. The returned value will
+ * only be a valid URL if the underlying object is accessible via a URL.
*/
public abstract String getLocation();
@@ -48,13 +50,19 @@
public abstract String getPath();
/**
- * Returns a URL for this resource; this URL will only be valid for resources
- * based off the file system.
+ * Returns a URL for this resource if the resource happens to be based off the
+ * file system, otherwise returns <code>null</code>.
*
- * TODO: get rid of this method?
+ * @deprecated with no replacement
*/
- public abstract URL getURL();
-
+ @Deprecated
+ public final URL getURL() {
+ try {
+ return new URL(getLocation());
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
/**
* Overridden to finalize; always returns identity hash code.
*/
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 a3183cc..291ecd5 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
@@ -19,8 +19,6 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
/**
* Represents a resource contained in directory on a file system.
@@ -62,15 +60,6 @@
}
@Override
- public URL getURL() {
- try {
- return new URL(getLocation());
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
public boolean isStale() {
if (!file.exists()) {
// File was deleted. Always stale.
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 9a5696e..8982cf3 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
@@ -105,11 +105,6 @@
}
@Override
- public URL getURL() {
- return resource.getURL();
- }
-
- @Override
public boolean isStale() {
return resource.isStale();
}
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 bfd6432..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
@@ -17,8 +17,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
@@ -59,15 +57,6 @@
return path;
}
- @Override
- public URL getURL() {
- try {
- return new URL(getLocation());
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
/**
* Since we don't dynamically reload zips during a run, zip-based resources
* cannot become stale.
diff --git a/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java b/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java
index 162ab12..269fdbd 100644
--- a/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java
+++ b/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java
@@ -404,6 +404,7 @@
* @param moduleName the name of the module
* @throws IOException
*/
+ @SuppressWarnings("deprecation")
private void doGetPublicFile(HttpServletRequest request,
HttpServletResponse response, TreeLogger logger, String partialPath,
String moduleName) throws IOException {
diff --git a/dev/core/src/com/google/gwt/dev/shell/HostedModeServletContextProxy.java b/dev/core/src/com/google/gwt/dev/shell/HostedModeServletContextProxy.java
index b68f90a..d6b321e 100644
--- a/dev/core/src/com/google/gwt/dev/shell/HostedModeServletContextProxy.java
+++ b/dev/core/src/com/google/gwt/dev/shell/HostedModeServletContextProxy.java
@@ -157,6 +157,7 @@
* @throws MalformedURLException
* @see javax.servlet.ServletContext#getResource(java.lang.String)
*/
+ @SuppressWarnings("deprecation")
public URL getResource(String path) throws MalformedURLException {
ModuleDef moduleDef = moduleDefRef.get();
assert (moduleDef != null) : "GWTShellServlet should have guaranteed that a"
diff --git a/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java b/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java
index 5a86612..5d72cf1 100644
--- a/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java
+++ b/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java
@@ -22,7 +22,7 @@
import com.google.gwt.dev.resource.impl.PathPrefixSet;
import com.google.gwt.dev.resource.impl.ResourceOracleImpl;
import com.google.gwt.dev.shell.WorkDirs;
-import com.google.gwt.util.tools.Utility;
+import com.google.gwt.dev.util.Util;
import org.apache.catalina.Connector;
import org.apache.catalina.ContainerEvent;
@@ -39,7 +39,6 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.ServerSocket;
@@ -275,70 +274,44 @@
* Assumes that the leaf is a file (not a directory).
*/
private void copyFileNoOverwrite(TreeLogger logger, String srcResName,
- Resource resource, File catBase) {
+ Resource srcRes, File catBase) {
File dest = new File(catBase, srcResName);
- InputStream is = null;
- FileOutputStream os = null;
try {
- URL srcRes = resource.getURL();
- if (srcRes == null) {
- logger.log(TreeLogger.TRACE, "Cannot find: " + srcResName, null);
- return;
- }
-
// Only copy if src is newer than desc.
- //
- long srcLastModified = srcRes.openConnection().getLastModified();
+ long srcLastModified = srcRes.getLastModified();
long dstLastModified = dest.lastModified();
if (srcLastModified < dstLastModified) {
// Don't copy over it.
- //
logger.log(TreeLogger.SPAM, "Source is older than existing: "
+ dest.getAbsolutePath(), null);
return;
} else if (srcLastModified == dstLastModified) {
// Exact same time; quietly don't overwrite.
- //
return;
} else if (dest.exists()) {
// Warn about the overwrite
logger.log(TreeLogger.WARN, "Overwriting existing file '"
- + dest.getAbsolutePath() + "' with '" + resource.getLocation()
+ + dest.getAbsolutePath() + "' with '" + srcRes.getLocation()
+ "', which has a newer timestamp");
}
// Make dest directories as required.
- //
File destParent = dest.getParentFile();
if (destParent != null) {
// No need to check mkdirs result because IOException later anyway.
destParent.mkdirs();
}
- // Open in and out streams.
- //
- is = srcRes.openStream();
- os = new FileOutputStream(dest);
-
- // Copy the bytes over.
- //
- Utility.streamOut(is, os, 1024);
-
- // Try to close and change the last modified time.
- //
- Utility.close(os);
+ Util.copy(srcRes.openContents(), new FileOutputStream(dest));
dest.setLastModified(srcLastModified);
logger.log(TreeLogger.TRACE, "Wrote: " + dest.getAbsolutePath(), null);
} catch (IOException e) {
logger.log(TreeLogger.WARN, "Failed to write: " + dest.getAbsolutePath(),
e);
- } finally {
- Utility.close(is);
- Utility.close(os);
- }
+ }
}
/**
diff --git a/dev/core/test/com/google/gwt/dev/javac/impl/MockResource.java b/dev/core/test/com/google/gwt/dev/javac/impl/MockResource.java
index bcce637..9c99761 100644
--- a/dev/core/test/com/google/gwt/dev/javac/impl/MockResource.java
+++ b/dev/core/test/com/google/gwt/dev/javac/impl/MockResource.java
@@ -48,11 +48,6 @@
}
@Override
- public URL getURL() {
- return null;
- }
-
- @Override
public InputStream openContents() {
return new ByteArrayInputStream(Util.getBytes(getContent().toString()));
}
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 afca6d4..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
@@ -18,7 +18,6 @@
import junit.framework.Assert;
import java.io.InputStream;
-import java.net.URL;
public final class MockAbstractResource extends AbstractResource {
private boolean isStale;
@@ -51,11 +50,6 @@
}
@Override
- public URL getURL() {
- return null;
- }
-
- @Override
public boolean isStale() {
return isStale;
}
diff --git a/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java b/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
index 5ec9238..2581868 100644
--- a/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
+++ b/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
@@ -93,11 +93,6 @@
}
@Override
- public URL getURL() {
- return null;
- }
-
- @Override
public InputStream openContents() {
return new ByteArrayInputStream(Util.getBytes("w00t!"));
}
diff --git a/user/src/com/google/gwt/resources/ext/ResourceGeneratorUtil.java b/user/src/com/google/gwt/resources/ext/ResourceGeneratorUtil.java
index c0ea076..3f65e14 100644
--- a/user/src/com/google/gwt/resources/ext/ResourceGeneratorUtil.java
+++ b/user/src/com/google/gwt/resources/ext/ResourceGeneratorUtil.java
@@ -92,9 +92,10 @@
resourceMap = oracle.getResourceMap();
}
+ @SuppressWarnings("deprecation")
public URL locate(String resourceName) {
Resource r = resourceMap.get(resourceName);
- return r == null ? null : r.getURL();
+ return (r == null) ? null : r.getURL();
}
}