incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwo...@apache.org
Subject svn commit: r996807 - in /incubator/aries/trunk/jmx/jmx-core/src: main/java/org/apache/aries/jmx/util/FrameworkUtils.java test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
Date Tue, 14 Sep 2010 09:24:53 GMT
Author: rwonly
Date: Tue Sep 14 09:24:52 2010
New Revision: 996807

URL: http://svn.apache.org/viewvc?rev=996807&view=rev
Log:
ARIES-405 getBundleImportedPackages() of FrameworkUtils does not split package declarations
correctly

Modified:
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java?rev=996807&r1=996806&r2=996807&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
Tue Sep 14 09:24:52 2010
@@ -257,6 +257,7 @@ public class FrameworkUtils {
         Dictionary<String, String> bundleHeaders = bundle.getHeaders();
         String dynamicImportHeader = bundleHeaders.get(Constants.DYNAMICIMPORT_PACKAGE);
         // if DynamicImport-Package used, then do full iteration
+        // else means no dynamic import or has dynamic import but no wildcard "*" in it.
         if (dynamicImportHeader != null && dynamicImportHeader.contains("*")) {
             Bundle[] bundles = localBundleContext.getBundles();
             for (Bundle candidate : bundles) {
@@ -277,10 +278,14 @@ public class FrameworkUtils {
             List<String> importPackages = new ArrayList<String>();
             String importPackageHeader = bundleHeaders.get(Constants.IMPORT_PACKAGE);
             if (importPackageHeader != null && importPackageHeader.length() >
0) {
-                importPackages.addAll(extractHeaderDeclaration(importPackageHeader));
+            	for (String headerDeclaration : extractHeaderDeclaration(importPackageHeader))
{
+            		importPackages.addAll(removeParameters(headerDeclaration));
+            	}
             }
             if (dynamicImportHeader != null) {
-                importPackages.addAll(extractHeaderDeclaration(dynamicImportHeader));
+            	for (String headerDeclaration : extractHeaderDeclaration(dynamicImportHeader))
{
+            		importPackages.addAll(removeParameters(headerDeclaration));
+            	}
             }
             for (String packageName : importPackages) {
                 ExportedPackage[] candidateExports = packageAdmin.getExportedPackages(packageName);
@@ -491,7 +496,10 @@ public class FrameworkUtils {
         Dictionary<String, String> bundleHeaders = bundle.getHeaders();
         String requireBundleHeader = bundleHeaders.get(Constants.REQUIRE_BUNDLE);
         if (requireBundleHeader != null) { // only check if Require-Bundle is used
-            List<String> bundleSymbolicNames = extractHeaderDeclaration(requireBundleHeader);
+            List<String> bundleSymbolicNames = new ArrayList<String>();
+            for (String headerDeclaration : extractHeaderDeclaration(requireBundleHeader))
{
+            	bundleSymbolicNames.addAll(removeParameters(headerDeclaration));
+        	}
             for (String bundleSymbolicName: bundleSymbolicNames) {
                 RequiredBundle[] candidateRequiredBundles = packageAdmin.getRequiredBundles(bundleSymbolicName);
                 if (candidateRequiredBundles != null) {
@@ -619,11 +627,60 @@ public class FrameworkUtils {
      */
     public static List<String> extractHeaderDeclaration(String headerStatement) {
         List<String> result = new ArrayList<String>();
-        for (String headerDeclaration : headerStatement.split("\\s*,\\s*")) {
-            String name = headerDeclaration.contains(";") ? headerDeclaration.substring(0,
headerDeclaration
-                    .indexOf(";")) : headerDeclaration;
-            result.add(name);
+        
+        while(true){
+        	int commaPoz = headerStatement.indexOf(",");
+        	
+        	while (commaPoz!= -1){
+        		String testStr = headerStatement.substring(0, commaPoz);
+        		
+        		int quoteNum = 0;
+        		int bracketNum = 0;
+        		for(char testStrChar : testStr.toCharArray()){
+        			switch (testStrChar) {
+	        			case '"': quoteNum++; break;
+	        			case '[':
+	        			case ']':
+	        			case '(':
+	        			case ')': bracketNum++;
+        			}
+        		}
+        		
+        		// there might be odd numbered quote marks or brackets in the left part,
+        		// which indicates the comma appears in version=[1.0,3.5) or uses="xxx,yyy,zzz"
+	        	if (quoteNum % 2 == 1 || bracketNum %2 ==1){
+	        		commaPoz = headerStatement.indexOf(",", commaPoz+1);
+	        	}else {
+	        		break;
+	        	}
+        	}
+        	
+        	if (commaPoz == -1){	//to the end
+        		result.add(headerStatement.trim());
+        		break;
+        	}else{
+        		result.add(headerStatement.substring(0,commaPoz).trim());
+        		if (commaPoz+1 < headerStatement.trim().length()){ //commaPoz is not the last
char
+        			headerStatement = headerStatement.substring(commaPoz+1, headerStatement.length());
+        		}else{
+        			break;
+        		}
+        	}
         }
+        
         return result;
     }
+    
+    private static List<String> removeParameters(String headerDeclaration) {
+    	List<String> result = new ArrayList<String>();
+    	
+    	for (String headerSentence : headerDeclaration.split("\\s*;\\s*")) {
+            if (headerSentence.indexOf("=") == -1){
+            	result.add(headerSentence.trim());
+            }
+        }
+    	
+    	return result;
+    }
+    
 }

Modified: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java?rev=996807&r1=996806&r2=996807&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
Tue Sep 14 09:24:52 2010
@@ -139,7 +139,6 @@ public class FrameworkUtilsTest {
         when(ep2.getImportingBundles()).thenReturn(new Bundle[] { bundle, b3 });
         when(ep2.getName()).thenReturn("org.apache.aries.jmx.b2");
         when(ep2.getVersion()).thenReturn(Version.parseVersion("2.0.1"));
-       
         
         PackageAdmin admin = mock(PackageAdmin.class);
         when(admin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1 });
@@ -155,7 +154,7 @@ public class FrameworkUtilsTest {
         
         //check with ImportPackage statement
         headers.remove(Constants.DYNAMICIMPORT_PACKAGE);
-        String importPackageStatement = "org.apache.aries.jmx.b1;version=0.0.0;resolution:=optional,org.apache.aries.jmx.b2;attribute:=value";

+        String importPackageStatement = "org.apache.aries.jmx.b1;version=0.0.0;resolution:=optional,org.apache.aries.jmx.b2;attribute:=value;version=\"[2.0,
3.0)\""; 
         headers.put(Constants.IMPORT_PACKAGE, importPackageStatement);
         when(admin.getExportedPackages("org.apache.aries.jmx.b1")).thenReturn(new ExportedPackage[]
{ ep1 });
         when(admin.getExportedPackages("org.apache.aries.jmx.b2")).thenReturn(new ExportedPackage[]
{ ep2 });



Mime
View raw message