deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-399 fixed handling in case of ambiguous resource-lookups
Date Sat, 28 Dec 2013 11:56:00 GMT
Updated Branches:
  refs/heads/master aa9cf17b2 -> d51c210c3


DELTASPIKE-399 fixed handling in case of ambiguous resource-lookups


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/d51c210c
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/d51c210c
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/d51c210c

Branch: refs/heads/master
Commit: d51c210c32e2c6485a20a160dc230f4df06a5dcf
Parents: aa9cf17
Author: gpetracek <gpetracek@apache.org>
Authored: Sat Dec 28 12:45:10 2013 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Sat Dec 28 12:53:16 2013 +0100

----------------------------------------------------------------------
 .../ClasspathResourceProvider.java              | 19 ++++++++++++------
 .../resourceloader/ClasspathResourceTest.java   | 21 ++++++++++++++++----
 .../impl/resourceloader/FileResourceTest.java   |  2 +-
 3 files changed, 31 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d51c210c/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/resourceloader/ClasspathResourceProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/resourceloader/ClasspathResourceProvider.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/resourceloader/ClasspathResourceProvider.java
index a0a0f05..7111cf4 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/resourceloader/ClasspathResourceProvider.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/resourceloader/ClasspathResourceProvider.java
@@ -27,7 +27,9 @@ import javax.enterprise.context.ApplicationScoped;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -60,19 +62,24 @@ public class ClasspathResourceProvider extends BaseResourceProvider
     private InputStream readClassPath(final String name) throws IOException
     {
         Enumeration<URL> urls = ClassUtils.getClassLoader(null).getResources(name);
-        if (logger.isLoggable(Level.FINEST))
-        {
-            logger.finest("Found URLS " + urls);
-        }
+
+        InputStream result = null;
+        URL firstURL = null;
         while (urls.hasMoreElements())
         {
             URL url = urls.nextElement();
             InputStream is = url.openStream();
             if (is != null)
             {
-                return is;
+                if (firstURL != null)
+                {
+                    throw new IllegalStateException("multiple files found for '" + name +
+                        "' (" + firstURL.toExternalForm() + ", " + url.toExternalForm() +
")");
+                }
+                firstURL = url;
+                result = is;
             }
         }
-        return null;
+        return result;
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d51c210c/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
index 9672992..8f2e469 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
@@ -19,6 +19,7 @@
 package org.apache.deltaspike.test.core.impl.resourceloader;
 
 
+import org.apache.deltaspike.core.api.literal.ExternalResourceLiteral;
 import org.apache.deltaspike.core.api.resourceloader.ClasspathStorage;
 import org.apache.deltaspike.core.api.resourceloader.ExternalResource;
 import org.apache.deltaspike.test.util.ArchiveUtils;
@@ -33,6 +34,8 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
 import javax.inject.Inject;
 import java.io.IOException;
 import java.io.InputStream;
@@ -43,21 +46,25 @@ public class ClasspathResourceTest {
     @Deployment
     public static Archive<?> createResourceLoaderArchive()
     {
-        Archive<?> arch = ShrinkWrap.create(WebArchive.class, "resourceloader.war")
+        Archive<?> arch = ShrinkWrap.create(WebArchive.class, ClasspathResourceTest.class.getSimpleName()
+ ".war")
                 .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
-                .add(new StringAsset("some.propertykey = somevalue"),"WEB-INF/classes/myconfig.properties")
+                .add(new StringAsset("some.propertykey = somevalue"), "WEB-INF/classes/testconfig.properties")
                 .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive());
         return arch;
     }
 
     @Inject
-    @ExternalResource(storage = ClasspathStorage.class,location="myconfig.properties")
+    @ExternalResource(storage = ClasspathStorage.class,location="testconfig.properties")
     private InputStream inputStream;
 
     @Inject
-    @ExternalResource(storage = ClasspathStorage.class,location="myconfig.properties")
+    @ExternalResource(storage = ClasspathStorage.class,location="testconfig.properties")
     private Properties props;
 
+    @Inject
+    @Any
+    private Instance<InputStream> inputStreams;
+
     @Test
     public void testInputStream() throws IOException
     {
@@ -72,4 +79,10 @@ public class ClasspathResourceTest {
     {
         Assert.assertEquals("somevalue", props.getProperty("some.propertykey", "wrong answer"));
     }
+
+    @Test(expected = RuntimeException.class)
+    public void testAmbiguousFileLookup()
+    {
+        inputStreams.select(new ExternalResourceLiteral(ClasspathStorage.class, "META-INF/beans.xml")).get();
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d51c210c/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
index fed41a4..1a19b9a 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
@@ -71,7 +71,7 @@ public class FileResourceTest
     @Deployment
     public static Archive<?> createResourceLoaderArchive()
     {
-        Archive<?> arch = ShrinkWrap.create(WebArchive.class, "resourceloader.war")
+        Archive<?> arch = ShrinkWrap.create(WebArchive.class, FileResourceTest.class.getSimpleName()
+ ".war")
                 .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
                 .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive());
         return arch;


Mime
View raw message