[jboss-cvs] JBossAS SVN: r100422 - in projects/jboss-osgi/projects/runtime/framework/trunk: src/main/java/org/jboss/osgi/framework/bundle and 14 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 4 11:09:53 EST 2010


Author: alesj
Date: 2010-02-04 11:09:52 -0500 (Thu, 04 Feb 2010)
New Revision: 100422

Added:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServicesTest.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JBossJMXKernel.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JMXKernel.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvoker.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvokerMBean.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/macosx_x86/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/macosx_x86/libNative.jnilib
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/windows_x86/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/windows_x86/Native.dll
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase#testAtJmx.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase.xml
Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/nativecode/bundleA/NativeCodeActivatorA.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/simple-nativecode.bnd
Log:
[JBOSGI-141]; fix MDRFactory, fix native tests for non-linux env; mac, winz.

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml	2010-02-04 15:58:02 UTC (rev 100421)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml	2010-02-04 16:09:52 UTC (rev 100422)
@@ -49,7 +49,7 @@
     <version.drools>5.0.1</version.drools>
     <version.jboss.classloading>2.2.0.Alpha1</version.jboss.classloading>
     <version.jboss.deployers>2.2.0.Alpha1</version.jboss.deployers>
-    <version.jboss.kernel>2.2.0.Alpha2</version.jboss.kernel>
+    <version.jboss.kernel>2.2.0.Alpha5</version.jboss.kernel>
     <version.jboss.logging>2.1.0.GA</version.jboss.logging>
     <version.jboss.mdr>2.2.0.Alpha1</version.jboss.mdr>
     <version.jboss.osgi.apache.xerces>2.9.1.SP3</version.jboss.osgi.apache.xerces>
@@ -134,12 +134,27 @@
       <version>${version.jboss.deployers}</version>
     </dependency>
     <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-jmx</artifactId>
+      <version>${version.jboss.deployers}</version>
+    </dependency>
+    <dependency>
       <groupId>org.jboss.kernel</groupId>
       <artifactId>jboss-kernel</artifactId>
       <version>${version.jboss.kernel}</version>
     </dependency>
     <dependency>
       <groupId>org.jboss.kernel</groupId>
+      <artifactId>jboss-jmx-aop-mc-int</artifactId>
+      <version>${version.jboss.kernel}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.kernel</groupId>
+      <artifactId>jboss-jmx-mc-int</artifactId>
+      <version>${version.jboss.kernel}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.kernel</groupId>
       <artifactId>jboss-dependency</artifactId>
       <version>${version.jboss.kernel}</version>
     </dependency>

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java	2010-02-04 15:58:02 UTC (rev 100421)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -27,7 +27,9 @@
 
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.Kernel;
 import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
 import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
 import org.jboss.metadata.spi.retrieval.MetaDataRetrievalFactory;
 import org.jboss.metadata.spi.scope.CommonLevels;
@@ -42,15 +44,18 @@
 public class InstanceMetaDataRetrievalFactory implements MetaDataRetrievalFactory
 {
    private Controller controller;
+   private MutableMetaDataRepository repository;
    
    @SuppressWarnings("rawtypes")
    private Set<DictionaryFactory> factories = new CopyOnWriteArraySet<DictionaryFactory>();
 
-   public InstanceMetaDataRetrievalFactory(Controller controller)
+   public InstanceMetaDataRetrievalFactory(Kernel kernel)
    {
-      if (controller == null)
-         throw new IllegalArgumentException("Null controller");
-      this.controller = controller;
+      if (kernel == null)
+         throw new IllegalArgumentException("Null kernel");
+
+      this.controller = kernel.getController();
+      this.repository = kernel.getMetaDataRepository().getMetaDataRepository();
    }
 
    @SuppressWarnings({"unchecked", "rawtypes"})
@@ -62,6 +67,8 @@
          throw new IllegalArgumentException("Not an instance scope: " + scope);
 
       MemoryMetaDataLoader loader = new MemoryMetaDataLoader(new ScopeKey(scope));
+      repository.addMetaDataRetrieval(loader); // remember loader
+
       Object qualifier = scope.getQualifier();
       ControllerContext context = controller.getContext(qualifier, null);
       if (context != null)

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java	2010-02-04 15:58:02 UTC (rev 100421)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -313,8 +313,7 @@
    private MetaDataRetrievalFactory getMetaDataRetrievalFactory()
    {
       MetaDataRetrievalFactory mdrFactory;
-      Controller controller = kernel.getController();
-      InstanceMetaDataRetrievalFactory imdrf = new InstanceMetaDataRetrievalFactory(controller);
+      InstanceMetaDataRetrievalFactory imdrf = new InstanceMetaDataRetrievalFactory(kernel);
       imdrf.addFactory(new OSGiServiceStateDictionaryFactory());
       imdrf.addFactory(new KernelDictionaryFactory(kernel.getConfigurator()));
       // TODO - JMX?

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java	2010-02-04 15:58:02 UTC (rev 100421)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -101,6 +101,7 @@
       osAlias.put("WinVista", "WindowsVista");
       osAlias.put("Windows Vista", "WindowsVista");
       osAlias.put("Win32", "WindowsVista");
+      osAlias.put("Windows 7", "Windows7");
    }
 
    public OSGiNativeCodeMetaDataDeployer()
@@ -226,7 +227,7 @@
          boolean osmatch = false;
          for (String osname : osNames)
          {
-            osmatch = (osname.equals(fwOSName) || osname.equals(osAlias.get(fwOSName)));
+            osmatch = (osname.equalsIgnoreCase(fwOSName) || osname.equalsIgnoreCase(osAlias.get(fwOSName)));
             if (osmatch == true)
                break;
          }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/nativecode/bundleA/NativeCodeActivatorA.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/nativecode/bundleA/NativeCodeActivatorA.java	2010-02-04 15:58:02 UTC (rev 100421)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/nativecode/bundleA/NativeCodeActivatorA.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -28,8 +28,49 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 
+import java.util.HashMap;
+import java.util.Map;
+
 public class NativeCodeActivatorA implements BundleActivator
 {
+   private static Map<String, String> osAliases = new HashMap<String, String>();
+
+   static
+   {
+      osAliases.put("SymbianOS", "Epoc32");
+      osAliases.put("hp-ux", "HPUX");
+      osAliases.put("Linux", "Linux");
+      osAliases.put("Mac OS", "MacOS");
+      osAliases.put("Mac OS X", "MacOSX");
+      osAliases.put("OS/2", "OS2");
+      osAliases.put("procnto", "QNX");
+      osAliases.put("Win95", "Windows95");
+      osAliases.put("Windows 95", "Windows95");
+      osAliases.put("Win32", "Windows95");
+      osAliases.put("Win98", "Windows98");
+      osAliases.put("Windows 98", "Windows98");
+      osAliases.put("Win32", "Windows98");
+      osAliases.put("WinNT", "WindowsNT");
+      osAliases.put("Windows NT", "WindowsNT");
+      osAliases.put("Win32", "WindowsNT");
+      osAliases.put("WinCE", "WindowsCE");
+      osAliases.put("Windows CE", "WindowsCE");
+      osAliases.put("Win2000", "Windows2000");
+      osAliases.put("Windows 2000", "Windows2000");
+      osAliases.put("Win32", "Windows2000");
+      osAliases.put("Win2003", "Windows2003");
+      osAliases.put("Windows 2003", "Windows2003");
+      osAliases.put("Win32", "Windows2003");
+      osAliases.put("Windows Server 2003", "Windows2003");
+      osAliases.put("WinXP", "WindowsXP");
+      osAliases.put("Windows XP", "WindowsXP");
+      osAliases.put("Win32", "WindowsXP");
+      osAliases.put("WinVista", "WindowsVista");
+      osAliases.put("Windows Vista", "WindowsVista");
+      osAliases.put("Win32", "WindowsVista");
+      osAliases.put("Windows 7", "Windows7");
+   }
+
    public void start(BundleContext context) throws BundleException
    {
       Bundle bundle = context.getBundle();
@@ -42,7 +83,13 @@
       {
          String exmsg = ex.getMessage();
          long bundleid = bundle.getBundleId();
-         String substr = "osgi-store/bundle-" + bundleid + "/linux_x86";
+         String os = System.getProperty("os.name");
+         String osAlias = osAliases.get(os);
+         String suffix = osAlias != null ? osAlias.toLowerCase() : "";
+         if ("".equals(suffix))
+            System.err.println("No such OS mapped to alias: " + os);
+
+         String substr = "osgi-store/bundle-" + bundleid + "/" + suffix;
          if (exmsg.indexOf(substr) < 0)
             throw new UnsatisfiedLinkError("Cannot find '" + substr + "' in '" + exmsg + "'");
       }

Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java (from rev 100347, projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.osgi.service;
+
+import junit.framework.Test;
+import org.jboss.test.osgi.service.support.MockInvokerMBean;
+
+import javax.management.ObjectName;
+
+/**
+ * Test MC's jmx support.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JMXServicesUnitTestCase extends ServicesTest
+{
+   public JMXServicesUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(JMXServicesUnitTestCase.class);
+   }
+
+   public void testAtJmx() throws Throwable
+   {
+      MockInvokerMBean invoker = (MockInvokerMBean) getBean("Invoker");
+      assertNotNull(invoker.getServer());
+      ObjectName name = invoker.getServiceName();
+      assertNotNull(name);
+      assertEquals("jboss:service=invoker,type=unified", name.getCanonicalName());
+   }
+
+   public void testMBeans() throws Throwable
+   {
+      // mix mbean services with bundles -- TODO
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java	2010-02-04 15:58:02 UTC (rev 100421)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -49,7 +49,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
-public class ServiceMixUnitTestCase extends DeployersTest
+public class ServiceMixUnitTestCase extends ServicesTest
 {
    public ServiceMixUnitTestCase(String name)
    {
@@ -107,23 +107,6 @@
       }
    }
 
-   private static Object getter(Object target, String getter, String name) throws Throwable
-   {
-      assertNotNull("Target " + name + " is not null", target);
-      Class<?> clazz = target.getClass();
-      Method m = clazz.getDeclaredMethod(getter);
-      return m.invoke(target);
-   }
-
-   private static Object setter(Object target, String setter, Object value, String name) throws Throwable
-   {
-      assertNotNull("Target " + name + " is not null", target);
-      assertNotNull("Value is not null", value);
-      Class<?> clazz = target.getClass();
-      Method m = clazz.getDeclaredMethod(setter, value.getClass());
-      return m.invoke(target, value);
-   }
-
    public void testInjectionToMC() throws Throwable
    {
       BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("C", C.class.getName());

Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServicesTest.java (from rev 100347, projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServicesTest.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServicesTest.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.osgi.service;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.osgi.DeployersTest;
+import org.jboss.test.osgi.service.support.LazyBundle;
+import org.jboss.test.osgi.service.support.a.A;
+import org.jboss.test.osgi.service.support.c.C;
+import org.jboss.test.osgi.service.support.d.D;
+import org.jboss.virtual.AssembledDirectory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+import java.lang.reflect.Method;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+/**
+ * Test MC's services.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class ServicesTest extends DeployersTest
+{
+   public ServicesTest(String name)
+   {
+      super(name);
+   }
+
+   protected static Object getter(Object target, String getter, String name) throws Throwable
+   {
+      assertNotNull("Target " + name + " is not null", target);
+      Class<?> clazz = target.getClass();
+      Method m = clazz.getDeclaredMethod(getter);
+      return m.invoke(target);
+   }
+
+   protected static Object setter(Object target, String setter, Object value, String name) throws Throwable
+   {
+      assertNotNull("Target " + name + " is not null", target);
+      assertNotNull("Value is not null", value);
+      Class<?> clazz = target.getClass();
+      Method m = clazz.getDeclaredMethod(setter, value.getClass());
+      return m.invoke(target, value);
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JBossJMXKernel.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JBossJMXKernel.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JBossJMXKernel.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.test.osgi.service.support;
+
+import org.jboss.beans.metadata.api.annotations.Constructor;
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+
+/**
+ * Sets up MBeanServer impl.
+ *
+ * JDK = org.jboss.jmx.mbeanserver.JBossMBeanServerBuilder
+ * JBossMX = org.jboss.mx.server.MBeanServerBuilderImpl
+ *
+ * by default we use JDK's.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JBossJMXKernel extends JMXKernel
+{
+   private static final String MBEAN_SERVER_BUILDER_CLASS_PROPERTY = "javax.management.builder.initial";
+   private static final String DEFAULT_MBEAN_SERVER_BUILDER_CLASS = "org.jboss.jmx.mbeanserver.JBossMBeanServerBuilder";
+   private String builderClass;
+
+   @Constructor
+   public JBossJMXKernel(@Inject(bean = KernelConstants.KERNEL_NAME) Kernel kernel, @Inject ClassLoaderSystem system)
+   {
+      super(kernel, system);
+   }
+
+   protected void addProperties()
+   {
+      super.addProperties();
+      if (builderClass == null)
+         builderClass = DEFAULT_MBEAN_SERVER_BUILDER_CLASS;
+      System.setProperty(MBEAN_SERVER_BUILDER_CLASS_PROPERTY, builderClass);
+   }
+
+   protected void removeProperties()
+   {
+      System.clearProperty(MBEAN_SERVER_BUILDER_CLASS_PROPERTY);
+      super.removeProperties();
+   }
+
+   public void setBuilderClass(String builderClass)
+   {
+      this.builderClass = builderClass;
+   }
+}

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JMXKernel.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JMXKernel.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/JMXKernel.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,119 @@
+package org.jboss.test.osgi.service.support;
+
+import java.util.Properties;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.beans.metadata.api.annotations.Constructor;
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+import org.jboss.system.ServiceController;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JMXKernel
+{
+   private static final ObjectName CLASSLOADER_SYSTEM_OBJECT_NAME;
+
+   private Kernel kernel;
+   private ClassLoaderSystem system;
+
+   private Properties properties;
+   private MBeanServer mbeanServer;
+   private boolean createdMBeanServer;
+   private ServiceController serviceController;
+
+   static
+   {
+      try
+      {
+         CLASSLOADER_SYSTEM_OBJECT_NAME = new ObjectName("jboss.classloader:service=ClassLoaderSystem");
+      }
+      catch (MalformedObjectNameException e)
+      {
+         throw new RuntimeException("Unexpected error", e);
+      }
+   }
+
+   @Constructor
+   public JMXKernel(@Inject(bean = KernelConstants.KERNEL_NAME) Kernel kernel, @Inject ClassLoaderSystem system)
+   {
+      this.kernel = kernel;
+      this.system = system;
+   }
+
+   protected void addProperties()
+   {
+      if (properties != null)
+         System.setProperties(properties);
+   }
+
+   protected void removeProperties()
+   {
+      if (properties != null)
+      {
+         for (Object key : properties.keySet())
+            System.clearProperty(key.toString());
+      }
+   }
+
+   public void create()
+   {
+      addProperties();
+
+      if (mbeanServer == null)
+      {
+         mbeanServer = MBeanServerFactory.createMBeanServer("jboss");
+         createdMBeanServer = true;
+      }
+   }
+
+   public void start() throws Throwable
+   {
+      mbeanServer.registerMBean(system, CLASSLOADER_SYSTEM_OBJECT_NAME);
+
+      serviceController = new ServiceController();
+      serviceController.setKernel(kernel);
+      serviceController.setMBeanServer(mbeanServer);
+   }
+
+   public void stop() throws Throwable
+   {
+      serviceController.shutdown();
+
+      mbeanServer.unregisterMBean(CLASSLOADER_SYSTEM_OBJECT_NAME);
+   }
+
+   public void destroy()
+   {
+      if (createdMBeanServer)
+         MBeanServerFactory.releaseMBeanServer(mbeanServer);
+
+      removeProperties();
+   }
+
+   public void setProperties(Properties properties)
+   {
+      this.properties = properties;
+   }
+
+   public void setMbeanServer(MBeanServer mbeanServer)
+   {
+      this.mbeanServer = mbeanServer;
+   }
+
+   public ServiceController getServiceController()
+   {
+      return serviceController;
+   }
+
+   public MBeanServer getMbeanServer()
+   {
+      return mbeanServer;
+   }
+}

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvoker.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvoker.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvoker.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.test.osgi.service.support;
+
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * Test @JMX usage.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MockInvoker implements MockInvokerMBean, MBeanRegistration
+{
+   private MBeanServer server;
+   private ObjectName serviceName;
+
+   public MBeanServer getServer()
+   {
+      return server;
+   }
+
+   public ObjectName getServiceName()
+   {
+      return serviceName;
+   }
+
+   public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
+   {
+      this.server = server;
+      this.serviceName = name;
+      return null;
+   }
+
+   public void postRegister(Boolean registrationDone)
+   {
+   }
+
+   public void preDeregister() throws Exception
+   {
+   }
+
+   public void postDeregister()
+   {
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvokerMBean.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvokerMBean.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/MockInvokerMBean.java	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.test.osgi.service.support;
+
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * Test @JMX usage.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface MockInvokerMBean
+{
+   MBeanServer getServer();
+
+   ObjectName getServiceName();
+}
\ No newline at end of file

Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/macosx_x86/libNative.jnilib (from rev 100347, projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/linux_x86-64/libNative.so)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/macosx_x86/libNative.jnilib	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/macosx_x86/libNative.jnilib	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1 @@
+This is not really a native code library. We dont test linking. Instead we test that the file was extracted correctly.
\ No newline at end of file

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/windows_x86/Native.dll
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/windows_x86/Native.dll	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/libs/windows_x86/Native.dll	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1 @@
+This is not really a native code library. We dont test linking. Instead we test that the file was extracted correctly.
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/simple-nativecode.bnd
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/simple-nativecode.bnd	2010-02-04 15:58:02 UTC (rev 100421)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/nativecode/simple-nativecode.bnd	2010-02-04 16:09:52 UTC (rev 100422)
@@ -3,7 +3,11 @@
 Private-Package: org.jboss.test.osgi.nativecode.bundleA
 Bundle-NativeCode: \
  linux_x86/libNative.so; osname=Linux; processor=x86, \
- linux_x86-64/libNative.so; osname=Linux; processor=x86-64
+ linux_x86-64/libNative.so; osname=Linux; processor=x86-64, \
+ macosx_x86/libNative.jnilib; osname="mac os x"; processor=x86_64, \
+ macosx_x86/libNative.jnilib; osname="mac os x"; processor=ppc, \
+ windows_x86/Native.dll; osname=Win32; processor=x86, \
+ windows_x86/Native.dll; osname=Windows7; processor=amd86
 Include-Resource: libs
 
 -removeheaders: Include-Resource

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase#testAtJmx.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase#testAtJmx.xml	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase#testAtJmx.xml	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+    <bean name="Invoker" class="org.jboss.test.osgi.service.support.MockInvoker">
+        <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss:service=invoker,type=unified",exposedInterface=org.jboss.test.osgi.service.support.MockInvokerMBean.class,registerDirectly=true)</annotation>
+    </bean>
+
+</deployment>
\ No newline at end of file

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase.xml	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/org/jboss/test/osgi/service/JMXServicesUnitTestCase.xml	2010-02-04 16:09:52 UTC (rev 100422)
@@ -0,0 +1,51 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+    <!-- JMX Deployment -->
+
+    <bean name="JMXKernel" class="org.jboss.test.osgi.service.support.JBossJMXKernel"/>
+
+    <bean name="ServiceMetaDataICF" class="org.jboss.system.deployers.managed.ServiceMetaDataICF">
+       <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
+    </bean>
+    <bean name="SARDeployer" class="org.jboss.system.deployers.SARDeployer"/>
+    <bean name="ServiceClassLoaderDeployer" class="org.jboss.system.deployers.ServiceClassLoaderDeployer"/>
+    <bean name="ServiceDeploymentDeployer" class="org.jboss.system.deployers.ServiceDeploymentDeployer"/>
+    <bean name="ServiceDeployer" class="org.jboss.system.deployers.ServiceDeployer">
+        <constructor><parameter><inject bean="JMXKernel" property="serviceController"/></parameter></constructor>
+    </bean>
+
+    <!-- Intercept all annotation plugings -->
+
+    <bean name="BeanAnnotationAdapterFactory" class="org.jboss.kernel.plugins.annotations.BeanAnnotationAdapterFactory">
+       <constructor factoryMethod="getInstance"/>
+    </bean>
+
+   <bean name="BeanAnnotationAdapter">
+      <constructor factoryMethod="getBeanAnnotationAdapter">
+         <factory bean="BeanAnnotationAdapterFactory"/>
+      </constructor>
+      <incallback method="addAnnotationPlugin"/>
+      <uncallback method="removeAnnotationPlugin"/>
+   </bean>
+
+   <!-- Support for @JMX -->
+   <lifecycle-configure xmlns="urn:jboss:aop-beans:1.0"
+               name="JMXRegistrationAdvice"
+               class="org.jboss.system.microcontainer.jmx.ServiceControllerRegistrationLifecycleCallback"
+               classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX">
+      <property name="serviceController"><inject bean="JMXKernel" property="serviceController"/></property>
+   </lifecycle-configure>
+   <lifecycle-create xmlns="urn:jboss:aop-beans:1.0"
+               name="JMXCreateDestroyAdvice"
+               class="org.jboss.system.microcontainer.jmx.ServiceControllerCreateDestroyLifecycleCallback"
+               classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX">
+      <property name="serviceController"><inject bean="JMXKernel" property="serviceController"/></property>
+   </lifecycle-create>
+   <lifecycle-install xmlns="urn:jboss:aop-beans:1.0"
+               name="JMXStartStopAdvice"
+               class="org.jboss.system.microcontainer.jmx.ServiceControllerStartStopLifecycleCallback"
+               classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX">
+      <property name="serviceController"><inject bean="JMXKernel" property="serviceController"/></property>
+   </lifecycle-install>
+
+</deployment>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list