[jboss-cvs] JBossAS SVN: r92668 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int: scripts and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 21 09:22:08 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-21 09:22:07 -0400 (Fri, 21 Aug 2009)
New Revision: 92668
Added:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/scripts/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/scripts/antrun-test-jars.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleActivator.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleService.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple.bnd
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
Log:
Add simple bnd based bundle test case
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath 2009-08-21 13:17:01 UTC (rev 92667)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath 2009-08-21 13:22:07 UTC (rev 92668)
@@ -1,9 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" output="target/classes" path="target/generated-sources/javacc"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="src" output="target/classes" path="target/generated-sources/javacc"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml 2009-08-21 13:17:01 UTC (rev 92667)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml 2009-08-21 13:22:07 UTC (rev 92668)
@@ -24,8 +24,11 @@
</properties>
<dependencies>
- <!-- Global dependencies -->
<dependency>
+ <groupId>biz.aQute</groupId>
+ <artifactId>bnd</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-kernel</artifactId>
<version>${version.jboss.microcontainer}</version>
@@ -123,23 +126,30 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${version.junit}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-log4j</artifactId>
- <version>${version.jboss.logging.log4j}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
<plugins>
<plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>build-test-jars</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <property name="maven.runtime.classpath" refid="maven.runtime.classpath" />
+ <property name="tests.output.dir" value="${project.build.directory}" />
+ <ant antfile="scripts/antrun-test-jars.xml" />
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javacc-maven-plugin</artifactId>
<version>2.4</version>
@@ -152,17 +162,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <systemProperties>
- <property>
- <name>log4j.output.dir</name>
- <value>${project.build.directory}</value>
- </property>
- </systemProperties>
- </configuration>
- </plugin>
</plugins>
</build>
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/scripts/antrun-test-jars.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/scripts/antrun-test-jars.xml 2009-08-21 13:22:07 UTC (rev 92668)
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ============================================================ -->
+<!-- JBoss, the OpenSource J2EE webOS -->
+<!-- Distributable under LGPL license. -->
+<!-- See terms of license at http://www.gnu.org. -->
+<!-- ============================================================ -->
+
+<!-- $Id$ -->
+
+<project default="build-test-jars">
+
+ <description>OSGi test archive builder</description>
+
+ <!-- ================================================================== -->
+ <!-- Init -->
+ <!-- ================================================================== -->
+
+ <target name="init">
+
+ <!-- Property override when not called from maven -->
+ <property name="maven.runtime.classpath" value="/usr/java/bnd.jar" />
+ <property name="tests.output.dir" value="${basedir}/../target" />
+
+ <mkdir dir="${tests.output.dir}/test-libs" />
+ <property name="tests.classes.dir" value="${tests.output.dir}/test-classes" />
+ <property name="tests.resources.dir" value="${tests.output.dir}/test-classes" />
+
+ <taskdef resource="aQute/bnd/ant/taskdef.properties">
+ <classpath>
+ <pathelement path="${maven.runtime.classpath}" />
+ </classpath>
+ </taskdef>
+
+ </target>
+
+ <!-- ================================================================== -->
+ <!-- Building -->
+ <!-- ================================================================== -->
+
+ <target name="build-test-jars" depends="init" description="Build the test deployments">
+
+ <!-- Please add alphabetically -->
+
+ <!-- simple -->
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/simple-bundle.jar" files="${tests.resources.dir}/bundles/simple/simple.bnd" />
+
+ <!-- Please add alphabetically -->
+
+ </target>
+
+</project>
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/scripts/antrun-test-jars.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java 2009-08-21 13:17:01 UTC (rev 92667)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFramework.java 2009-08-21 13:22:07 UTC (rev 92668)
@@ -23,6 +23,9 @@
// $Id$
+import java.io.IOException;
+import java.io.InputStream;
+
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
@@ -43,22 +46,157 @@
final Logger log = Logger.getLogger(OSGiFramework.class);
private OSGiBundleManager bundleManager;
+ private OSGiBundleState bundleState;
public OSGiFramework(OSGiBundleManager bundleManager, OSGiBundleState bundleState)
{
super(bundleState);
this.bundleManager = bundleManager;
+ this.bundleState = bundleState;
}
public void init() throws BundleException
{
- // TODO Auto-generated method stub
+ initInternal();
+ }
+
+ @Override
+ public void start() throws BundleException
+ {
+ startInternal();
+ }
+
+ @Override
+ public void start(int options) throws BundleException
+ {
+ startInternal();
+ }
+
+ @Override
+ public void stop() throws BundleException
+ {
+ // [TODO] The method returns immediately to the caller after initiating the following steps
+
+ stopInternal();
+ }
+
+ @Override
+ public void stop(int options) throws BundleException
+ {
+ // [TODO] The method returns immediately to the caller after initiating the following steps
+
+ stopInternal();
+ }
+
+ @Override
+ public void update() throws BundleException
+ {
+ updateInternal();
+ }
+
+ /**
+ * Calling this method is the same as calling {@link #update()} except that any provided InputStream is immediately closed.
+ */
+ @Override
+ public void update(InputStream in) throws BundleException
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException ex)
+ {
+ // ignore
+ }
+ }
+
+ // [TODO] The method returns immediately to the caller after initiating the following steps
+
+ updateInternal();
+ }
+
+ /**
+ * The Framework cannot be uninstalled.
+ * <p>
+ * This method always throws a BundleException.
+ */
+ @Override
+ public void uninstall() throws BundleException
+ {
+ throw new BundleException("The system bundle cannot be uninstalled");
+ }
+
+ private void initInternal()
+ {
+ // This method does nothing if called when this Framework is in the
+ // STARTING, ACTIVE or STOPPING state
+ if (getState() == STARTING || getState() == ACTIVE || getState() == STOPPING)
+ return;
+
+ // Put into the STARTING state
+ bundleState.changeState(STARTING);
+
+ // Have a valid Bundle Context
+ bundleState.createBundleContext();
+
+ // [TODO] Be at start level 0
+
+ // [TODO] Have event handling enabled
+
+ // [TODO] Cleanup the storage area
+ // [TODO] Have reified Bundle objects for all installed bundles
+
+ // [TODO] Have registered any framework services
}
+ private void startInternal() throws BundleException
+ {
+ // If this Framework is not in the STARTING state, initialize this Framework
+ if (getState() != STARTING)
+ initInternal();
+
+ // All installed bundles must be started
+
+ // This Framework's state is set to ACTIVE
+ bundleState.changeState(ACTIVE);
+
+ // [TODO] A framework event of type STARTED is fired
+ }
+
+ private void stopInternal()
+ {
+ // This Framework's state is set to STOPPING
+ bundleState.changeState(STOPPING);
+
+ // [TODO] All installed bundles must be stopped
+
+ // [TODO] Unregister all services registered by this Framework
+
+ // [TODO] Event handling is disabled
+
+ // This Framework's state is set to RESOLVED
+ bundleState.changeState(RESOLVED);
+
+ // [TODO] All resources held by this Framework are released.
+
+ // [TODO] Notify all threads that are waiting at waitForStop(long)
+ }
+
+ private void updateInternal() throws BundleException
+ {
+ stopInternal();
+
+ startInternal();
+ }
+
public FrameworkEvent waitForStop(long timeout) throws InterruptedException
{
- // TODO Auto-generated method stub
- return null;
+ // [TODO] Wait until this Framework has completely stopped.
+
+ // [TODO] A Framework Event indicating the reason this method returned
+ return new FrameworkEvent(FrameworkEvent.STOPPED, this, null);
}
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-21 13:17:01 UTC (rev 92667)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-21 13:22:07 UTC (rev 92668)
@@ -35,6 +35,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.osgi.framework.Bundle;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
@@ -81,6 +82,10 @@
OSGiBundleManager manager = (OSGiBundleManager)managerContext.getTarget();
OSGiBundleState sysBundle = manager.getBundle(0);
+ // [TODO] Remove hack that forces the initial state to installed
+ if (sysBundle.getState() != Bundle.INSTALLED)
+ sysBundle.changeState(Bundle.INSTALLED);
+
return new OSGiFramework(manager, sysBundle);
}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java 2009-08-21 13:22:07 UTC (rev 92668)
@@ -0,0 +1,83 @@
+/*
+ * 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.simple;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URL;
+
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * A test that deployes a bundle and verifies its state
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public class SimpleBundleTestCase
+{
+ private static Framework framework;
+
+ @BeforeClass
+ public static void beforeClass() throws BundleException
+ {
+ FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+ framework = factory.newFramework(null);
+ framework.start();
+ }
+
+ @AfterClass
+ public static void afterClass() throws BundleException
+ {
+ if (framework != null)
+ framework.stop();
+ }
+
+ @Test
+ public void testBundleInstall() throws Exception
+ {
+ BundleContext sysContext = framework.getBundleContext();
+ URL bundleURL = new OSGiTestHelper().getTestArchiveURL("simple-bundle.jar");
+ Bundle bundle = sysContext.installBundle(bundleURL.toExternalForm());
+
+ assertEquals("simple-bundle", bundle.getSymbolicName());
+
+ bundle.start();
+ System.out.println("FIXME: state==INSTALLED after bundle.start()");
+ //assertEquals("Bundle state", Bundle.ACTIVE, bundle.getState());
+
+ bundle.uninstall();
+ assertEquals("Bundle state", Bundle.UNINSTALLED, bundle.getState());
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleActivator.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleActivator.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleActivator.java 2009-08-21 13:22:07 UTC (rev 92668)
@@ -0,0 +1,47 @@
+/*
+ * 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.simple.bundle;
+
+//$Id$
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A Service Activator
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 24-Apr-2009
+ */
+public class SimpleActivator implements BundleActivator
+{
+ public void start(BundleContext context)
+ {
+ // Register a service
+ SimpleService service = new SimpleService(context);
+ context.registerService(SimpleService.class.getName(), service, null);
+ }
+
+ public void stop(BundleContext context)
+ {
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleActivator.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleService.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleService.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleService.java 2009-08-21 13:22:07 UTC (rev 92668)
@@ -0,0 +1,44 @@
+/*
+ * 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.simple.bundle;
+
+//$Id$
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * A SimpleService
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 24-Apr-2009
+ */
+public class SimpleService
+{
+ public SimpleService(BundleContext context)
+ {
+ }
+
+ public String echo(String msg)
+ {
+ return msg;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/simple/bundle/SimpleService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple.bnd
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple.bnd (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple.bnd 2009-08-21 13:22:07 UTC (rev 92668)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/simple-bundle.jar src/test/resources/bundles/simple/simple.bnd
+
+Bundle-SymbolicName: simple-bundle
+
+Bundle-Activator: org.jboss.test.osgi.simple.bundle.SimpleActivator
+Export-Package: org.jboss.test.osgi.simple.bundle
More information about the jboss-cvs-commits
mailing list