[jboss-osgi-commits] JBoss-OSGI SVN: r97013 - in projects/jboss-osgi/projects/bundles/husky/trunk: scripts and 2 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Thu Nov 26 02:32:07 EST 2009
Author: thomas.diesler at jboss.com
Date: 2009-11-26 02:32:06 -0500 (Thu, 26 Nov 2009)
New Revision: 97013
Added:
projects/jboss-osgi/projects/bundles/husky/trunk/scripts/
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
projects/jboss-osgi/projects/bundles/husky/trunk/src/test/
Removed:
projects/jboss-osgi/projects/bundles/husky/trunk/harness/
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
projects/jboss-osgi/projects/bundles/husky/trunk/src/site/
projects/jboss-osgi/projects/bundles/husky/trunk/testsuite/
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/.classpath
projects/jboss-osgi/projects/bundles/husky/trunk/pom.xml
projects/jboss-osgi/projects/bundles/husky/trunk/scripts/antrun-test-jars.xml
projects/jboss-osgi/projects/bundles/husky/trunk/scripts/assembly-bundles.xml
Log:
Move integration tests and harness impl to one module
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/.classpath
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/.classpath 2009-11-26 07:28:45 UTC (rev 97012)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/.classpath 2009-11-26 07:32:06 UTC (rev 97013)
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<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/bundles/husky/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/pom.xml 2009-11-26 07:28:45 UTC (rev 97012)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/pom.xml 2009-11-26 07:32:06 UTC (rev 97013)
@@ -19,11 +19,11 @@
<description>JBoss OSGi Test Support</description>
<groupId>org.jboss.osgi.bundles</groupId>
- <artifactId>jboss-osgi-husky-parent</artifactId>
- <packaging>pom</packaging>
+ <artifactId>jboss-osgi-husky</artifactId>
+ <packaging>bundle</packaging>
<version>1.0.2-SNAPSHOT</version>
-
+
<!-- Parent -->
<parent>
<groupId>org.jboss.osgi</groupId>
@@ -45,44 +45,216 @@
<version.jboss.osgi.deployment>1.0.0</version.jboss.osgi.deployment>
<version.osgi>4.2.0</version.osgi>
</properties>
-
- <!-- Modules -->
- <modules>
- <module>harness</module>
- <module>testsuite</module>
- </modules>
-
- <!-- DependencyManagement -->
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.jboss.osgi</groupId>
- <artifactId>jboss-osgi-spi</artifactId>
- <version>${version.jboss.osgi.spi}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.osgi.runtime</groupId>
- <artifactId>jboss-osgi-deployment</artifactId>
- <version>${version.jboss.osgi.deployment}</version>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.osgi.runtime</groupId>
- <artifactId>jboss-osgi-runtime-felix</artifactId>
- <version>${version.jboss.osgi.runtime.felix}</version>
- </dependency>
-
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${version.osgi}</version>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>${version.osgi}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
+
+ <!-- Dependencies -->
+ <dependencies>
+ <dependency>
+ <groupId>biz.aQute</groupId>
+ <artifactId>bnd</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.osgi</groupId>
+ <artifactId>jboss-osgi-spi</artifactId>
+ <version>${version.jboss.osgi.spi}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.osgi.runtime</groupId>
+ <artifactId>jboss-osgi-deployment</artifactId>
+ <version>${version.jboss.osgi.deployment}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <!-- Provided Dependencies -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${version.osgi}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${version.osgi}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>org.jboss.osgi.runtime</groupId>
+ <artifactId>jboss-osgi-runtime-felix</artifactId>
+ <version>${version.jboss.osgi.runtime.felix}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
+ <Bundle-Activator>org.jboss.osgi.husky.runtime.osgi.HuskyActivator</Bundle-Activator>
+ <Export-Package>
+ org.jboss.osgi.husky;version=${version},
+ org.jboss.osgi.testing;version=${version},
+ </Export-Package>
+ <Import-Package>
+ javax.management,
+ javax.naming,
+ org.jboss.osgi.deployment.interceptor;version="[1.0,1.1)",
+ org.jboss.osgi.spi;version="[1.0,1.1)",
+ org.jboss.osgi.spi.capability;version="[1.0,1.1)",
+ org.jboss.osgi.spi.management;version="[1.0,1.1)",
+ org.jboss.osgi.spi.util;version="[1.0,1.1)",
+ org.junit;version="[4.6,5.0)",
+ org.osgi.framework,
+ org.osgi.util.tracker,
+ org.slf4j;version="[1.5,1.6)",
+
+ <!-- ignore client side -->
+ !org.jboss.osgi.deployment.deployer,
+ !org.jboss.osgi.spi.framework,
+ !org.jboss.virtual,
+ !org.osgi.framework.launch,
+ !org.osgi.service.packageadmin,
+ </Import-Package>
+ <Private-Package>
+ org.jboss.osgi.husky.internal,
+ org.jboss.osgi.husky.runtime*,
+ org.jboss.osgi.testing.internal,
+ </Private-Package>
+ <Embed-Transitive>true</Embed-Transitive>
+ <Embed-Dependency>
+ junit;inline=false,
+ </Embed-Dependency>
+ <_exportcontents>org.junit;version=${version.junit}</_exportcontents>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <quiet>true</quiet>
+ <excludePackageNames>*.internal</excludePackageNames>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>bundles</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>directory-single</goal>
+ </goals>
+ <configuration>
+ <finalName>test-libs</finalName>
+ <ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
+ <appendAssemblyId>false</appendAssemblyId>
+ <descriptors>
+ <descriptor>scripts/assembly-bundles.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>build-test-jars</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <property name="maven.runtime.classpath" refid="maven.runtime.classpath" />
+ <property name="artifactId" value="${artifactId}" />
+ <property name="tests.output.dir" value="${project.build.directory}" />
+ <property name="build.artifact" value="${project.build.finalName}" />
+ <ant antfile="scripts/antrun-test-jars.xml" />
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>surefire-integration-tests</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ <argLine>${surefire.jpda.args}</argLine>
+ <systemProperties>
+ <property>
+ <name>java.protocol.handler.pkgs</name>
+ <value>org.jboss.net.protocol|org.jboss.virtual.protocol</value>
+ </property>
+ <property>
+ <name>log4j.output.dir</name>
+ <value>${project.build.directory}</value>
+ </property>
+ <property>
+ <name>org.jboss.osgi.husky.Invoker</name>
+ <value>org.jboss.osgi.husky.internal.OSGiInvoker</value>
+ </property>
+ <property>
+ <name>test.archive.directory</name>
+ <value>${project.build.directory}/test-libs</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- Profiles -->
+ <profiles>
+
+ <!--
+ Name: jpda
+ Descr: Enable JPDA remote debuging
+ -->
+ <profile>
+ <id>jpda</id>
+ <activation>
+ <property>
+ <name>jpda</name>
+ </property>
+ </activation>
+ <properties>
+ <surefire.jpda.args>-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y</surefire.jpda.args>
+ </properties>
+ </profile>
+
+ </profiles>
+
</project>
Copied: projects/jboss-osgi/projects/bundles/husky/trunk/scripts (from rev 96948, projects/jboss-osgi/projects/bundles/husky/trunk/testsuite/scripts)
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/testsuite/scripts/antrun-test-jars.xml 2009-11-25 13:38:06 UTC (rev 96948)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/scripts/antrun-test-jars.xml 2009-11-26 07:32:06 UTC (rev 97013)
@@ -31,6 +31,9 @@
<pathelement path="${maven.runtime.classpath}" />
</classpath>
</taskdef>
+
+ <!-- Copy build artifact to test-libs/bundles -->
+ <copy file="${tests.output.dir}/${build.artifact}.jar" tofile="${tests.output.dir}/test-libs/bundles/${artifactId}.jar" overwrite="true"/>
</target>
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/scripts/assembly-bundles.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/testsuite/scripts/assembly-bundles.xml 2009-11-25 13:38:06 UTC (rev 96948)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/scripts/assembly-bundles.xml 2009-11-26 07:32:06 UTC (rev 97013)
@@ -15,7 +15,6 @@
<outputDirectory>bundles</outputDirectory>
<outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
<includes>
- <include>*:jboss-osgi-husky:jar</include>
<include>*:org.osgi.compendium:jar</include>
</includes>
<useStrictFiltering>true</useStrictFiltering>
Copied: projects/jboss-osgi/projects/bundles/husky/trunk/src/main (from rev 96948, projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main)
Deleted: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2009-11-25 13:38:06 UTC (rev 96948)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2009-11-26 07:32:06 UTC (rev 97013)
@@ -1,309 +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.testing.internal;
-
-// $Id$
-
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.management.MBeanServerConnection;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.jboss.osgi.deployment.deployer.DeployerService;
-import org.jboss.osgi.deployment.deployer.Deployment;
-import org.jboss.osgi.spi.management.MBeanProxy;
-import org.jboss.osgi.spi.management.MBeanProxyException;
-import org.jboss.osgi.spi.management.ManagedBundleMBean;
-import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
-import org.jboss.osgi.spi.management.ManagedServiceReference;
-import org.jboss.osgi.spi.util.BundleInfo;
-import org.jboss.osgi.testing.OSGiBundle;
-import org.jboss.osgi.testing.OSGiPackageAdmin;
-import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiServiceReference;
-import org.jboss.osgi.testing.OSGiTestHelper;
-import org.osgi.framework.BundleException;
-
-/**
- * A remote implementation of the {@link OSGiRuntime}
- *
- * @author Thomas.Diesler at jboss.org
- * @since 25-Sep-2008
- */
-public class RemoteRuntime extends OSGiRuntimeImpl
-{
- private MBeanServerConnection mbeanServer;
- private ManagedFrameworkMBean managedFramework;
-
- public RemoteRuntime(OSGiTestHelper helper)
- {
- super(helper);
- }
-
- public OSGiBundle installBundle(String location) throws BundleException
- {
- try
- {
- // Get the bundle info from the location
- URL bundleURL = getTestHelper().getTestArchiveURL(location);
- BundleInfo info = BundleInfo.createBundleInfo(bundleURL);
-
- // Create the deployment from the info
- DeployerServiceClient deployer = new DeployerServiceClient(DeployerService.MBEAN_DEPLOYER_SERVICE);
- Deployment dep = deployer.createDeployment(info);
- dep.setAutoStart(false);
-
- // Deploy the deployemnt through the DeployerService
- deployer.deploy(new Deployment[] { dep });
-
- String symbolicName = info.getSymbolicName();
- String version = info.getVersion().toString();
-
- // The remote framework uses a BundleTracker that works of an asynchronous
- // event to register the installed bundle. It is not available immediately.
- int timeout = 50;
- ManagedBundleMBean bundleMBean = getRemoteFramework().getBundle(symbolicName, version);
- while (bundleMBean == null && 0 < timeout--)
- {
- Thread.sleep(200);
- bundleMBean = getRemoteFramework().getBundle(symbolicName, version);
- }
- if (bundleMBean == null)
- throw new IllegalStateException("Cannot find installed bundle: " + symbolicName + "-" + version);
-
- RemoteBundle bundle = new RemoteBundle(this, bundleMBean, location);
- return registerBundle(location, bundle);
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (BundleException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new BundleException("Cannot install: " + location, ex);
- }
- }
-
- public void deploy(String location) throws Exception
- {
- URL archiveURL = getTestHelper().getTestArchiveURL(location);
- ObjectName oname = getDeployerServiceName(archiveURL);
- DeployerServiceClient deployer = new DeployerServiceClient(oname);
- deployer.deploy(archiveURL);
- }
-
- public void undeploy(String location) throws Exception
- {
- URL archiveURL = getTestHelper().getTestArchiveURL(location);
- ObjectName oname = getDeployerServiceName(archiveURL);
- DeployerServiceClient deployer = new DeployerServiceClient(oname);
- deployer.undeploy(archiveURL);
- }
-
- public OSGiBundle[] getBundles()
- {
- try
- {
- Set<ManagedBundleMBean> remoteBundles = getRemoteFramework().getBundles();
- Set<OSGiBundle> bundles = new HashSet<OSGiBundle>();
- for (ManagedBundleMBean remoteBundle : remoteBundles)
- bundles.add(new RemoteBundle(this, remoteBundle, null));
-
- OSGiBundle[] bundleArr = new OSGiBundle[bundles.size()];
- bundles.toArray(bundleArr);
- return bundleArr;
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Cannot obtain remote bundles", ex);
- }
- }
-
- public OSGiBundle getBundle(long bundleId)
- {
- ManagedBundleMBean bundle = getRemoteFramework().getBundle(bundleId);
- return bundle != null ? new RemoteBundle(this, bundle, null) : null;
- }
-
- public OSGiServiceReference getServiceReference(String clazz)
- {
- ManagedServiceReference manref = getRemoteFramework().getServiceReference(clazz);
- return manref != null ? new RemoteServiceReference(manref) : null;
- }
-
- public OSGiServiceReference[] getServiceReferences(String clazz, String filter)
- {
- OSGiServiceReference[] srefs = null;
-
- ManagedServiceReference[] manrefs = getRemoteFramework().getServiceReferences(clazz, filter);
- if (manrefs != null)
- {
- srefs = new OSGiServiceReference[manrefs.length];
- for (int i = 0; i < manrefs.length; i++)
- srefs[i] = new RemoteServiceReference(manrefs[i]);
- }
-
- return srefs;
- }
-
- public MBeanServerConnection getMBeanServer()
- {
- if (mbeanServer == null)
- {
- try
- {
- InitialContext iniCtx = getInitialContext();
- mbeanServer = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
- }
- catch (NamingException ex)
- {
- throw new IllegalStateException("Cannot obtain MBeanServerConnection", ex);
- }
- }
- return mbeanServer;
- }
-
- public OSGiPackageAdmin getPackageAdmin()
- {
- return new RemotePackageAdmin(this);
- }
-
- @Override
- public void shutdown()
- {
- super.shutdown();
- getPackageAdmin().refreshPackages(null);
- }
-
- private RemoteFramework getRemoteFramework()
- {
- try
- {
- if (managedFramework == null)
- managedFramework = MBeanProxy.get(ManagedFrameworkMBean.class, ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK, getMBeanServer());
- }
- catch (MBeanProxyException ex)
- {
- throw new RemoteFrameworkException(ex);
- }
-
- return new RemoteFramework()
- {
- public ManagedBundleMBean getBundle(String name, String version)
- {
- ManagedBundleMBean bundleMBean = null;
- ObjectName oname = managedFramework.getBundle(name, version);
- if (oname != null)
- {
- try
- {
- bundleMBean = MBeanProxy.get(ManagedBundleMBean.class, oname, getMBeanServer());
- }
- catch (MBeanProxyException ex)
- {
- throw new RemoteFrameworkException(ex);
- }
- }
- return bundleMBean;
- }
-
- public ManagedBundleMBean getBundle(long bundleId)
- {
- ManagedBundleMBean bundleMBean = null;
- ObjectName oname = managedFramework.getBundle(bundleId);
- if (oname != null)
- {
- try
- {
- bundleMBean = MBeanProxy.get(ManagedBundleMBean.class, oname, getMBeanServer());
- }
- catch (MBeanProxyException ex)
- {
- throw new RemoteFrameworkException(ex);
- }
- }
- return bundleMBean;
- }
-
- public Set<ManagedBundleMBean> getBundles()
- {
- Set<ManagedBundleMBean> remBundles = new HashSet<ManagedBundleMBean>();
- for (ObjectName bundleOName : managedFramework.getBundles())
- {
- try
- {
- ManagedBundleMBean remBundle = MBeanProxy.get(ManagedBundleMBean.class, bundleOName, getMBeanServer());
- remBundles.add(remBundle);
- }
- catch (MBeanProxyException ex)
- {
- throw new RemoteFrameworkException(ex);
- }
- }
- return remBundles;
- }
-
- public ManagedServiceReference getServiceReference(String clazz)
- {
- return managedFramework.getServiceReference(clazz);
- }
-
- public ManagedServiceReference[] getServiceReferences(String clazz, String filter)
- {
- return managedFramework.getServiceReferences(clazz, filter);
- }
- };
- }
-
- public boolean isRemoteRuntime()
- {
- return true;
- }
-
- /**
- * Return ObjectName of the DeployerService MBean if hte archive is a bundle
- * otherwise if returns the ObjectName of the MainDeployer
- */
- private ObjectName getDeployerServiceName(URL archiveURL) throws MalformedObjectNameException
- {
- ObjectName oname;
- try
- {
- BundleInfo.createBundleInfo(archiveURL);
- oname = DeployerService.MBEAN_DEPLOYER_SERVICE;
- }
- catch (Exception e)
- {
- oname = new ObjectName("jboss.system:service=MainDeployer");
- }
- return oname;
- }
-}
Copied: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java (from rev 96949, projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2009-11-26 07:32:06 UTC (rev 97013)
@@ -0,0 +1,302 @@
+/*
+ * 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.testing.internal;
+
+// $Id$
+
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.osgi.deployment.deployer.DeployerService;
+import org.jboss.osgi.deployment.deployer.Deployment;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.management.MBeanProxyException;
+import org.jboss.osgi.spi.management.ManagedBundleMBean;
+import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
+import org.jboss.osgi.spi.management.ManagedServiceReference;
+import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiPackageAdmin;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
+import org.jboss.osgi.testing.OSGiTestHelper;
+import org.osgi.framework.BundleException;
+
+/**
+ * A remote implementation of the {@link OSGiRuntime}
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 25-Sep-2008
+ */
+public class RemoteRuntime extends OSGiRuntimeImpl
+{
+ private MBeanServerConnection mbeanServer;
+ private ManagedFrameworkMBean managedFramework;
+
+ public RemoteRuntime(OSGiTestHelper helper)
+ {
+ super(helper);
+ }
+
+ public OSGiBundle installBundle(String location) throws BundleException
+ {
+ try
+ {
+ // Get the bundle info from the location
+ URL bundleURL = getTestHelper().getTestArchiveURL(location);
+ BundleInfo info = BundleInfo.createBundleInfo(bundleURL);
+
+ // Create the deployment from the info
+ DeployerServiceClient deployer = new DeployerServiceClient(DeployerService.MBEAN_DEPLOYER_SERVICE);
+ Deployment dep = deployer.createDeployment(info);
+ dep.setAutoStart(false);
+
+ // Deploy the deployemnt through the DeployerService
+ deployer.deploy(new Deployment[] { dep });
+
+ String symbolicName = info.getSymbolicName();
+ String version = info.getVersion().toString();
+
+ // The remote framework uses a BundleTracker that works of an asynchronous
+ // event to register the installed bundle. It is not available immediately.
+ int timeout = 50;
+ ManagedBundleMBean bundleMBean = getRemoteFramework().getBundle(symbolicName, version);
+ while (bundleMBean == null && 0 < timeout--)
+ {
+ Thread.sleep(200);
+ bundleMBean = getRemoteFramework().getBundle(symbolicName, version);
+ }
+ if (bundleMBean == null)
+ throw new IllegalStateException("Cannot find installed bundle: " + symbolicName + "-" + version);
+
+ RemoteBundle bundle = new RemoteBundle(this, bundleMBean, location);
+ return registerBundle(location, bundle);
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (BundleException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new BundleException("Cannot install: " + location, ex);
+ }
+ }
+
+ public void deploy(String location) throws Exception
+ {
+ URL archiveURL = getTestHelper().getTestArchiveURL(location);
+ ObjectName oname = getDeployerServiceName(archiveURL);
+ DeployerServiceClient deployer = new DeployerServiceClient(oname);
+ deployer.deploy(archiveURL);
+ }
+
+ public void undeploy(String location) throws Exception
+ {
+ URL archiveURL = getTestHelper().getTestArchiveURL(location);
+ ObjectName oname = getDeployerServiceName(archiveURL);
+ DeployerServiceClient deployer = new DeployerServiceClient(oname);
+ deployer.undeploy(archiveURL);
+ }
+
+ public OSGiBundle[] getBundles()
+ {
+ try
+ {
+ Set<ManagedBundleMBean> remoteBundles = getRemoteFramework().getBundles();
+ Set<OSGiBundle> bundles = new HashSet<OSGiBundle>();
+ for (ManagedBundleMBean remoteBundle : remoteBundles)
+ bundles.add(new RemoteBundle(this, remoteBundle, null));
+
+ OSGiBundle[] bundleArr = new OSGiBundle[bundles.size()];
+ bundles.toArray(bundleArr);
+ return bundleArr;
+ }
+ catch (Exception ex)
+ {
+ throw new IllegalStateException("Cannot obtain remote bundles", ex);
+ }
+ }
+
+ public OSGiBundle getBundle(long bundleId)
+ {
+ ManagedBundleMBean bundle = getRemoteFramework().getBundle(bundleId);
+ return bundle != null ? new RemoteBundle(this, bundle, null) : null;
+ }
+
+ public OSGiServiceReference getServiceReference(String clazz)
+ {
+ ManagedServiceReference manref = getRemoteFramework().getServiceReference(clazz);
+ return manref != null ? new RemoteServiceReference(manref) : null;
+ }
+
+ public OSGiServiceReference[] getServiceReferences(String clazz, String filter)
+ {
+ OSGiServiceReference[] srefs = null;
+
+ ManagedServiceReference[] manrefs = getRemoteFramework().getServiceReferences(clazz, filter);
+ if (manrefs != null)
+ {
+ srefs = new OSGiServiceReference[manrefs.length];
+ for (int i = 0; i < manrefs.length; i++)
+ srefs[i] = new RemoteServiceReference(manrefs[i]);
+ }
+
+ return srefs;
+ }
+
+ public MBeanServerConnection getMBeanServer()
+ {
+ if (mbeanServer == null)
+ {
+ try
+ {
+ InitialContext iniCtx = getInitialContext();
+ mbeanServer = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
+ }
+ catch (NamingException ex)
+ {
+ throw new IllegalStateException("Cannot obtain MBeanServerConnection", ex);
+ }
+ }
+ return mbeanServer;
+ }
+
+ public OSGiPackageAdmin getPackageAdmin()
+ {
+ return new RemotePackageAdmin(this);
+ }
+
+ private RemoteFramework getRemoteFramework()
+ {
+ try
+ {
+ if (managedFramework == null)
+ managedFramework = MBeanProxy.get(ManagedFrameworkMBean.class, ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK, getMBeanServer());
+ }
+ catch (MBeanProxyException ex)
+ {
+ throw new RemoteFrameworkException(ex);
+ }
+
+ return new RemoteFramework()
+ {
+ public ManagedBundleMBean getBundle(String name, String version)
+ {
+ ManagedBundleMBean bundleMBean = null;
+ ObjectName oname = managedFramework.getBundle(name, version);
+ if (oname != null)
+ {
+ try
+ {
+ bundleMBean = MBeanProxy.get(ManagedBundleMBean.class, oname, getMBeanServer());
+ }
+ catch (MBeanProxyException ex)
+ {
+ throw new RemoteFrameworkException(ex);
+ }
+ }
+ return bundleMBean;
+ }
+
+ public ManagedBundleMBean getBundle(long bundleId)
+ {
+ ManagedBundleMBean bundleMBean = null;
+ ObjectName oname = managedFramework.getBundle(bundleId);
+ if (oname != null)
+ {
+ try
+ {
+ bundleMBean = MBeanProxy.get(ManagedBundleMBean.class, oname, getMBeanServer());
+ }
+ catch (MBeanProxyException ex)
+ {
+ throw new RemoteFrameworkException(ex);
+ }
+ }
+ return bundleMBean;
+ }
+
+ public Set<ManagedBundleMBean> getBundles()
+ {
+ Set<ManagedBundleMBean> remBundles = new HashSet<ManagedBundleMBean>();
+ for (ObjectName bundleOName : managedFramework.getBundles())
+ {
+ try
+ {
+ ManagedBundleMBean remBundle = MBeanProxy.get(ManagedBundleMBean.class, bundleOName, getMBeanServer());
+ remBundles.add(remBundle);
+ }
+ catch (MBeanProxyException ex)
+ {
+ throw new RemoteFrameworkException(ex);
+ }
+ }
+ return remBundles;
+ }
+
+ public ManagedServiceReference getServiceReference(String clazz)
+ {
+ return managedFramework.getServiceReference(clazz);
+ }
+
+ public ManagedServiceReference[] getServiceReferences(String clazz, String filter)
+ {
+ return managedFramework.getServiceReferences(clazz, filter);
+ }
+ };
+ }
+
+ public boolean isRemoteRuntime()
+ {
+ return true;
+ }
+
+ /**
+ * Return ObjectName of the DeployerService MBean if hte archive is a bundle
+ * otherwise if returns the ObjectName of the MainDeployer
+ */
+ private ObjectName getDeployerServiceName(URL archiveURL) throws MalformedObjectNameException
+ {
+ ObjectName oname;
+ try
+ {
+ BundleInfo.createBundleInfo(archiveURL);
+ oname = DeployerService.MBEAN_DEPLOYER_SERVICE;
+ }
+ catch (Exception e)
+ {
+ oname = new ObjectName("jboss.system:service=MainDeployer");
+ }
+ return oname;
+ }
+}
Copied: projects/jboss-osgi/projects/bundles/husky/trunk/src/test (from rev 96948, projects/jboss-osgi/projects/bundles/husky/trunk/testsuite/src/test)
More information about the jboss-osgi-commits
mailing list