[jboss-osgi-commits] JBoss-OSGI SVN: r96568 - in projects/jboss-osgi/trunk/reactor/framework/src/test: resources/META-INF and 2 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu Nov 19 09:16:53 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-11-19 09:16:52 -0500 (Thu, 19 Nov 2009)
New Revision: 96568

Added:
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportother/
Removed:
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportsecond/
Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/resolver-rules.drl
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportother/META-INF/MANIFEST.MF
Log:
Prefer wire to exporter with lower bundle id

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java	2009-11-19 13:46:21 UTC (rev 96567)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java	2009-11-19 14:16:52 UTC (rev 96568)
@@ -809,9 +809,9 @@
       // Export-Package: org.jboss.test.osgi.classloader.support.a
       VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexport", A.class);
       
-      // Bundle-SymbolicName: simpleexport
+      // Bundle-SymbolicName: simpleexportother
       // Export-Package: org.jboss.test.osgi.classloader.support.a
-      VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportsecond", A.class);
+      VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportother", A.class);
       
       // Bundle-SymbolicName: simpleimport
       // Import-Package: org.jboss.test.osgi.classloader.support.a
@@ -875,9 +875,9 @@
       // Export-Package: org.jboss.test.osgi.classloader.support.a
       VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexport", A.class);
       
-      // Bundle-SymbolicName: simpleexport
+      // Bundle-SymbolicName: simpleexportother
       // Export-Package: org.jboss.test.osgi.classloader.support.a
-      VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportsecond", A.class);
+      VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportother", A.class);
       
       // Bundle-SymbolicName: simpleimport
       // Import-Package: org.jboss.test.osgi.classloader.support.a
@@ -1057,6 +1057,138 @@
       }
    }
    
+   @Test
+   public void testPreferredExporterLowerId() throws Exception
+   {
+      Resolver resolver = getTestResolver();
+      assertEquals("No bundles in resolver", 0, resolver.getBundles().size());
+
+      // Bundle-SymbolicName: simpleexport
+      // Export-Package: org.jboss.test.osgi.classloader.support.a
+      VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexport", A.class);
+      
+      // Bundle-SymbolicName: simpleexportother
+      // Export-Package: org.jboss.test.osgi.classloader.support.a
+      VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportother", A.class);
+      
+      // Bundle-SymbolicName: simpleimport
+      // Import-Package: org.jboss.test.osgi.classloader.support.a
+      VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+      
+      Bundle bundleA = framework.installBundle(fileA);
+      try
+      {
+         Bundle bundleB = framework.installBundle(fileB);
+         try
+         {
+            // Resolve the installed bundles
+            resolver.resolve(null);
+
+            // Verify resBundle for bundleA
+            ResolverBundle resBundleA = resolver.getBundle(bundleA);
+            assertTrue("BundleA resolved", resBundleA.isResolved());
+            
+            // Verify resBundle for bundleB
+            ResolverBundle resBundleB = resolver.getBundle(bundleB);
+            assertTrue("BundleB resolved", resBundleB.isResolved());
+
+            Bundle bundleC = framework.installBundle(fileC);
+            try
+            {
+               // Resolve the installed bundles
+               resolver.resolve(null);
+
+               // Verify resBundle for bundleC
+               ResolverBundle resBundleC = resolver.getBundle(bundleC);
+               assertTrue("BundleC resolved", resBundleC.isResolved());
+               
+               // Verify that bundleC is wired to bundleA
+               ExportPackage exporter = resolver.getExporter(bundleC, A.class.getPackage().getName());
+               assertNotNull("Exporter not null", exporter);
+               assertEquals("Wired to bundleA", bundleA.getSymbolicName(), exporter.getOwner().getSymbolicName());
+            }
+            finally
+            {
+               bundleC.uninstall();
+            }
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
+      }
+      finally
+      {
+         bundleA.uninstall();
+      }
+   }
+   
+   @Test
+   public void testPreferredExporterLowerIdReverse() throws Exception
+   {
+      Resolver resolver = getTestResolver();
+      assertEquals("No bundles in resolver", 0, resolver.getBundles().size());
+
+      // Bundle-SymbolicName: simpleexportother
+      // Export-Package: org.jboss.test.osgi.classloader.support.a
+      VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexportother", A.class);
+      
+      // Bundle-SymbolicName: simpleexport
+      // Export-Package: org.jboss.test.osgi.classloader.support.a
+      VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+      
+      // Bundle-SymbolicName: simpleimport
+      // Import-Package: org.jboss.test.osgi.classloader.support.a
+      VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+      
+      Bundle bundleA = framework.installBundle(fileA);
+      try
+      {
+         Bundle bundleB = framework.installBundle(fileB);
+         try
+         {
+            // Resolve the installed bundles
+            resolver.resolve(null);
+
+            // Verify resBundle for bundleA
+            ResolverBundle resBundleA = resolver.getBundle(bundleA);
+            assertTrue("BundleA resolved", resBundleA.isResolved());
+            
+            // Verify resBundle for bundleB
+            ResolverBundle resBundleB = resolver.getBundle(bundleB);
+            assertTrue("BundleB resolved", resBundleB.isResolved());
+
+            Bundle bundleC = framework.installBundle(fileC);
+            try
+            {
+               // Resolve the installed bundles
+               resolver.resolve(null);
+
+               // Verify resBundle for bundleC
+               ResolverBundle resBundleC = resolver.getBundle(bundleC);
+               assertTrue("BundleC resolved", resBundleC.isResolved());
+               
+               // Verify that bundleC is wired to bundleA
+               ExportPackage exporter = resolver.getExporter(bundleC, A.class.getPackage().getName());
+               assertNotNull("Exporter not null", exporter);
+               assertEquals("Wired to bundleA", bundleA.getSymbolicName(), exporter.getOwner().getSymbolicName());
+            }
+            finally
+            {
+               bundleC.uninstall();
+            }
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
+      }
+      finally
+      {
+         bundleA.uninstall();
+      }
+   }
+   
    /*
    public void testLogger() throws Exception
    {

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/resolver-rules.drl
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/resolver-rules.drl	2009-11-19 13:46:21 UTC (rev 96567)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/resolver-rules.drl	2009-11-19 14:16:52 UTC (rev 96568)
@@ -87,11 +87,11 @@
 salience 2000
 when
 	$importer : ResolverBundle( state == Bundle.INSTALLED, resolved == false )
-	$reqbundle : RequiredBundle( ) from $importer.requiredBundles
-	not RequiredBundle( owner == $importer, this == $reqbundle ) 
+	$reqbnd : RequiredBundle( ) from $importer.requiredBundles
+	not RequiredBundle( owner == $importer, this == $reqbnd ) 
 then
-    log("Add " + $reqbundle);
-    insert( $reqbundle );
+    log("Add " + $reqbnd);
+    insert( $reqbnd );
 end
 
 
@@ -161,14 +161,16 @@
 * associated with a higher version on the ExportPackage.
 */
 rule "Retract WireCandidate to lower version"
-salience 1000
+salience 400
 when
-    $expkeep : ExportPackage( )
+    $bndkeep : ResolverBundle(  )
+    $expkeep : ExportPackage( owner  == $bndkeep )
     $wckeep : WireCandidate( exportPackage == $expkeep )
-    $resdel : ResolverBundle( resolved == false )
-    $expdel : ExportPackage( this != $expkeep, owner  == $resdel )
+    $bnddel : ResolverBundle( )
+    $expdel : ExportPackage( this != $expkeep, owner  == $bnddel )
     $wcdel : WireCandidate( importPackage == $wckeep.importPackage, exportPackage == $expdel )
-    eval ( $expkeep.getVersion().compareTo($expdel.getVersion()) > 0 ) 
+    eval( $expkeep.getVersion().compareTo($expdel.getVersion()) > 0 ) 
+    eval( $bnddel.isResolved() == false || ( $bnddel.isResolved() == true && $bndkeep.isResolved() == true ) )
 then
     log("Retract lower version " + $wcdel);
     retract ( $wcdel );
@@ -176,16 +178,36 @@
 
 /**************************************************************************************************
 * A rule that retracts a WireCandidate if there is another 
+* associated with a lower bundle id.
+*/
+rule "Retract WireCandidate to higher bundle id"
+salience 300
+when
+    $bndkeep : ResolverBundle(  )
+    $expkeep : ExportPackage( owner  == $bndkeep )
+    $wckeep : WireCandidate( exportPackage == $expkeep )
+    $bnddel : ResolverBundle( )
+    $expdel : ExportPackage( this != $expkeep, owner  == $bnddel )
+    $wcdel : WireCandidate( importPackage == $wckeep.importPackage, exportPackage == $expdel )
+    eval ( $bnddel.getBundleId() > $bndkeep.getBundleId() ) 
+    eval( $bnddel.isResolved() == false || ( $bnddel.isResolved() == true && $bndkeep.isResolved() == true ) )
+then
+    log("Retract higher bundle id " + $wcdel);
+    retract ( $wcdel );
+end
+
+/**************************************************************************************************
+* A rule that retracts a WireCandidate if there is another 
 * associated with an already resolved exporter.
 */
 rule "Retract WireCandidate to unresolved exporter"
 salience 200
 when
-    $reskeep : ResolverBundle( resolved == true )
-    $expkeep : ExportPackage( owner  == $reskeep )
+    $bndkeep : ResolverBundle( resolved == true )
+    $expkeep : ExportPackage( owner  == $bndkeep )
     $wckeep : WireCandidate( exportPackage == $expkeep )
-    $resdel : ResolverBundle( resolved == false )
-    $expdel : ExportPackage( this != $expkeep, owner  == $resdel )
+    $bnddel : ResolverBundle( resolved == false )
+    $expdel : ExportPackage( this != $expkeep, owner  == $bnddel )
     $wcdel : WireCandidate( importPackage == $wckeep.importPackage, exportPackage == $expdel )
 then
     log("Retract unresolved exporter " + $wcdel);
@@ -199,10 +221,10 @@
 salience 100
 when
     $provider : ResolverBundle( )
-    $reqbundle : RequiredBundle( symbolicName == $provider.symbolicName, version == null, provider == null )
+    $reqbnd : RequiredBundle( symbolicName == $provider.symbolicName, version == null, provider == null )
 then
-    log("RequiredBundle match " + $reqbundle + " --> " + $provider);
-    modify ( $reqbundle ) { setProvider( $provider ) };
+    log("RequiredBundle match " + $reqbnd + " --> " + $provider);
+    modify ( $reqbnd ) { setProvider( $provider ) };
 end
 
 /**************************************************************************************************
@@ -213,11 +235,11 @@
 salience 100
 when
     $provider : ResolverBundle( )
-    $reqbundle : RequiredBundle( symbolicName == $provider.symbolicName, version != null, provider == null )
-    eval( inRange( $reqbundle.getVersion(), $provider.getVersion()))
+    $reqbnd : RequiredBundle( symbolicName == $provider.symbolicName, version != null, provider == null )
+    eval( inRange( $reqbnd.getVersion(), $provider.getVersion()))
 then
-    log("RequiredBundle match " + $reqbundle + " --> " + $provider);
-    modify ( $reqbundle ) { setProvider( $provider ) };
+    log("RequiredBundle match " + $reqbnd + " --> " + $provider);
+    modify ( $reqbnd ) { setProvider( $provider ) };
 end
 
 /**************************************************************************************************
@@ -345,10 +367,10 @@
 rule "Retract uninstalled RequiredBundles"
 when
     $importer : ResolverBundle( state == Bundle.UNINSTALLED )
-    $reqbundle : RequiredBundle( owner == $importer )
+    $reqbnd : RequiredBundle( owner == $importer )
 then
-    log("Uninstall " + $reqbundle);
-    retract ( $reqbundle );
+    log("Uninstall " + $reqbnd);
+    retract ( $reqbnd );
 end
 
 /**************************************************************************************************

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportother (from rev 96553, projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportsecond)

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportother/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportsecond/META-INF/MANIFEST.MF	2009-11-19 07:09:26 UTC (rev 96553)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/resolver/simpleexportother/META-INF/MANIFEST.MF	2009-11-19 14:16:52 UTC (rev 96568)
@@ -1,3 +1,3 @@
 Bundle-ManifestVersion: 2
-Bundle-SymbolicName: simpleexportsecond
+Bundle-SymbolicName: simpleexportother
 Export-Package: org.jboss.test.osgi.classloader.support.a



More information about the jboss-osgi-commits mailing list