[jboss-osgi-commits] JBoss-OSGI SVN: r96638 - in projects/jboss-osgi/trunk/reactor/framework/src: main/java/org/jboss/osgi/framework/resolver/internal and 1 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Fri Nov 20 07:30:17 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-11-20 07:30:17 -0500 (Fri, 20 Nov 2009)
New Revision: 96638

Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ImportPackageImpl.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java
Log:
Resolver attribute matching

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java	2009-11-20 12:02:11 UTC (rev 96637)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java	2009-11-20 12:30:17 UTC (rev 96638)
@@ -69,6 +69,21 @@
    Set<String> getExcludes();
 
    /**
+    * Match the attributes of the given export package
+    * 
+    * In order for an import definition to be resolved to an export definition, 
+    * the values of the attributes specified by the import definition must match the values
+    * of the attributes of the export definition. By default, a match is not prevented 
+    * if the export definition contains attributes that do not occur in the import definition.
+    *  
+    * The mandatory directive in the export definition can reverse this by listing all 
+    * attributes that the Framework must match in the import definition.
+    *  
+    * @return true if the attributes match
+    */
+   boolean matchAttributes(ImportPackage importPackage);
+   
+   /**
     * Get the current set of importers of this export package.
     * 
     * @return An empty set if there is no importer

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java	2009-11-20 12:02:11 UTC (rev 96637)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java	2009-11-20 12:30:17 UTC (rev 96638)
@@ -58,21 +58,6 @@
    boolean isOptional();
    
    /**
-    * Match the attributes of the given export package
-    * 
-    * In order for an import definition to be resolved to an export definition, 
-    * the values of the attributes specified by the import definition must match the values
-    * of the attributes of the export definition. By default, a match is not prevented 
-    * if the export definition contains attributes that do not occur in the import definition.
-    *  
-    * The mandatory directive in the export definition can reverse this by listing all 
-    * attributes that the Framework must match in the import definition.
-    *  
-    * @return true if the attributes match
-    */
-   boolean matchAttributes(ExportPackage exportPackage);
-   
-   /**
     * Get the exporter that this import  package is wired to.
     * 
     * @return Null if the import is not yet resolved. 

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java	2009-11-20 12:02:11 UTC (rev 96637)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java	2009-11-20 12:30:17 UTC (rev 96638)
@@ -95,6 +95,51 @@
       return Collections.unmodifiableSet(valueList);
    }
 
+   public boolean matchAttributes(ImportPackage importPackage)
+   {
+      if (importPackage == null)
+         throw new IllegalArgumentException("Null importPackage");
+      
+      boolean match = true;
+      Set<String> importAttributes = importPackage.getAttributes();
+      Set<String> mandatoryAttributes = getMandatory();
+
+      // Check the import attributes
+      for(String attrKey : importAttributes)
+      {
+         String impValue = (String)importPackage.getAttribute(attrKey);
+         if (impValue != null)
+            impValue = impValue.trim();
+         
+         String expValue = (String)getAttribute(attrKey);
+         if (expValue != null)
+            expValue = expValue.trim();
+         
+         if (impValue.equals(expValue) == false)
+         {
+            match = false;
+            break;
+         }
+      }
+      
+      // Check the mandatory export attributes
+      for(String attrKey : mandatoryAttributes)
+      {
+         String expValue = (String)getAttribute(attrKey);
+         if (expValue == null)
+            throw new IllegalStateException("Cannot get mandatory attribute value: " + attrKey);
+         
+         String impValue = (String)importPackage.getAttribute(attrKey);
+         if (impValue == null)
+         {
+            match = false;
+            break;
+         }
+      }
+      
+      return match;
+   }
+
    public Set<ImportPackage> getImporters()
    {
       return Collections.unmodifiableSet(importers);

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ImportPackageImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ImportPackageImpl.java	2009-11-20 12:02:11 UTC (rev 96637)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ImportPackageImpl.java	2009-11-20 12:30:17 UTC (rev 96638)
@@ -76,19 +76,6 @@
       return optional;
    }
 
-   public boolean matchAttributes(ExportPackage exportPackage)
-   {
-      if (exportPackage == null)
-         throw new IllegalArgumentException("Null exportPackage");
-      
-      boolean match = false;
-      Set<String> importAttributes = getAttributes();
-      Set<String> exportAttributes = exportPackage.getAttributes();
-      Set<String> mandatoryAttributes = exportPackage.getMandatory();
-      
-      return match;
-   }
-
    public ExportPackage getExporter()
    {
       return exporter;

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java	2009-11-20 12:02:11 UTC (rev 96637)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java	2009-11-20 12:30:17 UTC (rev 96638)
@@ -63,24 +63,24 @@
       {
          Resolver resolver = getTestResolver();
          assertEquals(1, resolver.getBundles().size());
-         
+
          ResolverBundle resBundleA = resolver.getBundle(bundleA.getSymbolicName(), null);
          assertNotNull("Resolvable not null", resBundleA);
-         
+
          resBundleA = resolver.getBundle(bundleA.getSymbolicName(), bundleA.getVersion());
          assertNotNull("Resolvable not null", resBundleA);
-         
+
          resBundleA = resolver.getBundle(bundleA);
          assertNotNull("Resolvable not null", resBundleA);
-         
+
          assertNotNull(resBundleA.getBundle());
          assertEquals("simpleexport", resBundleA.getSymbolicName());
          assertEquals(Version.emptyVersion, resBundleA.getVersion());
-         
+
          List<ExportPackage> exportPackages = resBundleA.getExportPackages();
          assertNotNull("ExportPackages not null", exportPackages);
          assertEquals(1, exportPackages.size());
-         
+
          ExportPackage exportPackage = resBundleA.getExportPackage("org.jboss.test.osgi.classloader.support.a");
          assertNotNull("ExportPackage not null", exportPackage);
          assertEquals("org.jboss.test.osgi.classloader.support.a", exportPackage.getName());
@@ -90,11 +90,11 @@
          assertEquals(0, exportPackage.getMandatory().size());
          assertNull("Null includes", exportPackage.getIncludes());
          assertNull("Null excludes", exportPackage.getExcludes());
-         
+
          List<ImportPackage> importPackages = resBundleA.getImportPackages();
          assertNotNull("ImportPackages not null", importPackages);
          assertEquals(0, importPackages.size());
-         
+
          assertFalse("No sigleton", resBundleA.isSingleton());
          assertFalse("Not resolved", resBundleA.isResolved());
       }
@@ -114,7 +114,7 @@
       try
       {
          ResolverBundle resBundleA = getTestResolver().getBundle(bundleA);
-         
+
          List<ImportPackage> importPackages = resBundleA.getImportPackages();
          assertNotNull("ImportPackages not null", importPackages);
          assertEquals(1, importPackages.size());
@@ -220,7 +220,7 @@
       }
    }
 
-   @Ignore
+   @Test
    public void testPackageAttribute() throws Exception
    {
       //Bundle-SymbolicName: packageexportattribute
@@ -231,23 +231,42 @@
       {
          ResolverBundle resBundleA = getTestResolver().getBundle(bundleA);
          ExportPackage exportPackage = resBundleA.getExportPackage("org.jboss.test.osgi.classloader.support.a");
-         Set<String> attributes = exportPackage.getAttributes();
-         assertTrue("Contains attr", attributes.contains("test"));
+         Set<String> exportAttributes = exportPackage.getAttributes();
+         assertTrue("Contains attr", exportAttributes.contains("test"));
          assertEquals("x", exportPackage.getAttribute("test"));
-         
+
          //Bundle-SymbolicName: simpleimport
          //Import-Package: org.jboss.test.osgi.classloader.support.a
-         VirtualFile fileB = assembleBundle("bundleA", "/bundles/resolver/simpleimport");
+         VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleimport");
          Bundle bundleB = framework.installBundle(fileB);
          try
          {
             ResolverBundle resBundleB = getTestResolver().getBundle(bundleB);
             ImportPackage importPackage = resBundleB.getImportPackage("org.jboss.test.osgi.classloader.support.a");
+            assertTrue("Attribute match", exportPackage.matchAttributes(importPackage));
          }
          finally
          {
             bundleB.uninstall();
          }
+
+         //Bundle-SymbolicName: packageimportattribute
+         //Import-Package: org.jboss.test.osgi.classloader.support.a;test=x
+         fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattribute");
+         bundleB = framework.installBundle(fileB);
+         try
+         {
+            ResolverBundle resBundleB = getTestResolver().getBundle(bundleB);
+            ImportPackage importPackage = resBundleB.getImportPackage("org.jboss.test.osgi.classloader.support.a");
+            Set<String>  importAttributes = importPackage.getAttributes();
+            assertTrue("Contains attr", importAttributes.contains("test"));
+            assertEquals("x", importPackage.getAttribute("test"));
+            assertTrue("Attribute match", exportPackage.matchAttributes(importPackage));
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
       }
       finally
       {
@@ -255,7 +274,46 @@
       }
    }
 
-   @Ignore
+   @Test
+   public void testPackageAttributeFails() throws Exception
+   {
+      //Bundle-SymbolicName: packageexportattribute
+      //Export-Package: org.jboss.test.osgi.classloader.support.a;test=x
+      VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattribute");
+      Bundle bundleA = framework.installBundle(fileA);
+      try
+      {
+         ResolverBundle resBundleA = getTestResolver().getBundle(bundleA);
+         ExportPackage exportPackage = resBundleA.getExportPackage("org.jboss.test.osgi.classloader.support.a");
+         Set<String> attributes = exportPackage.getAttributes();
+         assertTrue("Contains attr", attributes.contains("test"));
+         assertEquals("x", exportPackage.getAttribute("test"));
+
+         //Bundle-SymbolicName: packageimportattributefails
+         //Import-Package: org.jboss.test.osgi.classloader.support.a;test=y
+         VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattributefails");
+         Bundle bundleB = framework.installBundle(fileB);
+         try
+         {
+            ResolverBundle resBundleB = getTestResolver().getBundle(bundleB);
+            ImportPackage importPackage = resBundleB.getImportPackage("org.jboss.test.osgi.classloader.support.a");
+            Set<String>  importAttributes = importPackage.getAttributes();
+            assertTrue("Contains attr", importAttributes.contains("test"));
+            assertEquals("y", importPackage.getAttribute("test"));
+            assertFalse("Attribute no match", exportPackage.matchAttributes(importPackage));
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
+      }
+      finally
+      {
+         bundleA.uninstall();
+      }
+   }
+
+   @Test
    public void testPackageAttributeMandatory() throws Exception
    {
       //Bundle-SymbolicName: packageexportattributemandatory
@@ -271,10 +329,84 @@
          assertEquals("x", exportPackage.getAttribute("test"));
          Set<String> mandatory = exportPackage.getMandatory();
          assertTrue("Contains test", mandatory.contains("test"));
+
+         //Bundle-SymbolicName: packageimportattribute
+         //Import-Package: org.jboss.test.osgi.classloader.support.a;test=x
+         VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattribute");
+         Bundle bundleB = framework.installBundle(fileB);
+         try
+         {
+            ResolverBundle resBundleB = getTestResolver().getBundle(bundleB);
+            ImportPackage importPackage = resBundleB.getImportPackage("org.jboss.test.osgi.classloader.support.a");
+            Set<String>  importAttributes = importPackage.getAttributes();
+            assertTrue("Contains attr", importAttributes.contains("test"));
+            assertEquals("x", importPackage.getAttribute("test"));
+            assertTrue("Attribute match", exportPackage.matchAttributes(importPackage));
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
       }
       finally
       {
          bundleA.uninstall();
       }
    }
+
+   @Test
+   public void testPackageAttributeMandatoryFails() throws Exception
+   {
+      //Bundle-SymbolicName: packageexportattributemandatory
+      //Export-Package: org.jboss.test.osgi.classloader.support.a;test=x;mandatory:=test
+      VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattributemandatory");
+      Bundle bundleA = framework.installBundle(fileA);
+      try
+      {
+         ResolverBundle resBundleA = getTestResolver().getBundle(bundleA);
+         ExportPackage exportPackage = resBundleA.getExportPackage("org.jboss.test.osgi.classloader.support.a");
+         Set<String> attributes = exportPackage.getAttributes();
+         assertTrue("Contains test", attributes.contains("test"));
+         assertEquals("x", exportPackage.getAttribute("test"));
+         Set<String> mandatory = exportPackage.getMandatory();
+         assertTrue("Contains test", mandatory.contains("test"));
+
+         //Bundle-SymbolicName: simpleimport
+         //Import-Package: org.jboss.test.osgi.classloader.support.a
+         VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleimport");
+         Bundle bundleB = framework.installBundle(fileB);
+         try
+         {
+            ResolverBundle resBundleB = getTestResolver().getBundle(bundleB);
+            ImportPackage importPackage = resBundleB.getImportPackage("org.jboss.test.osgi.classloader.support.a");
+            assertFalse("Attribute no match", exportPackage.matchAttributes(importPackage));
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
+
+         //Bundle-SymbolicName: packageimportattributefails
+         //Import-Package: org.jboss.test.osgi.classloader.support.a;test=y
+         fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattributefails");
+         bundleB = framework.installBundle(fileB);
+         try
+         {
+            ResolverBundle resBundleB = getTestResolver().getBundle(bundleB);
+            ImportPackage importPackage = resBundleB.getImportPackage("org.jboss.test.osgi.classloader.support.a");
+            Set<String>  importAttributes = importPackage.getAttributes();
+            assertTrue("Contains attr", importAttributes.contains("test"));
+            assertEquals("y", importPackage.getAttribute("test"));
+            assertFalse("Attribute no match", exportPackage.matchAttributes(importPackage));
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
+      }
+      finally
+      {
+         bundleA.uninstall();
+      }
+   }
 }
\ No newline at end of file



More information about the jboss-osgi-commits mailing list