This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag 
org.apache.sling.testing.osgi-mock-2.3.2
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 2d3e1c4612ec97dffe0524349c6ae9d7ab49b2b5
Author: Stefan Seifert <[email protected]>
AuthorDate: Fri May 5 09:43:35 2017 +0000

    SLING-6832 osgi-mock: Support parsing SCR metadata when multiple definition 
XML files exists with the same name
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1793994 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/testing/mock/osgi/OsgiMetadataUtil.java  | 39 ++++++++++++++--------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java 
b/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
index a41be7c..a4c5a4b 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
@@ -20,7 +20,9 @@ package org.apache.sling.testing.mock.osgi;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -173,26 +175,35 @@ final class OsgiMetadataUtil {
     }
     
     private static void parseMetadataDocuments(Map<String,Document> cacheMap, 
String resourcePath, XPathExpression xpathExpression) {
-        try (InputStream fileStream = 
OsgiMetadataUtil.class.getClassLoader().getResourceAsStream(resourcePath)) {
-            if (fileStream != null) {
-                Document metadata = toXmlDocument(fileStream, resourcePath);
-                NodeList nodes = (NodeList)xpathExpression.evaluate(metadata, 
XPathConstants.NODESET);
-                if (nodes != null) {
-                    for (int i = 0; i < nodes.getLength(); i++) {
-                        Node node = nodes.item(i);
-                        String implementationClass = 
getImplementationClassName(node);
-                        if (implementationClass != null) {
-                            cacheMap.put(implementationClass, metadata);
-                        }
-                    }
-                }                            
+        try {
+            Enumeration<URL> resourceUrls = 
OsgiMetadataUtil.class.getClassLoader().getResources(resourcePath);
+            while (resourceUrls.hasMoreElements()) {
+                URL resourceUrl = resourceUrls.nextElement();
+                try (InputStream fileStream = resourceUrl.openStream()) {
+                    parseMetadataDocument(cacheMap, resourcePath, fileStream, 
xpathExpression);
+                }
             }
         }
-        catch (Throwable ex) {
+        catch (Exception ex) {
             log.warn("Error reading SCR metadata XML document from " + 
resourcePath, ex);
         }
     }
     
+    private static void parseMetadataDocument(Map<String,Document> cacheMap, 
String resourcePath,
+            InputStream fileStream, XPathExpression xpathExpression) throws 
XPathExpressionException {
+        Document metadata = toXmlDocument(fileStream, resourcePath);
+        NodeList nodes = (NodeList)xpathExpression.evaluate(metadata, 
XPathConstants.NODESET);
+        if (nodes != null) {
+            for (int i = 0; i < nodes.getLength(); i++) {
+                Node node = nodes.item(i);
+                String implementationClass = getImplementationClassName(node);
+                if (implementationClass != null) {
+                    cacheMap.put(implementationClass, metadata);
+                }
+            }
+        }                            
+    }
+
     private static String getImplementationClassName(Node componentNode) {
         NodeList childNodes = componentNode.getChildNodes();
         for (int j = 0; j < childNodes.getLength(); j++) {

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to