diff --git a/core/play/src/main/scala/play/api/controllers/Assets.scala b/core/play/src/main/scala/play/api/controllers/Assets.scala index 6505560df03..60b55ce0ba6 100644 --- a/core/play/src/main/scala/play/api/controllers/Assets.scala +++ b/core/play/src/main/scala/play/api/controllers/Assets.scala @@ -570,10 +570,10 @@ private class AssetInfo( } url.getProtocol match { - case "file" => Some(httpDateFormat.format(Instant.ofEpochMilli(new File(url.toURI).lastModified))) - case "jar" => getLastModified[JarURLConnection](c => c.getJarEntry.getTime) - case "bundle" => getLastModified[URLConnection](c => c.getLastModified) - case _ => None + case "file" => Some(httpDateFormat.format(Instant.ofEpochMilli(new File(url.toURI).lastModified))) + case "jar" => getLastModified[JarURLConnection](c => c.getJarEntry.getTime) + case "bundle" | "bundleresource" => getLastModified[URLConnection](c => c.getLastModified) + case _ => None } } diff --git a/core/play/src/main/scala/play/utils/Resources.scala b/core/play/src/main/scala/play/utils/Resources.scala index 3dba2f86c62..e47e4ad4365 100644 --- a/core/play/src/main/scala/play/utils/Resources.scala +++ b/core/play/src/main/scala/play/utils/Resources.scala @@ -16,10 +16,10 @@ import java.util.zip.ZipFile */ object Resources { def isDirectory(classLoader: ClassLoader, url: URL) = url.getProtocol match { - case "file" => new File(url.toURI).isDirectory - case "jar" => isZipResourceDirectory(url) - case "zip" => isZipResourceDirectory(url) - case "bundle" => isBundleResourceDirectory(classLoader, url) + case "file" => new File(url.toURI).isDirectory + case "jar" => isZipResourceDirectory(url) + case "zip" => isZipResourceDirectory(url) + case "bundle" | "bundleresource" => isBundleResourceDirectory(classLoader, url) case _ => throw new IllegalArgumentException(s"Cannot check isDirectory for a URL with protocol='${url.getProtocol}'") } diff --git a/core/play/src/test/scala/play/utils/ResourcesSpec.scala b/core/play/src/test/scala/play/utils/ResourcesSpec.scala index 21ab1adce9d..80632fc11c9 100644 --- a/core/play/src/test/scala/play/utils/ResourcesSpec.scala +++ b/core/play/src/test/scala/play/utils/ResourcesSpec.scala @@ -100,25 +100,31 @@ class ResourcesSpec extends Specification { isDirectory(classloader, url) must beFalse } - "return true for a directory resource URL with the 'bundle' protocol" in { - val relativeIndex = dirBundle.getAbsolutePath.indexOf("test-bundle-") - val dir = dirBundle.getAbsolutePath.substring(relativeIndex) - val url = new URL("bundle", "325.0", 25, dir, new BundleStreamHandler) - isDirectory(osgiClassloader, url) must beTrue + "return true for a directory resource URL with the 'bundle' and 'bundleresource' protocols" in { + val relativeIndex = dirBundle.getAbsolutePath.indexOf("test-bundle-") + val dir = dirBundle.getAbsolutePath.substring(relativeIndex) + val urlBundle = new URL("bundle", "325.0", 25, dir, new BundleStreamHandler) + val urlBundleresource = new URL("bundleresource", "325.0", 25, dir, new BundleStreamHandler) + (isDirectory(osgiClassloader, urlBundle) must beTrue) + .and(isDirectory(osgiClassloader, urlBundleresource) must beTrue) } - "return true for a directory resource URL that contains spaces with the 'bundle' protocol" in { - val relativeIndex = spacesDirBundle.getAbsolutePath.indexOf("test-bundle-") - val dir = spacesDirBundle.getAbsolutePath.substring(relativeIndex) - val url = new URL("bundle", "325.0", 25, dir, new BundleStreamHandler) - isDirectory(osgiClassloader, url) must beTrue + "return true for a directory resource URL that contains spaces with the 'bundle' and 'bundleresource' protocols" in { + val relativeIndex = spacesDirBundle.getAbsolutePath.indexOf("test-bundle-") + val dir = spacesDirBundle.getAbsolutePath.substring(relativeIndex) + val urlBundle = new URL("bundle", "325.0", 25, dir, new BundleStreamHandler) + val urlBundleresource = new URL("bundleresource", "325.0", 25, dir, new BundleStreamHandler) + (isDirectory(osgiClassloader, urlBundle) must beTrue) + .and(isDirectory(osgiClassloader, urlBundleresource) must beTrue) } - "return false for a file resource URL with the 'bundle' protocol" in { - val relativeIndex = fileBundle.getAbsolutePath.indexOf("test-bundle-") - val file = fileBundle.getAbsolutePath.substring(relativeIndex) - val url = new URL("bundle", "325.0", 25, file, new BundleStreamHandler) - isDirectory(osgiClassloader, url) must beFalse + "return false for a file resource URL with the 'bundle' and 'bundleresource' protocols" in { + val relativeIndex = fileBundle.getAbsolutePath.indexOf("test-bundle-") + val file = fileBundle.getAbsolutePath.substring(relativeIndex) + val urlBundle = new URL("bundle", "325.0", 25, file, new BundleStreamHandler) + val urlBundleresource = new URL("bundleresource", "325.0", 25, file, new BundleStreamHandler) + (isDirectory(osgiClassloader, urlBundle) must beFalse) + .and(isDirectory(osgiClassloader, urlBundleresource) must beFalse) } "return true for a directory resource URL with the 'zip' protocol" in { @@ -157,6 +163,7 @@ class ResourcesSpec extends Specification { } object EmptyURLStreamHandler extends URLStreamHandler { + def openConnection(u: URL) = new URLConnection(u) { def connect(): Unit = {} }