You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2021/01/18 14:12:16 UTC
[myfaces] branch 3.0.x updated: MYFACES-4375
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch 3.0.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/3.0.x by this push:
new 4ff3b4e MYFACES-4375
4ff3b4e is described below
commit 4ff3b4e49b05b6f8afc5ad6f8cf7de7be87360d7
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Jan 18 15:11:48 2021 +0100
MYFACES-4375
---
.../facelets/impl/CacheELFaceletCacheImpl.java | 5 +-
.../view/facelets/impl/DefaultFaceletFactory.java | 20 +-----
.../view/facelets/impl/FaceletCacheImpl.java | 26 +-------
.../shared/resource/ResourceLoaderUtils.java | 72 +++++++++-------------
4 files changed, 32 insertions(+), 91 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java
index 3b89723..f1d86b4 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java
@@ -20,7 +20,6 @@ package org.apache.myfaces.view.facelets.impl;
import java.io.IOException;
import java.net.URL;
-import java.net.URLConnection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
@@ -240,11 +239,9 @@ class CacheELFaceletCacheImpl extends AbstractFaceletCache<DefaultFacelet>
if (System.currentTimeMillis() > target)
{
// Should check for file modification
-
try
{
- URLConnection conn = facelet.getSource().openConnection();
- long lastModified = ResourceLoaderUtils.getResourceLastModified(conn);
+ long lastModified = ResourceLoaderUtils.getResourceLastModified(facelet.getSource());
return lastModified == 0 || lastModified > target;
}
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
index 88183fd..6480f2e 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
@@ -21,7 +21,6 @@ package org.apache.myfaces.view.facelets.impl;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
-import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
@@ -332,12 +331,9 @@ public final class DefaultFaceletFactory extends FaceletFactory
if (System.currentTimeMillis() > target)
{
// Should check for file modification
-
- URLConnection conn = null;
try
{
- conn = facelet.getSource().openConnection();
- long lastModified = ResourceLoaderUtils.getResourceLastModified(conn);
+ long lastModified = ResourceLoaderUtils.getResourceLastModified(facelet.getSource());
return lastModified == 0 || lastModified > target;
}
@@ -345,20 +341,6 @@ public final class DefaultFaceletFactory extends FaceletFactory
{
throw new FaceletException("Error Checking Last Modified for " + facelet.getAlias(), e);
}
- finally
- {
- if (conn != null)
- {
- try
- {
- conn.getInputStream().close();
- }
- catch (Exception e)
- {
- // Ignored
- }
- }
- }
}
return false;
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java
index b99a3ab..a676347 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java
@@ -19,9 +19,7 @@
package org.apache.myfaces.view.facelets.impl;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URL;
-import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
@@ -154,12 +152,9 @@ class FaceletCacheImpl extends FaceletCache<DefaultFacelet>
if (System.currentTimeMillis() > target)
{
// Should check for file modification
-
- URLConnection conn = null;
try
{
- conn = facelet.getSource().openConnection();
- long lastModified = ResourceLoaderUtils.getResourceLastModified(conn);
+ long lastModified = ResourceLoaderUtils.getResourceLastModified(facelet.getSource());
return lastModified == 0 || lastModified > target;
}
@@ -167,25 +162,6 @@ class FaceletCacheImpl extends FaceletCache<DefaultFacelet>
{
throw new FaceletException("Error Checking Last Modified for " + facelet.getAlias(), e);
}
- finally
- {
- // finally close input stream when finished, if fails just continue.
- if (conn != null)
- {
- try
- {
- InputStream is = conn.getInputStream();
- if (is != null)
- {
- is.close();
- }
- }
- catch (IOException e)
- {
- // Ignore
- }
- }
- }
}
return false;
diff --git a/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java b/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java
index bfdc6d3..da3e099 100644
--- a/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java
+++ b/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java
@@ -18,8 +18,8 @@
*/
package org.apache.myfaces.shared.resource;
-import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
@@ -76,64 +76,50 @@ public class ResourceLoaderUtils
return Long.valueOf(date.getTime());
}
- //Taken from trinidad URLUtils
public static 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());
- }
- }
+ long lastModified;
- //Taken from trinidad URLUtils
- public static long getResourceLastModified(URLConnection connection) throws IOException
- {
- long modified;
- if (connection instanceof JarURLConnection)
+ InputStream is = null;
+ try
{
- // 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
+ URLConnection connection = url.openConnection();
+ 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.
+ JarURLConnection jarUrlConnection = (JarURLConnection) connection;
+ URL jarFileUrl = jarUrlConnection.getJarFileURL();
+ URLConnection jarFileConnection = jarFileUrl.openConnection();
+ is = jarFileConnection.getInputStream();
+ lastModified = jarFileConnection.getLastModified();
+ }
+ else
{
- modified = jarFileConnection.getLastModified();
+ is = connection.getInputStream();
+ lastModified = connection.getLastModified();
}
- finally
+ }
+ finally
+ {
+ if (is != null)
{
try
{
- jarFileConnection.getInputStream().close();
+ is.close();
}
- catch (Exception exception)
+ catch (Exception e)
{
// Ignored
}
}
}
- else
- {
- modified = connection.getLastModified();
- }
- return modified;
+ return lastModified;
}
public static int getDepth(String path)