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

sseifert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c66341  SLING-7864 osgi-mock: Filter out OSGi metatype files when 
parsing OSGi metadata
2c66341 is described below

commit 2c6634106b7320d47ef8973d3bd87acca07fe69a
Author: sseifert <[email protected]>
AuthorDate: Wed Aug 29 14:31:27 2018 +0200

    SLING-7864 osgi-mock: Filter out OSGi metatype files when parsing OSGi 
metadata
---
 .../apache/sling/testing/mock/osgi/OsgiMetadataUtil.java   | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git 
a/core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java 
b/core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
index 1bee861..5a4e4c2 100644
--- 
a/core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
+++ 
b/core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
@@ -71,6 +71,7 @@ final class OsgiMetadataUtil {
     private static final Logger log = 
LoggerFactory.getLogger(OsgiMetadataUtil.class);
     
     private static final String METADATA_PATH = "OSGI-INF";
+    private static final String METADATA_METATYPE_PATH = "OSGI-INF/metatype/";
 
     private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY;
     static {
@@ -165,11 +166,16 @@ final class OsgiMetadataUtil {
             throw new RuntimeException("Compiling XPath expression failed.", 
ex);
         }
 
+        // get all OSGI-INF/*.xml files from classpath
         Reflections reflections = new Reflections(METADATA_PATH, new 
ResourcesScanner());
-        Set<String> paths = 
reflections.getResources(Pattern.compile("^.*\\.xml$"));
-        for (String path : paths) {
-            parseMetadataDocuments(cacheMap, path, xpathExpression);
-        }
+        Pattern xmlFilesPattern = Pattern.compile("^.*\\.xml$");
+        Set<String> paths = reflections.getResources(xmlFilesPattern);
+        
+        // filter out OSGi metatype files and parse all found XML documents
+        Pattern metatypeFilesPattern = Pattern.compile("^" + 
Pattern.quote(METADATA_METATYPE_PATH )+ ".*$");
+        paths.stream()
+            .filter(path -> !metatypeFilesPattern.matcher(path).matches())
+            .forEach(path -> parseMetadataDocuments(cacheMap, path, 
xpathExpression));
         
         return cacheMap;
     }

Reply via email to