[jboss-osgi-commits] JBoss-OSGI SVN: r89047 - in projects/jboss-osgi/projects/husky/trunk/harness: src/main/java/org/jboss/osgi/husky/internal and 3 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Tue May 19 10:05:01 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-05-19 10:05:01 -0400 (Tue, 19 May 2009)
New Revision: 89047
Added:
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Activator.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Extender.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnectorMBean.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitPackageListener.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitRunner.java
Removed:
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Activator.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Extender.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnector.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnectorMBean.java
Modified:
projects/jboss-osgi/projects/husky/trunk/harness/pom.xml
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/BasicBridge.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/LocalInvoker.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/Runner.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitPackageListener.java
projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitRunner.java
Log:
Add propper OSGi support
Modified: projects/jboss-osgi/projects/husky/trunk/harness/pom.xml
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/pom.xml 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/pom.xml 2009-05-19 14:05:01 UTC (rev 89047)
@@ -66,7 +66,7 @@
<configuration>
<instructions>
<Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
- <Bundle-Activator>org.jboss.osgi.husky.internal.Activator</Bundle-Activator>
+ <Bundle-Activator>org.jboss.osgi.husky.runtime.osgi.Activator</Bundle-Activator>
<Private-Package>
org.jboss.osgi.husky.internal,
org.jboss.osgi.husky.runtime*,
Deleted: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Activator.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Activator.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Activator.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -1,55 +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.husky.internal;
-
-// $Id$
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * [TODO]
- *
- * @author Thomas.Diesler at jboss.com
- * @since 17-May-2009
- */
-public class Activator implements BundleActivator
-{
- private JMXConnector connector;
-
- public void start(BundleContext context) throws Exception
- {
- connector = new JMXConnector(context);
- connector.start();
-
- context.addBundleListener(new Extender(context));
- }
-
- public void stop(BundleContext context) throws Exception
- {
- if (connector != null)
- {
- connector.stop();
- connector = null;
- }
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/BasicBridge.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/BasicBridge.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/BasicBridge.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -71,7 +71,7 @@
className = System.getProperty(Invoker.class.getName());
if (className == null)
- throw new IllegalStateException("Cannot load invoker: " + className);
+ throw new IllegalStateException("Cannot obtain value for invoker property: " + Invoker.class.getName());
invoker = (Invoker)Util.loadInstance(className, props);
}
Deleted: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Extender.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Extender.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Extender.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -1,95 +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.husky.internal;
-
-// $Id$
-
-import javax.management.MBeanServer;
-
-import org.jboss.osgi.common.log.LogServiceTracker;
-import org.jboss.osgi.husky.runtime.PackageListener;
-import org.jboss.osgi.husky.runtime.junit.JUnitPackageListener;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-
-/**
- * [TODO]
- *
- * @author Thomas.Diesler at jboss.com
- * @since 17-May-2009
- */
-public class Extender implements BundleListener
-{
- private BundleContext context;
- private LogService log;
-
- public Extender(BundleContext context)
- {
- this.log = new LogServiceTracker(context);
- this.context = context;
- }
-
- public void bundleChanged(BundleEvent event)
- {
- if (event.getType() == BundleEvent.STARTED)
- {
- Bundle bundle = event.getBundle();
- String testPackage = (String)bundle.getHeaders().get("Test-Package");
- if (testPackage != null)
- {
- log.log(LogService.LOG_INFO, "Test-Package: " + testPackage + " in bundle: " + bundle);
- registerPackageListener(bundle, testPackage.split("[, ]"));
- }
- }
- }
-
- private void registerPackageListener(Bundle bundle, String[] testPackages)
- {
- ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
- if (sref == null)
- {
- log.log(LogService.LOG_WARNING, "Cannot obtain MBeanServer service");
- return;
- }
-
- JUnitPackageListener listener = new JUnitPackageListener(bundle, testPackages);
- MBeanServer server = (MBeanServer)context.getService(sref);
- if (server.isRegistered(JMXConnector.OBJECT_NAME) == false)
- {
- log.log(LogService.LOG_WARNING, "Cannot obtain connector: " + JMXConnector.OBJECT_NAME);
- return;
- }
-
- try
- {
- server.invoke(JMXConnector.OBJECT_NAME, "addPackageListener", new Object[] { listener }, new String[] { PackageListener.class.getName() });
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Cannot register package listener", ex);
- }
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnector.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnector.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnector.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -1,125 +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.husky.internal;
-
-// $Id$
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.jboss.osgi.common.log.LogServiceTracker;
-import org.jboss.osgi.husky.Request;
-import org.jboss.osgi.husky.Response;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-
-/**
- * [TODO]
- *
- * @author Thomas.Diesler at jboss.com
- * @since 17-May-2009
- */
-public class JMXConnector extends AbstractConnector implements JMXConnectorMBean
-{
- public static ObjectName OBJECT_NAME;
- static
- {
- try
- {
- OBJECT_NAME = ObjectName.getInstance("jboss.osgi.husky:service=jmx-connector");
- }
- catch (MalformedObjectNameException e)
- {
- // should never get here
- }
- }
-
- private LogService log;
- private BundleContext context;
-
- public JMXConnector(BundleContext context)
- {
- this.log = new LogServiceTracker(context);
- this.context = context;
- }
-
- public void start() throws Exception
- {
- ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
- if (sref == null)
- throw new IllegalStateException("Cannot obtain MBeanServer service");
-
- MBeanServer server = (MBeanServer)context.getService(sref);
- server.registerMBean(this, OBJECT_NAME);
- log.log(LogService.LOG_INFO, "JMXConnector registered: " + OBJECT_NAME);
- }
-
- public void stop() throws Exception
- {
- ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
- if (sref != null)
- {
- MBeanServer server = (MBeanServer)context.getService(sref);
- if (server.isRegistered(OBJECT_NAME));
- server.unregisterMBean(OBJECT_NAME);
- }
- }
-
- public InputStream process(InputStream reqStream)
- {
- try
- {
- // Unmarshall the Request
- ObjectInputStream ois = new ObjectInputStream(reqStream);
- Request request = (Request)ois.readObject();
-
- // Field the request through the abstract connector
- Response response = process(request);
- if (response == null)
- throw new IllegalStateException("response cannot be null");
-
- // Marshall the Response
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(response);
- oos.close();
-
- return new ByteArrayInputStream(baos.toByteArray());
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Cannot process request", ex);
- }
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnectorMBean.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnectorMBean.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnectorMBean.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -1,53 +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.husky.internal;
-
-//$Id$
-
-import java.io.InputStream;
-
-import org.jboss.osgi.husky.Request;
-import org.jboss.osgi.husky.Response;
-import org.jboss.osgi.husky.runtime.PackageListener;
-
-/**
- * [TODO]
- *
- * @author Thomas.Diesler at jboss.com
- * @since 17-May-2009
- */
-public interface JMXConnectorMBean
-{
- /**
- * Consumes the serialized version of an {@link Request} and
- * return the the {@link Response} from the test run
- *
- * @param reqStream the input stream to read the {@link Request} from
- * @return the input stream to read the {@link Response} from
- */
- InputStream process(InputStream reqStream);
-
- /**
- * Add a {@link PackageListener} to this connector
- */
- void addPackageListener(PackageListener listener);
-}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/LocalInvoker.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/LocalInvoker.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/LocalInvoker.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -42,6 +42,7 @@
import org.jboss.osgi.husky.runtime.Connector;
import org.jboss.osgi.husky.runtime.Runner;
import org.jboss.osgi.husky.runtime.junit.JUnitRunner;
+import org.jboss.osgi.husky.runtime.osgi.JMXConnector;
/**
* [TODO]
Modified: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/Runner.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/Runner.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/Runner.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -53,4 +53,9 @@
* Note, some test frameworks may choose to use an instance per test method.
*/
Response runTests(Context context, Class<?> testClass);
+
+ /**
+ * Inject the {@link Context} inte the test case instance
+ */
+ void injectContext(Object test, Context context) throws Exception;
}
Modified: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitPackageListener.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitPackageListener.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitPackageListener.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -26,33 +26,26 @@
import org.jboss.osgi.husky.Context;
import org.jboss.osgi.husky.internal.AbstractPackageListener;
import org.jboss.osgi.husky.internal.BasicContext;
+import org.jboss.osgi.husky.internal.Util;
import org.jboss.osgi.husky.runtime.Runner;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
/**
- * An implementation of a {@link Runner} that uses the
- * JUnit4 Test Runner.
+ * An implementation of a {@link Runner} that uses the JUnit4 Test Runner.
*
* @author Thomas.Diesler at jboss.com
* @since 16-May-2009
*/
public class JUnitPackageListener extends AbstractPackageListener
{
- private Bundle bundle;
-
- public JUnitPackageListener(Bundle bundle, String[] testPackages)
+ public JUnitPackageListener(String[] testPackages)
{
super(testPackages);
- this.bundle = bundle;
}
@Override
public Context getContext()
{
BasicContext context = new BasicContext();
- context.addAttachment(Bundle.class, bundle);
- context.addAttachment(BundleContext.class, bundle.getBundleContext());
return context;
}
@@ -65,6 +58,6 @@
@Override
public Class<?> loadTestClass(String className) throws ClassNotFoundException
{
- return bundle.loadClass(className);
+ return Util.loadClass(className);
}
}
Modified: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitRunner.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitRunner.java 2009-05-19 14:03:15 UTC (rev 89046)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/junit/JUnitRunner.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -59,22 +59,7 @@
protected Object createTest() throws Exception
{
Object test = super.createTest();
- for (Field field : testClass.getFields())
- {
- ProvideContext anProvide = field.getAnnotation(ProvideContext.class);
- if (anProvide != null)
- {
- field.set(test, context);
- }
- }
- for (Method method : testClass.getDeclaredMethods())
- {
- ProvideContext anProvide = method.getAnnotation(ProvideContext.class);
- if (anProvide != null)
- {
- method.invoke(test, context);
- }
- }
+ injectContext(test, context);
return test;
}
};
@@ -102,4 +87,25 @@
Response response = new JUnitResponse(result);
return response;
}
+
+ public void injectContext(Object test, Context context) throws Exception
+ {
+ Class<? extends Object> testClass = test.getClass();
+ for (Field field : testClass.getFields())
+ {
+ ProvideContext anProvide = field.getAnnotation(ProvideContext.class);
+ if (anProvide != null)
+ {
+ field.set(test, context);
+ }
+ }
+ for (Method method : testClass.getDeclaredMethods())
+ {
+ ProvideContext anProvide = method.getAnnotation(ProvideContext.class);
+ if (anProvide != null)
+ {
+ method.invoke(test, context);
+ }
+ }
+ }
}
Copied: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Activator.java (from rev 89040, projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Activator.java)
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Activator.java (rev 0)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Activator.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -0,0 +1,55 @@
+/*
+ * 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.husky.runtime.osgi;
+
+// $Id$
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * [TODO]
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 17-May-2009
+ */
+public class Activator implements BundleActivator
+{
+ private JMXConnector connector;
+
+ public void start(BundleContext context) throws Exception
+ {
+ connector = new JMXConnector(context);
+ connector.start();
+
+ context.addBundleListener(new Extender(context));
+ }
+
+ public void stop(BundleContext context) throws Exception
+ {
+ if (connector != null)
+ {
+ connector.stop();
+ connector = null;
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Extender.java (from rev 89041, projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/Extender.java)
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Extender.java (rev 0)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/Extender.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -0,0 +1,95 @@
+/*
+ * 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.husky.runtime.osgi;
+
+// $Id$
+
+import javax.management.MBeanServer;
+
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.husky.runtime.PackageListener;
+import org.jboss.osgi.husky.runtime.junit.JUnitPackageListener;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+/**
+ * [TODO]
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 17-May-2009
+ */
+public class Extender implements BundleListener
+{
+ private BundleContext context;
+ private LogService log;
+
+ public Extender(BundleContext context)
+ {
+ this.log = new LogServiceTracker(context);
+ this.context = context;
+ }
+
+ public void bundleChanged(BundleEvent event)
+ {
+ if (event.getType() == BundleEvent.STARTED)
+ {
+ Bundle bundle = event.getBundle();
+ String testPackage = (String)bundle.getHeaders().get("Test-Package");
+ if (testPackage != null)
+ {
+ log.log(LogService.LOG_INFO, "Test-Package: " + testPackage + " in bundle: " + bundle);
+ registerPackageListener(bundle, testPackage.split("[, ]"));
+ }
+ }
+ }
+
+ private void registerPackageListener(Bundle bundle, String[] testPackages)
+ {
+ ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
+ if (sref == null)
+ {
+ log.log(LogService.LOG_WARNING, "Cannot obtain MBeanServer service");
+ return;
+ }
+
+ JUnitPackageListener listener = new OSGiJUnitPackageListener(bundle, testPackages);
+ MBeanServer server = (MBeanServer)context.getService(sref);
+ if (server.isRegistered(JMXConnector.OBJECT_NAME) == false)
+ {
+ log.log(LogService.LOG_WARNING, "Cannot obtain connector: " + JMXConnector.OBJECT_NAME);
+ return;
+ }
+
+ try
+ {
+ server.invoke(JMXConnector.OBJECT_NAME, "addPackageListener", new Object[] { listener }, new String[] { PackageListener.class.getName() });
+ }
+ catch (Exception ex)
+ {
+ throw new IllegalStateException("Cannot register package listener", ex);
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java (from rev 89040, projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnector.java)
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java (rev 0)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -0,0 +1,126 @@
+/*
+ * 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.husky.runtime.osgi;
+
+// $Id$
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.husky.Request;
+import org.jboss.osgi.husky.Response;
+import org.jboss.osgi.husky.internal.AbstractConnector;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+/**
+ * [TODO]
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 17-May-2009
+ */
+public class JMXConnector extends AbstractConnector implements JMXConnectorMBean
+{
+ public static ObjectName OBJECT_NAME;
+ static
+ {
+ try
+ {
+ OBJECT_NAME = ObjectName.getInstance("jboss.osgi.husky:service=jmx-connector");
+ }
+ catch (MalformedObjectNameException e)
+ {
+ // should never get here
+ }
+ }
+
+ private LogService log;
+ private BundleContext context;
+
+ public JMXConnector(BundleContext context)
+ {
+ this.log = new LogServiceTracker(context);
+ this.context = context;
+ }
+
+ public void start() throws Exception
+ {
+ ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
+ if (sref == null)
+ throw new IllegalStateException("Cannot obtain MBeanServer service");
+
+ MBeanServer server = (MBeanServer)context.getService(sref);
+ server.registerMBean(this, OBJECT_NAME);
+ log.log(LogService.LOG_INFO, "JMXConnector registered: " + OBJECT_NAME);
+ }
+
+ public void stop() throws Exception
+ {
+ ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
+ if (sref != null)
+ {
+ MBeanServer server = (MBeanServer)context.getService(sref);
+ if (server.isRegistered(OBJECT_NAME));
+ server.unregisterMBean(OBJECT_NAME);
+ }
+ }
+
+ public InputStream process(InputStream reqStream)
+ {
+ try
+ {
+ // Unmarshall the Request
+ ObjectInputStream ois = new ObjectInputStream(reqStream);
+ Request request = (Request)ois.readObject();
+
+ // Field the request through the abstract connector
+ Response response = process(request);
+ if (response == null)
+ throw new IllegalStateException("response cannot be null");
+
+ // Marshall the Response
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(response);
+ oos.close();
+
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ throw new IllegalStateException("Cannot process request", ex);
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnectorMBean.java (from rev 89041, projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/JMXConnectorMBean.java)
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnectorMBean.java (rev 0)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnectorMBean.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -0,0 +1,53 @@
+/*
+ * 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.husky.runtime.osgi;
+
+//$Id$
+
+import java.io.InputStream;
+
+import org.jboss.osgi.husky.Request;
+import org.jboss.osgi.husky.Response;
+import org.jboss.osgi.husky.runtime.PackageListener;
+
+/**
+ * [TODO]
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 17-May-2009
+ */
+public interface JMXConnectorMBean
+{
+ /**
+ * Consumes the serialized version of an {@link Request} and
+ * return the the {@link Response} from the test run
+ *
+ * @param reqStream the input stream to read the {@link Request} from
+ * @return the input stream to read the {@link Response} from
+ */
+ InputStream process(InputStream reqStream);
+
+ /**
+ * Add a {@link PackageListener} to this connector
+ */
+ void addPackageListener(PackageListener listener);
+}
\ No newline at end of file
Added: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitPackageListener.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitPackageListener.java (rev 0)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitPackageListener.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -0,0 +1,70 @@
+/*
+ * 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.husky.runtime.osgi;
+
+// $Id$
+
+import org.jboss.osgi.husky.Context;
+import org.jboss.osgi.husky.internal.BasicContext;
+import org.jboss.osgi.husky.runtime.Runner;
+import org.jboss.osgi.husky.runtime.junit.JUnitPackageListener;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * An implementation of a {@link Runner} that uses the
+ * JUnit4 Test Runner.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public class OSGiJUnitPackageListener extends JUnitPackageListener
+{
+ private Bundle bundle;
+
+ public OSGiJUnitPackageListener(Bundle bundle, String[] testPackages)
+ {
+ super(testPackages);
+ this.bundle = bundle;
+ }
+
+ @Override
+ public Context getContext()
+ {
+ BasicContext context = new BasicContext();
+ context.addAttachment(Bundle.class, bundle);
+ context.addAttachment(BundleContext.class, bundle.getBundleContext());
+ return context;
+ }
+
+ @Override
+ public Runner getRunner()
+ {
+ return new OSGiJUnitRunner();
+ }
+
+ @Override
+ public Class<?> loadTestClass(String className) throws ClassNotFoundException
+ {
+ return bundle.loadClass(className);
+ }
+}
Property changes on: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitPackageListener.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitRunner.java
===================================================================
--- projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitRunner.java (rev 0)
+++ projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitRunner.java 2009-05-19 14:05:01 UTC (rev 89047)
@@ -0,0 +1,79 @@
+/*
+ * 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.husky.runtime.osgi;
+
+// $Id$
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.jboss.osgi.husky.Context;
+import org.jboss.osgi.husky.annotation.ProvideContext;
+import org.jboss.osgi.husky.runtime.Runner;
+import org.jboss.osgi.husky.runtime.junit.JUnitRunner;
+import org.osgi.framework.BundleContext;
+
+/**
+ * An implementation of a {@link Runner} that uses the JUnit4 Test Runner.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public class OSGiJUnitRunner extends JUnitRunner
+{
+ public void injectContext(Object test, Context context) throws Exception
+ {
+ BundleContext bundleContext = context.getAttachment(BundleContext.class);
+ Class<? extends Object> testClass = test.getClass();
+
+ for (Field field : testClass.getFields())
+ {
+ ProvideContext anProvide = field.getAnnotation(ProvideContext.class);
+ if (anProvide != null)
+ {
+ if (field.getType().isAssignableFrom(BundleContext.class))
+ {
+ field.set(test, bundleContext);
+ }
+ else
+ {
+ field.set(test, context);
+ }
+ }
+ }
+ for (Method method : testClass.getDeclaredMethods())
+ {
+ ProvideContext anProvide = method.getAnnotation(ProvideContext.class);
+ if (anProvide != null)
+ {
+ if (method.getParameterTypes()[0].isAssignableFrom(BundleContext.class))
+ {
+ method.invoke(test, bundleContext);
+ }
+ else
+ {
+ method.invoke(test, context);
+ }
+ }
+ }
+ }
+}
Property changes on: projects/jboss-osgi/projects/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/OSGiJUnitRunner.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jboss-osgi-commits
mailing list