You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by mn...@apache.org on 2012/11/20 17:54:48 UTC

svn commit: r1411741 - in /aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling: impl/ModelledResourceManagerImpl.java internal/BundleBlueprintParser.java

Author: mnuttall
Date: Tue Nov 20 16:54:48 2012
New Revision: 1411741

URL: http://svn.apache.org/viewvc?rev=1411741&view=rev
Log:
Aries-969: Empty Bundle-Blueprint: header should result in no blueprint container

Modified:
    aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
    aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/internal/BundleBlueprintParser.java

Modified: aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java?rev=1411741&r1=1411740&r2=1411741&view=diff
==============================================================================
--- aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java (original)
+++ aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java Tue Nov 20 16:54:48 2012
@@ -26,6 +26,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -206,6 +208,8 @@ public class ModelledResourceManagerImpl
       return mbi;      
   }
 
+
+  
   /**
    * Helper method to pass a single bundle into findBlueprints 
    * @param bundleMf The bundle manifest 
@@ -220,32 +224,38 @@ public class ModelledResourceManagerImpl
 
     Collection<IFile> blueprints = new ArrayList<IFile>();
     BundleBlueprintParser bpParser = new BundleBlueprintParser(bundleMf);
-    List<IFile> files = bundle.listAllFiles();
-    Iterator<IFile> it = files.iterator();
-    while (it.hasNext()) {
-        IFile file = it.next();         
-        String directoryFullPath = file.getName(); 
-        String directoryName = "";
-        String fileName = "";
-        if (directoryFullPath.lastIndexOf("/") != -1) {
-        	// This bundle may be nested within another archive. In that case, we need to trim
-        	// /bundleFileName.jar from the front of the directory. 
-        	int bundleNameLength = bundle.getName().length();
-            directoryName = directoryFullPath.substring(bundleNameLength, directoryFullPath.lastIndexOf("/"));
-            if (directoryName.startsWith("/") && directoryName.length() > 1) { 
-            	directoryName = directoryName.substring(1);
-            }
-            fileName = directoryFullPath.substring(directoryFullPath.lastIndexOf("/") + 1);
-        } else {
-            if (file.isFile()) {
-                directoryName="";
-                fileName = directoryFullPath;
-            } 
-
-        }
-        if (bpParser.isBPFile(directoryName, fileName)) {
-            blueprints.add(file);
-        }
+    
+    /* OSGi R5 Spec, section 121.3.4: "If the Bundle-Blueprint header is specified but empty, then the Blueprint 
+     * bundle must not be managed. This can be used to temporarily disable a Blueprint bundle."
+     */
+    if (bpParser.mightContainBlueprint()) { 
+	    List<IFile> files = bundle.listAllFiles();
+	    Iterator<IFile> it = files.iterator();
+	    while (it.hasNext()) {
+	        IFile file = it.next();         
+	        String directoryFullPath = file.getName(); 
+	        String directoryName = "";
+	        String fileName = "";
+	        if (directoryFullPath.lastIndexOf("/") != -1) {
+	        	// This bundle may be nested within another archive. In that case, we need to trim
+	        	// /bundleFileName.jar from the front of the directory. 
+	        	int bundleNameLength = bundle.getName().length();
+	            directoryName = directoryFullPath.substring(bundleNameLength, directoryFullPath.lastIndexOf("/"));
+	            if (directoryName.startsWith("/") && directoryName.length() > 1) { 
+	            	directoryName = directoryName.substring(1);
+	            }
+	            fileName = directoryFullPath.substring(directoryFullPath.lastIndexOf("/") + 1);
+	        } else {
+	            if (file.isFile()) {
+	                directoryName="";
+	                fileName = directoryFullPath;
+	            } 
+	
+	        }
+	        if (!file.isDirectory() && bpParser.isBPFile(directoryName, fileName)) {
+	            blueprints.add(file);
+	        }
+	    }
     }
     
     Collection<InputStream> result = new ArrayList<InputStream>();

Modified: aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/internal/BundleBlueprintParser.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/internal/BundleBlueprintParser.java?rev=1411741&r1=1411740&r2=1411741&view=diff
==============================================================================
--- aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/internal/BundleBlueprintParser.java (original)
+++ aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/internal/BundleBlueprintParser.java Tue Nov 20 16:54:48 2012
@@ -17,6 +17,8 @@
  * under the License.
  */
 package org.apache.aries.application.modelling.internal;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.regex.Pattern;
@@ -105,10 +107,34 @@ public class BundleBlueprintParser {
     setup(null);
   }
   
+  static final boolean _blueprintHeaderMandatory;
+  static 
+  { 
+	  String blueprintHeaderMandatory = AccessController.doPrivileged(new PrivilegedAction<String>() 
+	  {
+		  public String run()
+	      {
+	        return System.getProperty("org.apache.aries.blueprint.header.mandatory", "false");
+	      }
+	  });
+	  _blueprintHeaderMandatory = blueprintHeaderMandatory.toLowerCase().equals("true");
+  }
+  
+  /**
+   * @return true if this bundle might contain blueprint files
+   */
+  public boolean mightContainBlueprint() {
+	  return _mfHeader != null && _mfHeader.trim().length() > 0;
+  }
+  
   private void setup (String bundleBPHeader) { 
     _paths = new LinkedList <Path>();
     if (bundleBPHeader == null) { 
-      _mfHeader = DEFAULT_HEADER;
+    	if (_blueprintHeaderMandatory) { 
+    		_mfHeader = null;
+    	} else { 
+    		_mfHeader = DEFAULT_HEADER;	
+    	}
     } else { 
       _mfHeader = bundleBPHeader;
     }