[jboss-cvs] JBossAS SVN: r95565 - in projects/jboss-osgi/trunk: reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 26 10:32:43 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-26 10:32:42 -0400 (Mon, 26 Oct 2009)
New Revision: 95565

Added:
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InvocationContextImpl.java
   projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/MockBundleContext.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/DeploymentUnitAttachments.java
Removed:
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorContextImpl.java
Modified:
   projects/jboss-osgi/trunk/pom.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/Attachments.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/AttachmentSupport.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorWrapper.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
   projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/InterceptorOrderTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF
Log:
Delegate interceptor attachments to DeploymentUnit

Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/pom.xml	2009-10-26 14:32:42 UTC (rev 95565)
@@ -71,7 +71,7 @@
     <version.jboss.osgi.webapp>0.7.2-SNAPSHOT</version.jboss.osgi.webapp>
     <version.jboss.osgi.webconsole>1.0.2</version.jboss.osgi.webconsole>
     <version.jboss.osgi.xml.binding>2.0.1.SP1</version.jboss.osgi.xml.binding>
-    <version.ops4j.pax.web>0.7.2-20091021.163357-3</version.ops4j.pax.web>
+    <version.ops4j.pax.web>0.7.2-SNAPSHOT</version.ops4j.pax.web>
     <version.osgi>4.2.0</version.osgi>
     
     <surefire.memory.args>-Xmx512m</surefire.memory.args>

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/Attachments.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/Attachments.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/Attachments.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -37,10 +37,10 @@
    Collection<Key> getAttachmentKeys();
 
    /** Add arbitrary attachment */
-   <T> T addAttachment(Class<T> clazz, Object value);
+   <T> T addAttachment(Class<T> clazz, T value);
 
    /** Add arbitrary attachment with name */
-   <T> T addAttachment(Class<T> clazz, String name, Object value);
+   <T> T addAttachment(String name, T value, Class<T> clazz);
 
    /** Add arbitrary attachment with name */
    Object addAttachment(String name, Object value);
@@ -49,7 +49,7 @@
    <T> T getAttachment(Class<T> clazz);
 
    /** Get an arbitrary attachment */
-   <T> T getAttachment(Class<T> clazz, String name);
+   <T> T getAttachment(String name, Class<T> clazz);
 
    /** Get an arbitrary attachment */
    Object getAttachment(String name);
@@ -74,7 +74,7 @@
       /**
        * Construct the key with optional class and name
        */
-      public Key(Class<?> clazz, String name)
+      public Key(String name, Class<?> clazz)
       {
          this.clazz = clazz;
          this.name = name;
@@ -99,7 +99,7 @@
                   throw new IllegalArgumentException("Cannot find class '" + className + "' in: " + key);
                }
             }
-            return new Key(classPart, namePart);
+            return new Key(namePart, classPart);
          }
          return null;
       }

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -30,14 +30,10 @@
 import java.util.List;
 import java.util.Set;
 
-import org.jboss.osgi.deployment.deployer.Deployment;
-import org.jboss.osgi.deployment.internal.InterceptorContextImpl;
 import org.jboss.osgi.deployment.internal.InterceptorWrapper;
 import org.jboss.osgi.spi.util.ConstantsHelper;
-import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -137,11 +133,13 @@
          }
          
          // Log the interceptor order
+         StringBuffer buffer = new StringBuffer();
          for (LifecycleInterceptor aux : sortedList)
          {
             InterceptorWrapper wrapper = new InterceptorWrapper(aux);
-            log.debug("\n  " + wrapper.toLongString());
+            buffer.append("\n  " + wrapper.toLongString());
          }
+         log.debug("Resulting interceptor chain" + buffer.toString());
          
          // Use the sorted result as the new interceptor chain
          interceptorChain.clear();
@@ -219,45 +217,43 @@
          if (interceptorChain.size() == 0)
             return;
          
-         String name = bundle.getSymbolicName();
-         Version version = bundle.getVersion();
-         Deployment dep = getDeployment(getSystemContext(), name, version);
-         if (dep == null)
-            throw new IllegalStateException("Cannot get deployment for: " + name + "-" + version);
+         InvocationContext inv = getInvocationContext(bundle);
+         if (inv == null)
+            throw new IllegalStateException("Cannot get invocation context for: " + bundle);
          
-         VirtualFile root = dep.getRoot();
-         InterceptorContextImpl intContext = new InterceptorContextImpl(context, bundle, root, dep);
-         
          // Call the interceptor chain
          for (LifecycleInterceptor aux : interceptorChain)
          {
             Set<Class<?>> input = aux.getInput();
+            
             boolean doInvocation = true;
             if (input != null)
             {
                // Check if all required input is available 
                for (Class<?> clazz : input)
                {
-                  if (dep.getAttachment(clazz) == null)
+                  if (inv.getAttachment(clazz) == null)
                   {
                      doInvocation = false;
                      break;
                   }
                }
             }
-            if (doInvocation)
+            
+            if (doInvocation == true)
             {
                InterceptorWrapper wrapper = new InterceptorWrapper(aux);
                String stateName = ConstantsHelper.bundleState(state);
-               log.trace("Invoke: " + wrapper + " with state " + stateName + " on " + dep.getLocation());
-               aux.invoke(state, intContext);
+               String location = inv.getBundle().getLocation();
+               log.trace("Invoke: " + wrapper + " with state " + stateName + " on " + location);
+               aux.invoke(state, inv);
             }
          }
       }
    }
 
    /**
-    * Get the deployment for the given bundle symbolic name and version 
+    * Get the InvocationContext for the given bundle. 
     */
-   protected abstract Deployment getDeployment(BundleContext context, String symbolicName, Version version);
+   protected abstract InvocationContext getInvocationContext(Bundle bundle);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/AttachmentSupport.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/AttachmentSupport.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/AttachmentSupport.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -58,52 +58,52 @@
    @SuppressWarnings("unchecked")
    public <T> T getAttachment(Class<T> clazz)
    {
-      return (T)attachments.get(new Key(clazz, null));
+      return (T)attachments.get(new Key(null, clazz));
    }
 
    @SuppressWarnings("unchecked")
-   public <T> T getAttachment(Class<T> clazz, String name)
+   public <T> T getAttachment(String name, Class<T> clazz)
    {
-      return (T)attachments.get(new Key(clazz, name));
+      return (T)attachments.get(new Key(name, clazz));
    }
 
    public Object getAttachment(String name)
    {
-      return attachments.get(new Key(null, name));
+      return attachments.get(new Key(name, null));
    }
 
    @SuppressWarnings("unchecked")
-   public <T> T addAttachment(Class<T> clazz, Object obj)
+   public <T> T addAttachment(Class<T> clazz, T obj)
    {
-      return (T)attachments.put(new Key(clazz, null), obj);
+      return (T)attachments.put(new Key(null, clazz), obj);
    }
 
    @SuppressWarnings("unchecked")
-   public <T> T addAttachment(Class<T> clazz, String name, Object obj)
+   public <T> T addAttachment(String name, T obj, Class<T> clazz)
    {
-      return (T)attachments.put(new Key(clazz, name), obj);
+      return (T)attachments.put(new Key(name, clazz), obj);
    }
 
    public Object addAttachment(String name, Object obj)
    {
-      return attachments.put(new Key(null, name), obj);
+      return attachments.put(new Key(name, null), obj);
    }
 
    @SuppressWarnings("unchecked")
    public <T> T removeAttachment(Class<T> clazz)
    {
-      return (T)attachments.remove(new Key(clazz, null));
+      return (T)attachments.remove(new Key(null, clazz));
    }
 
    @SuppressWarnings("unchecked")
    public <T> T removeAttachment(Class<T> clazz, String name)
    {
-      return (T)attachments.remove(new Key(clazz, name));
+      return (T)attachments.remove(new Key(name, clazz));
    }
 
    public Object removeAttachment(String name)
    {
-      return attachments.remove(new Key(null, name));
+      return attachments.remove(new Key(name, null));
    }
 
    public String toString()

Deleted: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorContextImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorContextImpl.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorContextImpl.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -1,126 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.deployment.internal;
-
-//$Id$
-
-import java.util.Collection;
-
-import org.jboss.osgi.deployment.deployer.Attachments;
-import org.jboss.osgi.deployment.interceptor.InvocationContext;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-
-/**
- * The context passed between Interceptors
- * 
- * @author thomas.diesler at jboss.com
- * @since 27-May-2009
- */
-public class InterceptorContextImpl implements InvocationContext
-{
-   private Attachments attachments;
-   private BundleContext systemContext;
-   private VirtualFile root;
-   private Bundle bundle;
-   
-   public InterceptorContextImpl(BundleContext systemContext, Bundle bundle, VirtualFile root, Attachments attachments)
-   {
-      if (systemContext == null)
-         throw new IllegalArgumentException("Null system context");
-      if (bundle == null)
-         throw new IllegalArgumentException("Null bundle");
-      if (root == null)
-         throw new IllegalArgumentException("Null root file");
-
-      this.systemContext = systemContext;
-      this.root = root;
-      this.bundle = bundle;
-      this.attachments = attachments;
-   }
-
-   public BundleContext getSystemContext()
-   {
-      return systemContext;
-   }
-
-   public Bundle getBundle()
-   {
-      return bundle;
-   }
-
-   public VirtualFile getRoot()
-   {
-      return root;
-   }
-
-   public <T> T addAttachment(Class<T> clazz, Object value)
-   {
-      return attachments.addAttachment(clazz, value);
-   }
-
-   public <T> T addAttachment(Class<T> clazz, String name, Object value)
-   {
-      return attachments.addAttachment(clazz, name, value);
-   }
-
-   public Object addAttachment(String name, Object value)
-   {
-      return attachments.addAttachment(name, value);
-   }
-
-   public <T> T getAttachment(Class<T> clazz, String name)
-   {
-      return attachments.getAttachment(clazz, name);
-   }
-
-   public <T> T getAttachment(Class<T> clazz)
-   {
-      return attachments.getAttachment(clazz);
-   }
-
-   public Object getAttachment(String name)
-   {
-      return attachments.getAttachment(name);
-   }
-
-   public Collection<Key> getAttachmentKeys()
-   {
-      return attachments.getAttachmentKeys();
-   }
-
-   public <T> T removeAttachment(Class<T> clazz, String name)
-   {
-      return attachments.removeAttachment(clazz, name);
-   }
-
-   public <T> T removeAttachment(Class<T> clazz)
-   {
-      return attachments.removeAttachment(clazz);
-   }
-
-   public Object removeAttachment(String name)
-   {
-      return attachments.removeAttachment(name);
-   }
-}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorWrapper.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorWrapper.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorWrapper.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -77,7 +77,7 @@
       {
          input = new HashSet<String>();
          for(Class<?> aux : getInput())
-            input.add(getLastNameToken(aux.getClass()));
+            input.add(getLastNameToken(aux));
       }
       
       Set<String> output = null; 
@@ -85,7 +85,7 @@
       {
          output = new HashSet<String>();
          for(Class<?> aux : getOutput())
-            output.add(getLastNameToken(aux.getClass()));
+            output.add(getLastNameToken(aux));
       }
       
       return "[" + classToken + ",order=" + getRelativeOrder() + ",input=" + input + ",output=" + output + "]";

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InvocationContextImpl.java (from rev 95556, projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InterceptorContextImpl.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InvocationContextImpl.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/InvocationContextImpl.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployment.internal;
+
+//$Id$
+
+import java.util.Collection;
+
+import org.jboss.osgi.deployment.deployer.Attachments;
+import org.jboss.osgi.deployment.interceptor.InvocationContext;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The context passed between Interceptors
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class InvocationContextImpl implements InvocationContext
+{
+   private Attachments attachments;
+   private BundleContext systemContext;
+   private VirtualFile root;
+   private Bundle bundle;
+   
+   public InvocationContextImpl(BundleContext systemContext, Bundle bundle, VirtualFile root, Attachments attachments)
+   {
+      if (systemContext == null)
+         throw new IllegalArgumentException("Null system context");
+      if (bundle == null)
+         throw new IllegalArgumentException("Null bundle");
+      if (root == null)
+         throw new IllegalArgumentException("Null root file");
+      if (attachments == null)
+         throw new IllegalArgumentException("Null attachments");
+
+      this.systemContext = systemContext;
+      this.root = root;
+      this.bundle = bundle;
+      this.attachments = attachments;
+   }
+
+   public BundleContext getSystemContext()
+   {
+      return systemContext;
+   }
+
+   public Bundle getBundle()
+   {
+      return bundle;
+   }
+
+   public VirtualFile getRoot()
+   {
+      return root;
+   }
+
+   public <T> T addAttachment(Class<T> clazz, T value)
+   {
+      return attachments.addAttachment(clazz, value);
+   }
+
+   public <T> T addAttachment(String name, T value, Class<T> clazz)
+   {
+      return attachments.addAttachment(name, value, clazz);
+   }
+
+   public Object addAttachment(String name, Object value)
+   {
+      return attachments.addAttachment(name, value);
+   }
+
+   public <T> T getAttachment(String name, Class<T> clazz)
+   {
+      return attachments.getAttachment(name, clazz);
+   }
+
+   public <T> T getAttachment(Class<T> clazz)
+   {
+      return attachments.getAttachment(clazz);
+   }
+
+   public Object getAttachment(String name)
+   {
+      return attachments.getAttachment(name);
+   }
+
+   public Collection<Key> getAttachmentKeys()
+   {
+      return attachments.getAttachmentKeys();
+   }
+
+   public <T> T removeAttachment(Class<T> clazz, String name)
+   {
+      return attachments.removeAttachment(clazz, name);
+   }
+
+   public <T> T removeAttachment(Class<T> clazz)
+   {
+      return attachments.removeAttachment(clazz);
+   }
+
+   public Object removeAttachment(String name)
+   {
+      return attachments.removeAttachment(name);
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -28,10 +28,11 @@
 import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
 import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptorService;
+import org.jboss.osgi.deployment.interceptor.InvocationContext;
 import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
 
 /**
  * A basic service that manages bundle lifecycle interceptors.
@@ -53,14 +54,18 @@
    }
 
    @Override
-   protected Deployment getDeployment(BundleContext context, String symbolicName, Version version)
+   protected InvocationContext getInvocationContext(Bundle bundle)
    {
-      DeploymentRegistryService service = getDeploymentRegistryService(context);
-      return service.getDeployment(symbolicName, version);
+      DeploymentRegistryService service = getDeploymentRegistryService();
+      Deployment dep = service.getDeployment(bundle.getSymbolicName(), bundle.getVersion());
+      if (dep == null)
+         throw new IllegalStateException("Cannot get deployment for: " + bundle);
+      return new InvocationContextImpl(getSystemContext(), bundle, dep.getRoot(), dep);
    }
 
-   private DeploymentRegistryService getDeploymentRegistryService(BundleContext context)
+   private DeploymentRegistryService getDeploymentRegistryService()
    {
+      BundleContext context = getSystemContext();
       ServiceReference sref = context.getServiceReference(DeploymentRegistryService.class.getName());
       if (sref == null)
          throw new IllegalStateException("Cannot obtain deployment registry service");

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/InterceptorOrderTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/InterceptorOrderTestCase.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/InterceptorOrderTestCase.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -59,7 +59,7 @@
       };
 
       // Add ordered
-      LifecycleInterceptorServiceImpl service = new LifecycleInterceptorServiceImpl(null);
+      LifecycleInterceptorServiceImpl service = new LifecycleInterceptorServiceImpl(new MockBundleContext());
       service.addInterceptor(rel0000);
       service.addInterceptor(rel2000);
 
@@ -69,7 +69,7 @@
       assertEquals(RELATIVE_ORDER, chain.get(1).getRelativeOrder());
 
       // Add unordered
-      service = new LifecycleInterceptorServiceImpl(null);
+      service = new LifecycleInterceptorServiceImpl(new MockBundleContext());
       service.addInterceptor(rel2000);
       service.addInterceptor(rel0000);
 
@@ -93,7 +93,7 @@
       outA.addOutput(A.class);
 
       // Add ordered
-      LifecycleInterceptorServiceImpl service = new LifecycleInterceptorServiceImpl(null);
+      LifecycleInterceptorServiceImpl service = new LifecycleInterceptorServiceImpl(new MockBundleContext());
       service.addInterceptor(outA);
       service.addInterceptor(inA);
 
@@ -103,7 +103,7 @@
       assertEquals(inA, chain.get(1));
 
       // Add unordered
-      service = new LifecycleInterceptorServiceImpl(null);
+      service = new LifecycleInterceptorServiceImpl(new MockBundleContext());
       service.addInterceptor(inA);
       service.addInterceptor(outA);
 

Added: projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/MockBundleContext.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/MockBundleContext.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/MockBundleContext.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.deployment.interceptor;
+
+//$Id$
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * A mock bundle context
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 26-Oct-2009
+ */
+class MockBundleContext implements BundleContext
+{
+   public void addBundleListener(BundleListener listener)
+   {
+   }
+
+   public void addFrameworkListener(FrameworkListener listener)
+   {
+   }
+
+   public void addServiceListener(ServiceListener listener)
+   {
+   }
+
+   public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
+   {
+   }
+
+   public Filter createFilter(String filter) throws InvalidSyntaxException
+   {
+      return null;
+   }
+
+   public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+   {
+      return null;
+   }
+
+   public Bundle getBundle()
+   {
+      return null;
+   }
+
+   public Bundle getBundle(long id)
+   {
+      return null;
+   }
+
+   public Bundle[] getBundles()
+   {
+      return null;
+   }
+
+   public File getDataFile(String filename)
+   {
+      return null;
+   }
+
+   public String getProperty(String key)
+   {
+      return null;
+   }
+
+   public Object getService(ServiceReference reference)
+   {
+      return null;
+   }
+
+   public ServiceReference getServiceReference(String clazz)
+   {
+      return null;
+   }
+
+   public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+   {
+      return null;
+   }
+
+   public Bundle installBundle(String location) throws BundleException
+   {
+      return null;
+   }
+
+   public Bundle installBundle(String location, InputStream input) throws BundleException
+   {
+      return null;
+   }
+
+   @SuppressWarnings("unchecked")
+   public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
+   {
+      return null;
+   }
+
+   @SuppressWarnings("unchecked")
+   public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
+   {
+      return null;
+   }
+
+   public void removeBundleListener(BundleListener listener)
+   {
+   }
+
+   public void removeFrameworkListener(FrameworkListener listener)
+   {
+   }
+
+   public void removeServiceListener(ServiceListener listener)
+   {
+   }
+
+   public boolean ungetService(ServiceReference reference)
+   {
+      return false;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/MockBundleContext.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -28,20 +28,19 @@
 
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.logging.Logger;
-import org.jboss.osgi.deployment.deployer.DeployerService;
-import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptorService;
+import org.jboss.osgi.deployment.interceptor.InvocationContext;
 import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
 import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
+import org.jboss.osgi.deployment.internal.InvocationContextImpl;
 import org.jboss.osgi.framework.bundle.OSGiBundleManager;
 import org.jboss.osgi.framework.bundle.OSGiBundleState;
 import org.jboss.osgi.framework.plugins.LifecycleInterceptorServicePlugin;
 import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
+import org.jboss.osgi.framework.util.DeploymentUnitAttachments;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.Version;
 
 /**
  * A plugin that manages bundle lifecycle interceptors.
@@ -68,22 +67,24 @@
       BundleContext context = getSystemContext();
       delegate = new AbstractLifecycleInterceptorService(context)
       {
-         protected Deployment getDeployment(BundleContext context, String name, Version version)
+         @Override
+         protected InvocationContext getInvocationContext(Bundle bundle)
          {
-            OSGiBundleState bundle = (OSGiBundleState)bundleManager.getBundle(name, version);
+            long bundleId = bundle.getBundleId();
+            OSGiBundleState bundleState = (OSGiBundleState)bundleManager.getBundleById(bundleId);
             if (bundle == null)
-               throw new IllegalStateException("Cannot obtain bundle for: " + name + "-" + version);
+               throw new IllegalStateException("Cannot obtain bundle for: " + bundle);
 
-            VFSDeploymentUnit unit = (VFSDeploymentUnit)bundle.getDeploymentUnit();
-            Deployment dep = unit.getAttachment(Deployment.class);
-            if (dep == null)
+            VFSDeploymentUnit unit = (VFSDeploymentUnit)bundleState.getDeploymentUnit();
+            InvocationContext inv = unit.getAttachment(InvocationContext.class);
+            if (inv == null)
             {
-               ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
-               DeployerService service = (DeployerService)context.getService(sref);
-               dep = service.createDeployment(unit.getRoot());
-               unit.addAttachment(Deployment.class, dep);
+               BundleContext context = bundleState.getBundleManager().getSystemContext();
+               DeploymentUnitAttachments att = new DeploymentUnitAttachments(unit);
+               inv = new InvocationContextImpl(context, bundle, unit.getRoot(), att);
+               unit.addAttachment(InvocationContext.class, inv);
             }
-            return dep;
+            return inv;
          }
       };
       

Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/DeploymentUnitAttachments.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/DeploymentUnitAttachments.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/DeploymentUnitAttachments.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -0,0 +1,107 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.deployment.deployer.Attachments;
+
+/**
+ * An implementation of {@link Attachments} that delegates to a 
+ * {@link DeploymentUnit}.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 26-Oct-2009
+ */
+public class DeploymentUnitAttachments implements Attachments
+{
+   private DeploymentUnit delegate;
+   
+   public DeploymentUnitAttachments(DeploymentUnit unit)
+   {
+      if (unit == null)
+         throw new IllegalArgumentException("Null unit");
+      this.delegate = unit;
+   }
+
+   public <T> T addAttachment(Class<T> clazz, T value)
+   {
+      return delegate.addAttachment(clazz, value);
+   }
+
+   public <T> T addAttachment(String name, T value, Class<T> clazz)
+   {
+      return delegate.addAttachment(name, value, clazz);
+   }
+
+   public Object addAttachment(String name, Object value)
+   {
+      return delegate.addAttachment(name, value);
+   }
+
+   public <T> T getAttachment(String name, Class<T> clazz)
+   {
+      return delegate.getAttachment(name, clazz);
+   }
+
+   public <T> T getAttachment(Class<T> clazz)
+   {
+      return delegate.getAttachment(clazz);
+   }
+
+   public Object getAttachment(String name)
+   {
+      return delegate.getAttachment(name);
+   }
+
+   public Collection<Key> getAttachmentKeys()
+   {
+      List<Key> keys = new ArrayList<Key>();
+      Set<String> keySet = delegate.getAttachments().keySet();
+      for(String key : keySet)
+      {
+         keys.add(new Key(key, null));
+      }
+      return Collections.unmodifiableList(keys);
+   }
+
+   public <T> T removeAttachment(Class<T> clazz, String name)
+   {
+      return delegate.removeAttachment(name, clazz);
+   }
+
+   public <T> T removeAttachment(Class<T> clazz)
+   {
+      return delegate.removeAttachment(clazz);
+   }
+
+   public Object removeAttachment(String name)
+   {
+      return delegate.removeAttachment(name);
+   } 
+
+}


Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/DeploymentUnitAttachments.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java	2009-10-26 14:32:42 UTC (rev 95565)
@@ -39,7 +39,7 @@
 {
    protected String getHttpResponse(String reqPath) throws Exception
    {
-      URL url = new URL("http://" + getServerHost() + ":8090/webapp" + reqPath);
+      URL url = new URL("http://" + getServerHost() + ":8090/example-webapp" + reqPath);
       BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
       return br.readLine();
    }

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF	2009-10-26 14:30:20 UTC (rev 95564)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF	2009-10-26 14:32:42 UTC (rev 95565)
@@ -3,5 +3,4 @@
 Bundle-ManifestVersion: 2
 Bundle-SymbolicName: example-webapp
 Bundle-ClassPath: .,WEB-INF/classes
-Import-Package: javax.servlet,javax.servlet.http,org.osgi.service.http,org.ops4j.pax.web.service
-Webapp-Context: webapp
+Import-Package: javax.servlet,javax.servlet.http,org.osgi.service.http,org.ops4j.pax.web.service
\ No newline at end of file




More information about the jboss-cvs-commits mailing list