[jboss-cvs] JBossAS SVN: r103320 - in projects/jboss-osgi: projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/packageadmin and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 31 08:50:49 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-31 08:50:47 -0400 (Wed, 31 Mar 2010)
New Revision: 103320

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi38/OSGi38TestCase.java
Log:
[JBDEPLOY-245] - Reset deployment stages to previously cached values
Extract DeploymentMetaData attachment to separate deployer that only works when deployers-2.2.0.Alpha4 is present

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java	2010-03-31 12:48:07 UTC (rev 103319)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java	2010-03-31 12:50:47 UTC (rev 103320)
@@ -26,6 +26,8 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.spi.util.ConstantsHelper;
 import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.test.osgi.AbstractFrameworkTest;
 import org.jboss.test.osgi.bundle.support.a.ActivatorA;

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java	2010-03-31 12:48:07 UTC (rev 103319)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java	2010-03-31 12:50:47 UTC (rev 103320)
@@ -36,6 +36,7 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.IncompleteDeploymentException;
 import org.jboss.deployers.plugins.classloading.AbstractDeploymentClassLoaderPolicyModule;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStage;
@@ -337,15 +338,9 @@
       boolean allResolved = resolvableBundles.containsAll(unresolvedBundles);
 
       // Advance the bundles to stage CLASSLOADER and check at the end
-      advanceBundlesToClassloader(resolvableBundles);
-      try
+      if (advanceBundlesToClassloader(resolvableBundles) == false)
       {
-         DeployerClient deployerClient = getBundleManager().getDeployerClient();
-         deployerClient.checkComplete();
-      }
-      catch (DeploymentException ex)
-      {
-         log.error("Error resolving bundles: " + resolvableBundles, ex);
+         resetBundleDeploymentStates(resolvableBundles);
          allResolved = false;
          
          // Reset the required state for bundles that didn't get resolved
@@ -364,25 +359,24 @@
       return allResolved;
    }
 
-   private void advanceBundlesToClassloader(List<OSGiBundleState> resolvableBundles) 
+   private boolean advanceBundlesToClassloader(List<OSGiBundleState> resolvableBundles) 
    {
+      DeployerClient deployerClient = getBundleManager().getDeployerClient();
+
+      // Remember the state of every deployment unit
       for (OSGiBundleState bundleState: resolvableBundles)
       {
-         // If the bundle is in any other state but INSTALLED there is nothing to do
-         if (bundleState.getState() != Bundle.INSTALLED)
-            continue;
-
          DeploymentUnit unit = bundleState.getDeploymentUnit();
-         String unitName = unit.getName();
+         unit.addAttachment(StateTuple.class, new StateTuple(unit));
+      }
 
-         ControllerContext context = unit.getAttachment(ControllerContext.class);
-         ControllerState requiredState = context.getRequiredState();
-         DeploymentStage requiredStage = unit.getRequiredStage();
-
+      // Change to DeploymentStage CLASSLOADER 
+      for (OSGiBundleState bundleState: resolvableBundles)
+      {
          try
          {
-            DeployerClient deployerClient = getBundleManager().getDeployerClient();
-            deployerClient.change(unitName, DeploymentStages.CLASSLOADER);
+            DeploymentUnit unit = bundleState.getDeploymentUnit();
+            deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
 
             // Advance the attached fragments to CLASSLOADER 
             for (OSGiFragmentState fragment : bundleState.getAttachedFragments())
@@ -393,15 +387,41 @@
          }
          catch (DeploymentException ex)
          {
-            unit.setRequiredStage(requiredStage);
-            context.setRequiredState(requiredState);
-            unit.addAttachment(DeploymentException.class, ex);
-            ex.printStackTrace();
             log.error("Error resolving bundle: " + bundleState, ex);
          }
       }
+      
+      // Check that every deployment could reach the desired stage
+      try
+      {
+         deployerClient.checkComplete();
+         return true;
+      }
+      catch (DeploymentException ex)
+      {
+         log.error("Error resolving bundles: " + resolvableBundles, ex);
+         if (ex instanceof IncompleteDeploymentException)
+         {
+            // TODO relay better error message to caller
+            // IncompleteDeploymentException idex = (IncompleteDeploymentException)ex;
+         }
+         return false;
+      }
    }
 
+   private void resetBundleDeploymentStates(List<OSGiBundleState> resolvableBundles) 
+   {
+      for (OSGiBundleState bundleState: resolvableBundles)
+      {
+         DeploymentUnit unit = bundleState.getDeploymentUnit();
+         StateTuple stateTuple = unit.removeAttachment(StateTuple.class);
+         if (stateTuple != null)
+         {
+            stateTuple.reset(unit);
+         }
+      }
+   }
+
    private boolean verifyExecutionEnvironment(OSGiBundleState bundleState, boolean errorOnFail) throws BundleException
    {
       // A bundle can only resolve if the framework is running on a VM which
@@ -432,4 +452,24 @@
       
       return foundExecEnv;
    }
+   
+   static class StateTuple
+   {
+      ControllerState requiredState;
+      DeploymentStage requiredStage;
+      
+      StateTuple(DeploymentUnit unit)
+      {
+         ControllerContext context = unit.getAttachment(ControllerContext.class);
+         requiredState = context.getRequiredState();
+         requiredStage = unit.getRequiredStage();
+      }
+      
+      void reset(DeploymentUnit unit)
+      {
+         ControllerContext context = unit.getAttachment(ControllerContext.class);
+         context.setRequiredState(requiredState);
+         unit.setRequiredStage(requiredStage);
+      }
+   };
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi38/OSGi38TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi38/OSGi38TestCase.java	2010-03-31 12:48:07 UTC (rev 103319)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi38/OSGi38TestCase.java	2010-03-31 12:50:47 UTC (rev 103320)
@@ -161,9 +161,7 @@
          }
 
          OSGiBundle bundleX = runtime.installBundle("jbosgi38-bundleX.jar");
-         
-         System.out.println("FIXME [JBDEPLOY-245] Unexpected dependee state changes");
-         // assertBundleState(Bundle.INSTALLED, bundleX.getState());
+         assertBundleState(Bundle.INSTALLED, bundleX.getState());
 
          bundleB.start();
          assertBundleState(Bundle.RESOLVED, bundleX.getState());
@@ -206,9 +204,7 @@
          }
 
          OSGiBundle bundleX = runtime.installBundle("jbosgi38-bundleX.jar");
-         
-         System.out.println("FIXME [JBDEPLOY-245] Unexpected dependee state changes");
-         //assertBundleState(Bundle.INSTALLED, bundleX.getState());
+         assertBundleState(Bundle.INSTALLED, bundleX.getState());
 
          bundleB.start();
          assertBundleState(Bundle.RESOLVED, bundleX.getState());




More information about the jboss-cvs-commits mailing list