Author: gnodet
Date: Mon May 29 15:04:06 2017
New Revision: 1796641

URL: http://svn.apache.org/viewvc?rev=1796641&view=rev
Log:
[ARIES-1726] Always use findEntries to find blueprint xml configuration from 
fragments

Modified:
    
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
    
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java

Modified: 
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1796641&r1=1796640&r2=1796641&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
 Mon May 29 15:04:06 2017
@@ -18,7 +18,6 @@
  */
 package org.apache.aries.blueprint.container;
 
-import java.io.FileNotFoundException;
 import java.net.URI;
 import java.net.URL;
 import java.security.AccessControlContext;
@@ -68,7 +67,6 @@ import org.apache.aries.blueprint.utils.
 import org.apache.aries.blueprint.utils.JavaUtils;
 import org.apache.aries.blueprint.utils.ServiceUtil;
 import org.apache.aries.proxy.ProxyManager;
-import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -137,7 +135,7 @@ public class BlueprintContainerImpl
     private final Bundle extenderBundle;
     private final BlueprintListener eventDispatcher;
     private final NamespaceHandlerRegistry handlers;
-    private final List<Object> pathList;
+    private final List<URL> pathList;
     private final ComponentDefinitionRegistryImpl componentDefinitionRegistry;
     private final AggregateConverter converter;
     private final ExecutorService executors;
@@ -165,7 +163,7 @@ public class BlueprintContainerImpl
 
     public BlueprintContainerImpl(Bundle bundle, BundleContext bundleContext, 
Bundle extenderBundle, BlueprintListener eventDispatcher,
                                   NamespaceHandlerRegistry handlers, 
ExecutorService executor, ScheduledExecutorService timer,
-                                  List<Object> pathList, ProxyManager 
proxyManager, Collection<URI> namespaces) {
+                                  List<URL> pathList, ProxyManager 
proxyManager, Collection<URI> namespaces) {
         this.bundle = bundle;
         this.bundleContext = bundleContext;
         this.extenderBundle = extenderBundle;
@@ -303,7 +301,7 @@ public class BlueprintContainerImpl
                         readDirectives();
                         eventDispatcher.blueprintEvent(new 
BlueprintEvent(BlueprintEvent.CREATING, getBundle(), getExtenderBundle()));
                         parser = new Parser();
-                        parser.parse(getResources());
+                        parser.parse(pathList);
                         namespaces = parser.getNamespaces();
                         if (additionalNamespaces != null) {
                             namespaces.addAll(additionalNamespaces);
@@ -444,25 +442,6 @@ public class BlueprintContainerImpl
         }
     }
 
-    private List<URL> getResources() throws FileNotFoundException {
-        List<URL> resources = new ArrayList<URL>();
-        for (Object path : pathList) {
-            if (path instanceof URL) {
-                resources.add((URL) path);                
-            } else if (path instanceof String) {
-                URL url = bundle.getEntry((String) path);
-                if (url == null) {
-                    throw new FileNotFoundException("Unable to find 
configuration file for " + path);
-                } else {
-                    resources.add(url);
-                }
-            } else {
-                throw new IllegalArgumentException("Unexpected path type: " + 
path.getClass());
-            }
-        }
-        return resources;
-    }
-    
     public Class loadClass(final String name) throws ClassNotFoundException {
         if (accessControlContext == null) {
             return bundle.loadClass(name);

Modified: 
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=1796641&r1=1796640&r2=1796641&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
 Mon May 29 15:04:06 2017
@@ -261,15 +261,15 @@ public class BlueprintExtender implement
     }
 
     private boolean createContainer(Bundle bundle) {
-        List<Object> paths = getBlueprintPaths(bundle);
+        List<URL> paths = getBlueprintPaths(bundle);
         return createContainer(bundle, paths);
     }
 
-    private boolean createContainer(Bundle bundle, List<Object> paths) {
+    private boolean createContainer(Bundle bundle, List<URL> paths) {
         return createContainer(bundle, paths, null);
     }
 
-    private boolean createContainer(Bundle bundle, List<Object> paths, 
Collection<URI> namespaces) {
+    private boolean createContainer(Bundle bundle, List<URL> paths, 
Collection<URI> namespaces) {
         try {
             if (paths == null || paths.isEmpty()) {
                 // This bundle is not a blueprint bundle, so ignore it
@@ -351,12 +351,44 @@ public class BlueprintExtender implement
         }
     }
 
-    private List<Object> getBlueprintPaths(Bundle bundle) {
+    private List<URL> resolvePaths(Bundle bundle, List<Object> paths) {
+        if (paths == null || paths.isEmpty()) {
+            return null;
+        }
+        List<URL> resolved = new ArrayList<URL>(paths.size());
+        for (Object path : paths) {
+            if (path instanceof URL) {
+                resolved.add((URL) path);
+            } else if (path instanceof String) {
+                String name = (String) path;
+                if (name.endsWith("/")) {
+                    addEntries(bundle, name, "*.xml", resolved);
+                } else {
+                    String baseName;
+                    String filePattern;
+                    int pos = name.lastIndexOf('/');
+                    if (pos < 0) {
+                        baseName = "/";
+                        filePattern = name;
+                    } else {
+                        baseName = name.substring(0, pos + 1);
+                        filePattern = name.substring(pos + 1);
+                    }
+                    addEntries(bundle, baseName, filePattern, resolved);
+                }
+            } else {
+                throw new IllegalArgumentException("Unexpected path type: " + 
path.getClass());
+            }
+        }
+        return resolved;
+    }
+
+    private List<URL> getBlueprintPaths(Bundle bundle) {
         LOGGER.debug("Scanning bundle {}/{} for blueprint application", 
bundle.getSymbolicName(), bundle.getVersion());
         try {
-            List<Object> pathList = new ArrayList<Object>();
-            String blueprintHeader = (String) 
bundle.getHeaders().get(BlueprintConstants.BUNDLE_BLUEPRINT_HEADER);
-            String blueprintHeaderAnnotation = (String) 
bundle.getHeaders().get(BlueprintConstants.BUNDLE_BLUEPRINT_ANNOTATION_HEADER);
+            List<URL> pathList = new ArrayList<URL>();
+            String blueprintHeader = 
bundle.getHeaders().get(BlueprintConstants.BUNDLE_BLUEPRINT_HEADER);
+            String blueprintHeaderAnnotation = 
bundle.getHeaders().get(BlueprintConstants.BUNDLE_BLUEPRINT_ANNOTATION_HEADER);
             if (blueprintHeader == null) {
                 blueprintHeader = "OSGI-INF/blueprint/";
             }
@@ -376,11 +408,7 @@ public class BlueprintExtender implement
                         baseName = name.substring(0, pos + 1);
                         filePattern = name.substring(pos + 1);
                     }
-                    if (hasWildcards(filePattern)) {
-                        addEntries(bundle, baseName, filePattern, pathList);
-                    } else {
-                        addEntry(bundle, name, pathList);
-                    }
+                    addEntries(bundle, baseName, filePattern, pathList);
                 }
             }
             // Check annotations
@@ -521,23 +549,18 @@ public class BlueprintExtender implement
         }
         return compatible;
     }
-    
-    private boolean hasWildcards(String path) {
-        return path.indexOf("*") >= 0; 
-    }
-    
+
     private String getFilePart(URL url) {
         String path = url.getPath();
         int index = path.lastIndexOf('/');
         return path.substring(index + 1);
     }
     
-    private String cachePath(Bundle bundle, String filePath)
-    {
-      return Integer.toHexString(bundle.hashCode()) + "/" + filePath;
+    private String cachePath(Bundle bundle, String filePath) {
+        return Integer.toHexString(bundle.hashCode()) + "/" + filePath;
     }    
     
-    private URL getOverrideURLForCachePath(String privatePath){
+    private URL getOverrideURLForCachePath(String privatePath) {
         URL override = null;
         File privateDataVersion = context.getDataFile(privatePath);
         if (privateDataVersion != null
@@ -550,27 +573,13 @@ public class BlueprintExtender implement
         }
         return override;
     }
-    
-    private URL getOverrideURL(Bundle bundle, String path){
-        String cachePath = cachePath(bundle, path);
-        return getOverrideURLForCachePath(cachePath);
-    }
-    
-    private URL getOverrideURL(Bundle bundle, URL path, String basePath){
+
+    private URL getOverrideURL(Bundle bundle, URL path, String basePath) {
         String cachePath = cachePath(bundle, basePath + getFilePart(path));
         return getOverrideURLForCachePath(cachePath);
     }    
     
-    private void addEntry(Bundle bundle, String path, List<Object> pathList) {
-        URL override = getOverrideURL(bundle, path);
-        if(override == null) {
-            pathList.add(path);
-        } else {
-            pathList.add(override);
-        }
-    }
-    
-    private void addEntries(Bundle bundle, String path, String filePattern, 
List<Object> pathList) {
+    private void addEntries(Bundle bundle, String path, String filePattern, 
List<URL> pathList) {
         Enumeration<?> e = bundle.findEntries(path, filePattern, false);
         while (e != null && e.hasMoreElements()) {
             URL u = (URL) e.nextElement();
@@ -599,7 +608,7 @@ public class BlueprintExtender implement
         }
 
         public BlueprintContainer createContainer(Bundle bundle, List<Object> 
blueprintPaths) {
-            if (BlueprintExtender.this.createContainer(bundle, 
blueprintPaths)) {
+            if (BlueprintExtender.this.createContainer(bundle, 
resolvePaths(bundle, blueprintPaths))) {
                 return getContainer(bundle);
             } else {
                 return null;
@@ -607,7 +616,7 @@ public class BlueprintExtender implement
         }
 
         public BlueprintContainer createContainer(Bundle bundle, List<Object> 
blueprintPaths, Collection<URI> namespaces) {
-            if (BlueprintExtender.this.createContainer(bundle, blueprintPaths, 
namespaces)) {
+            if (BlueprintExtender.this.createContainer(bundle, 
resolvePaths(bundle, blueprintPaths), namespaces)) {
                 return getContainer(bundle);
             } else {
                 return null;


Reply via email to