You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:20:45 UTC
[sling-org-apache-sling-testing-osgi-mock] 02/04: SLING-6832
osgi-mock: Support parsing SCR metadata when multiple definition XML files
exists with the same name
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-1.9.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
commit 69817129db944bea359385c6d01a348b24e8f5a3
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri May 5 09:44:55 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/branches/testing/mocks/osgi-mock-1.x@1793995 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/testing/mock/osgi/OsgiMetadataUtil.java | 55 +++++++++++++---------
1 file changed, 33 insertions(+), 22 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 49ad738..8306218 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,38 +175,47 @@ final class OsgiMetadataUtil {
}
private static void parseMetadataDocuments(Map<String,Document> cacheMap, String resourcePath, XPathExpression xpathExpression) {
- InputStream fileStream = null;
try {
- 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);
+ Enumeration<URL> resourceUrls = OsgiMetadataUtil.class.getClassLoader().getResources(resourcePath);
+ while (resourceUrls.hasMoreElements()) {
+ URL resourceUrl = resourceUrls.nextElement();
+ InputStream fileStream = null;
+ try {
+ fileStream = resourceUrl.openStream();
+ parseMetadataDocument(cacheMap, resourcePath, fileStream, xpathExpression);
+ }
+ finally {
+ if (fileStream != null) {
+ try {
+ fileStream.close();
+ }
+ catch (IOException e) {
+ // ignore
}
}
- }
+ }
}
}
- catch (Throwable ex) {
+ catch (Exception ex) {
log.warn("Error reading SCR metadata XML document from " + resourcePath, ex);
}
- finally {
- if (fileStream != null) {
- try {
- fileStream.close();
- }
- catch (IOException e) {
- // ignore
+ }
+
+ 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
"commits@sling.apache.org" <co...@sling.apache.org>.