Permalink
Browse files

Make EventAdmin independent of org.osgi.enterprise

  • Loading branch information...
1 parent 3ad77af commit 9074936e2b09224b5cc6090a8eef6f880f5f4866 @tdiesler tdiesler committed Oct 22, 2012
View
18 pom.xml
@@ -49,6 +49,7 @@
<version.apache.felix.configadmin>1.2.8</version.apache.felix.configadmin>
<version.apache.felix.eventadmin>1.2.14</version.apache.felix.eventadmin>
<version.apache.felix.log>1.0.0</version.apache.felix.log>
+ <version.apache.felix.metatype>1.0.4</version.apache.felix.metatype>
<version.apache.felix.scr>1.6.0</version.apache.felix.scr>
<version.apache.felix.webconsole>3.1.8</version.apache.felix.webconsole>
<version.eclipse.jetty>8.1.4.v20120524</version.eclipse.jetty>
@@ -291,13 +292,13 @@
<dependency>
<groupId>org.jboss.osgi.felix</groupId>
<artifactId>jboss-osgi-felix</artifactId>
- <version>${version.jboss.osgi.felix}</version>
<exclusions>
<exclusion>
<groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-spi</artifactId>
</exclusion>
</exclusions>
+ <version>${version.jboss.osgi.felix}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
@@ -312,7 +313,21 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.log</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ </exclusions>
<version>${version.apache.felix.log}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.metatype</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.felix</groupId>
@@ -323,6 +338,7 @@
<artifactId>org.osgi.compendium</artifactId>
</exclusion>
</exclusions>
+ <version>${version.apache.felix.metatype}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
@@ -94,6 +94,11 @@
<artifactId>org.apache.felix.log</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.metatype</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
@@ -2,7 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
- <id>compendium</id>
+ <id>autoinstall</id>
<formats>
<format>dir</format>
</formats>
@@ -18,7 +18,6 @@
</outputFileNameMapping>
<includes>
<include>*:org.apache.felix.log:jar</include>
- <include>*:org.osgi.enterprise:jar</include>
<include>*:jboss-annotations-api_1.1_spec:jar</include>
<include>*:jboss-servlet-api_3.0_spec:jar</include>
<include>*:jbosgi-repository:jar</include>
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Provide the org.apache.felix.configadmin bundle
+ *
+ * @author thomas.diesler@jboss.com
+ * @since 22-Oct-2012
+ */
+public class ConfigurationAdminSupport extends RepositorySupport {
+
+ public static final String CONFIGURATION_ADMIN_SERVICE = "org.osgi.service.cm.ConfigurationAdmin";
+ public static final String APACHE_FELIX_CONFIGURATION_ADMIN = "org.apache.felix:org.apache.felix.configadmin";
+
+ public static void provideConfigurationAdmin(BundleContext syscontext, Bundle bundle) throws BundleException {
+ ServiceReference sref = syscontext.getServiceReference(CONFIGURATION_ADMIN_SERVICE);
+ if (sref == null) {
+ installSupportBundle(syscontext, getCoordinates(bundle, APACHE_FELIX_CONFIGURATION_ADMIN)).start();
+ }
+ }
+}
@@ -26,6 +26,8 @@
import org.osgi.framework.BundleException;
/**
+ * Provide the org.apache.felix.scr bundle
+ *
* @author thomas.diesler@jboss.com
* @since 28-Jan-2012
*/
@@ -25,22 +25,24 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.event.EventAdmin;
/**
+ * Provide the org.apache.felix.eventadmin bundle
+ *
* @author thomas.diesler@jboss.com
* @since 28-Jan-2012
*/
public class EventAdminSupport extends RepositorySupport {
+ public static final String EVENT_ADMIN_SERVICE = "org.osgi.service.event.EventAdmin";
public static final String APACHE_FELIX_EVENTADMIN = "org.apache.felix:org.apache.felix.eventadmin";
- public static EventAdmin provideEventAdmin(BundleContext syscontext, Bundle bundle) throws BundleException {
- ServiceReference sref = syscontext.getServiceReference(EventAdmin.class.getName());
+ public static void provideEventAdmin(BundleContext syscontext, Bundle bundle) throws BundleException {
+ ConfigurationAdminSupport.provideConfigurationAdmin(syscontext, bundle);
+ MetatypeSupport.provideMetatype(syscontext, bundle);
+ ServiceReference sref = syscontext.getServiceReference(EVENT_ADMIN_SERVICE);
if (sref == null) {
installSupportBundle(syscontext, getCoordinates(bundle, APACHE_FELIX_EVENTADMIN)).start();
- sref = syscontext.getServiceReference(EventAdmin.class.getName());
}
- return (EventAdmin) syscontext.getService(sref);
}
}
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., 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;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+/**
+ * Provide the org.apache.felix.metatype bundle
+ *
+ * @author Thomas.Diesler@jboss.com
+ * @since 22-Oct-2012
+ */
+public class MetatypeSupport extends RepositorySupport {
+
+ public static final String APACHE_FELIX_METATYPE = "org.apache.felix:org.apache.felix.metatype";
+
+ public static void provideMetatype(BundleContext syscontext, Bundle bundle) throws BundleException {
+ if (getPackageAdmin(syscontext).getBundles("org.apache.felix.metatype", null) == null) {
+ installSupportBundle(syscontext, getCoordinates(bundle, APACHE_FELIX_METATYPE)).start();
+ }
+ }
+}
@@ -5,6 +5,7 @@ org.apache.aries.proxy\:org.apache.aries.proxy=@version.apache.aries.proxy@
org.apache.aries\:org.apache.aries.util=@version.apache.aries.util@
org.apache.felix\:org.apache.felix.configadmin=@version.apache.felix.configadmin@
org.apache.felix\:org.apache.felix.eventadmin=@version.apache.felix.eventadmin@
+org.apache.felix\:org.apache.felix.metatype=@version.apache.felix.metatype@
org.apache.felix\:org.apache.felix.scr=@version.apache.felix.scr@
org.jboss.osgi.http\:jbosgi-http-api=@version.jboss.osgi.http@
org.jboss.osgi.jmx\:jbosgi-jmx=@version.jboss.osgi.jmx@
@@ -40,7 +40,9 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.test.osgi.ConfigurationAdminSupport;
import org.jboss.test.osgi.EventAdminSupport;
+import org.jboss.test.osgi.MetatypeSupport;
import org.jboss.test.osgi.RepositorySupport;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,7 +60,7 @@
/**
* A test that deployes the EventAdmin and sends/receives messages on a topic.
- *
+ *
* @author thomas.diesler@jboss.com
* @since 08-Dec-2009
*/
@@ -76,20 +78,20 @@
@ArquillianResource
BundleContext context;
- @ArquillianResource
- PackageAdmin packageAdmin;
-
@Deployment(name = EVENT_ADMIN_PROVIDER)
public static JavaArchive eventadminProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, EVENT_ADMIN_PROVIDER);
- archive.addClasses(EventAdminSupport.class, RepositorySupport.class);
+ archive.addClasses(EventAdminSupport.class, ConfigurationAdminSupport.class, MetatypeSupport.class, RepositorySupport.class);
archive.addAsManifestResource(RepositorySupport.BUNDLE_VERSIONS_FILE);
archive.setManifest(new Asset() {
+ @Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addImportPackages(XRequirementBuilder.class, XRequirement.class, Repository.class, Resource.class);
+ builder.addImportPackages(PackageAdmin.class);
+ builder.addDynamicImportPackages(EventAdmin.class.getPackage().getName());
return builder.openStream();
}
});
@@ -100,6 +102,7 @@ public InputStream openStream() {
public static JavaArchive testBundle() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, EVENT_ADMIN_BUNDLE);
archive.setManifest(new Asset() {
+ @Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
@@ -113,12 +116,12 @@ public InputStream openStream() {
@Test
@InSequence(0)
- public void addEventAdminSupport() throws BundleException {
- Bundle bundle = packageAdmin.getBundles(EVENT_ADMIN_PROVIDER, null)[0];
+ public void addEventAdminSupport(@ArquillianResource Bundle bundle) throws BundleException {
EventAdminSupport.provideEventAdmin(context, bundle);
}
@Test
+ @InSequence(1)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testEventHandler() throws Exception {
InputStream input = deployer.getDeployment(EVENT_ADMIN_BUNDLE);
@@ -131,7 +134,13 @@ public void testEventHandler() throws Exception {
// Register the EventHandler
Dictionary param = new Hashtable();
param.put(EventConstants.EVENT_TOPIC, new String[] { TOPIC });
- TestEventHandler eventHandler = new TestEventHandler();
+ final List<Event> received = new ArrayList<Event>();
+ EventHandler eventHandler = new EventHandler() {
+ @Override
+ public void handleEvent(Event event) {
+ received.add(event);
+ }
+ };
context.registerService(EventHandler.class.getName(), eventHandler, param);
// Send event through the the EventAdmin
@@ -140,18 +149,10 @@ public void testEventHandler() throws Exception {
eventAdmin.sendEvent(new Event(TOPIC, (Dictionary) null));
// Verify received event
- assertEquals("Event received", 1, eventHandler.received.size());
- assertEquals(TOPIC, eventHandler.received.get(0).getTopic());
+ assertEquals("Event received", 1, received.size());
+ assertEquals(TOPIC, received.get(0).getTopic());
} finally {
bundle.uninstall();
}
}
-
- static class TestEventHandler implements EventHandler {
- List<Event> received = new ArrayList<Event>();
-
- public void handleEvent(Event event) {
- received.add(event);
- }
- }
}
@@ -6,17 +6,13 @@
org.osgi.framework.storage=${basedir}/target/osgi-store
org.osgi.framework.storage.clean=onFirstInit
-# HttpService port
-org.osgi.service.http.port=8090
-
# Extra System Packages
org.osgi.framework.system.packages.extra=\
org.jboss.logging;version=3.0,\
org.slf4j;version=1.6
# Bundles that need to be installed with the Framework automatically
org.jboss.osgi.auto.install=\
- file://${test.archive.directory}/bundles/org.osgi.enterprise.jar,\
file://${test.archive.directory}/bundles/jboss-annotations-api_1.1_spec.jar,\
file://${test.archive.directory}/bundles/jboss-servlet-api_3.0_spec.jar

0 comments on commit 9074936

Please sign in to comment.