You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/05/27 00:58:44 UTC
svn commit: r778919 -
/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Author: lu4242
Date: Tue May 26 22:58:44 2009
New Revision: 778919
URL: http://svn.apache.org/viewvc?rev=778919&view=rev
Log:
Corrected getResourceLastModified to prevent lock on files (see TRINIDAD-73 for details)
Modified:
myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Modified: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=778919&r1=778918&r2=778919&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java (original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java Tue May 26 22:58:44 2009
@@ -26,6 +26,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
@@ -186,16 +187,80 @@
private long getResourceLastModified(String resource)
{
- try {
+ try
+ {
URL url = _externalContext.getResource(resource);
- if (url != null) {
- return url.openConnection().getLastModified();
+ if (url != null)
+ {
+ return getResourceLastModified(url);
}
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
log.error("Could not read resource " + resource, e);
}
return 0;
}
+
+ //Taken from trinidad URLUtils
+ private long getResourceLastModified(URL url) throws IOException
+ {
+ if ("file".equals(url.getProtocol()))
+ {
+ String externalForm = url.toExternalForm();
+ // Remove the "file:"
+ File file = new File(externalForm.substring(5));
+
+ return file.lastModified();
+ }
+ else
+ {
+ return getResourceLastModified(url.openConnection());
+ }
+ }
+
+ //Taken from trinidad URLUtils
+ private long getResourceLastModified(URLConnection connection) throws IOException
+ {
+ long modified;
+ if (connection instanceof JarURLConnection)
+ {
+ // The following hack is required to work-around a JDK bug.
+ // getLastModified() on a JAR entry URL delegates to the actual JAR file
+ // rather than the JAR entry.
+ // This opens internally, and does not close, an input stream to the JAR
+ // file.
+ // In turn, you cannot close it by yourself, because it's internal.
+ // The work-around is to get the modification date of the JAR file
+ // manually,
+ // and then close that connection again.
+
+ URL jarFileUrl = ((JarURLConnection) connection).getJarFileURL();
+ URLConnection jarFileConnection = jarFileUrl.openConnection();
+
+ try
+ {
+ modified = jarFileConnection.getLastModified();
+ }
+ finally
+ {
+ try
+ {
+ jarFileConnection.getInputStream().close();
+ }
+ catch (Exception exception)
+ {
+ // Ignored
+ }
+ }
+ }
+ else
+ {
+ modified = connection.getLastModified();
+ }
+
+ return modified;
+ }
private long getLastModifiedTime()
{