[jboss-svn-commits] JBoss Common SVN: r4547 - in arquillian/trunk: bundle and 8 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jun 24 04:47:59 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-06-24 04:47:58 -0400 (Thu, 24 Jun 2010)
New Revision: 4547

Added:
   arquillian/trunk/bundle/
   arquillian/trunk/bundle/pom.xml
   arquillian/trunk/bundle/src/
   arquillian/trunk/bundle/src/main/
   arquillian/trunk/bundle/src/main/java/
   arquillian/trunk/bundle/src/main/java/org/
   arquillian/trunk/bundle/src/main/java/org/jboss/
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/AbstractConnector.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/ArquillianActivator.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicFailure.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicRequest.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicResponse.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Connector.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Failure.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnector.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnectorMBean.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Request.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Response.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/SocketConnector.java
   arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Util.java
Modified:
   arquillian/trunk/.gitignore
   arquillian/trunk/containers/osgi-embedded/pom.xml
   arquillian/trunk/pom.xml
Log:
osgi: Add bundle module that contains husky impl - not functional

Modified: arquillian/trunk/.gitignore
===================================================================
--- arquillian/trunk/.gitignore	2010-06-24 08:46:51 UTC (rev 4546)
+++ arquillian/trunk/.gitignore	2010-06-24 08:47:58 UTC (rev 4547)
@@ -6,6 +6,8 @@
 api/target
 build/.project
 build/.settings/
+bundle/.classpath
+bundle/target
 containers/glassfish-embedded-30/target
 containers/jbossas-embedded-60/target
 containers/jbossas-local-51/target
@@ -65,4 +67,4 @@
 testenrichers/ejb/target
 testenrichers/resource/.classpath
 testenrichers/resource/target
-testng/target
\ No newline at end of file
+testng/target

Added: arquillian/trunk/bundle/pom.xml
===================================================================
--- arquillian/trunk/bundle/pom.xml	                        (rev 0)
+++ arquillian/trunk/bundle/pom.xml	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <!-- Parent -->
+  <parent>
+    <groupId>org.jboss.arquillian</groupId>
+    <artifactId>arquillian-build</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+
+  <!-- Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Configuration -->
+  <artifactId>arquillian-bundle</artifactId>
+  <name>Arquillian Bundle</name>
+  <description>Arquillian OSGi Bundle</description>
+  <packaging>bundle</packaging>
+
+  <!-- Properties -->
+  <properties>
+    <!-- Versioning -->
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
+            <Bundle-Activator>org.jboss.arquillian.bundle.ArquillianActivator</Bundle-Activator>
+            <Export-Package>
+              org.jboss.arquillian.bundle;version=${version},
+            </Export-Package>
+            <Import-Package>
+              javax.management*,
+              javax.naming,
+              javax.xml.parsers, 
+              org.w3c.dom,
+              
+              org.osgi.framework;version="[1.5,2.0)",
+              org.osgi.jmx.framework;version="[1.0,2.0)",
+              org.osgi.util.tracker;version="[1.4,2.0)",
+            </Import-Package>
+            <Private-Package>
+            </Private-Package>
+            <Embed-Transitive>true</Embed-Transitive>
+            <Embed-Dependency>
+              arquillian-api;inline=false,
+              arquillian-impl-base;inline=false,
+              arquillian-junit;inline=false,
+              arquillian-spi;inline=false,
+              shrinkwrap-api;inline=false,
+              shrinkwrap-impl-base;inline=false,
+              shrinkwrap-spi;inline=false,
+              junit;inline=false,
+            </Embed-Dependency>
+            <_exportcontents>
+            </_exportcontents>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+
+    <!-- PluginManagement -->
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>maven-bundle-plugin</artifactId>
+          <version>2.1.0</version>
+          <extensions>true</extensions>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+
+  <!-- Dependencies -->
+  <dependencies>
+    <dependency>
+      <groupId>org.jboss.arquillian</groupId>
+      <artifactId>arquillian-junit</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+</project>
+

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/AbstractConnector.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/AbstractConnector.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/AbstractConnector.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,118 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * An abstract {@link Connector} implementation 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public abstract class AbstractConnector implements Connector
+{
+   // Provide logging
+   private static final Logger log = Logger.getLogger(AbstractConnector.class.getName());
+   
+   private BundleContext context;
+
+   public AbstractConnector(BundleContext context)
+   {
+      this.context = context;
+   }
+
+   public BundleContext getBundleContext()
+   {
+      return context;
+   }
+
+   protected void start() throws Exception
+   {
+   }
+
+   protected void stop() throws Exception
+   {
+   }
+
+   public Response process(final Request req) throws Throwable
+   {
+      throw new IllegalStateException("Cannot find listener to handle: " + req.getClassName());
+   }
+
+   protected InputStream process(InputStream reqStream)
+   {
+      Request request = null;
+      Response response = null;
+      try
+      {
+         // Unmarshall the Request
+         ObjectInputStream ois = new ObjectInputStream(reqStream);
+         request = (Request)ois.readObject();
+
+         log.fine("Start invoke: " + request);
+         
+         // Field the request through the abstract connector
+         response = process(request);
+      }
+      catch (Throwable th)
+      {
+         response = new BasicResponse();
+         BasicFailure failure = new BasicFailure(th.getMessage(), th);
+         if (request != null)
+         {
+            failure.setClassName(request.getClassName());
+            failure.setMethodName(request.getMethodName());
+         }
+         response.addFailure(failure);
+      }
+      finally
+      {
+         log.fine("End invoke: " + response);
+      }
+
+      // Marshall the Response
+      try
+      {
+         ByteArrayOutputStream baos = new ByteArrayOutputStream();
+         ObjectOutputStream oos = new ObjectOutputStream(baos);
+         oos.writeObject(response);
+         oos.close();
+
+         return new ByteArrayInputStream(baos.toByteArray());
+      }
+      catch (IOException ex)
+      {
+         throw new IllegalStateException("Cannot marshall response", ex);
+      }
+   }
+}
\ No newline at end of file

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/ArquillianActivator.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/ArquillianActivator.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/ArquillianActivator.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,77 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleListener;
+
+/**
+ * This is the Husky {@link BundleActivator}.
+ * 
+ * It unconditionally starts the {@link JMXConnector}.
+ * 
+ * If the {@link SocketConnector#PROP_SOCKET_CONNECTOR_HOST} and 
+ * {@link SocketConnector#PROP_SOCKET_CONNECTOR_PORT} properites are set it also
+ * starts the {@link SocketConnector}.
+ * 
+ * Finally it starts the {@link HuskyExtender}, which is a {@link BundleListener}
+ * that looks for manifest headers called  {@link ManifestProcessor#HEADER_TEST_PACKAGE}. 
+ * 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 17-May-2009
+ */
+public class ArquillianActivator implements BundleActivator
+{
+   private SocketConnector socketConnector;
+   private JMXConnector jmxConnector;
+
+   public void start(BundleContext context) throws Exception
+   {
+      jmxConnector = new JMXConnector(context);
+      jmxConnector.start();
+
+      if (SocketConnector.isRemoteConnection(context))
+      {
+         socketConnector = new SocketConnector(context);
+         socketConnector.start();
+      }
+   }
+
+   public void stop(BundleContext context) throws Exception
+   {
+      if (socketConnector != null)
+      {
+         socketConnector.stop();
+         socketConnector = null;
+      }
+
+      if (jmxConnector != null)
+      {
+         jmxConnector.stop();
+         jmxConnector = null;
+      }
+   }
+}
\ No newline at end of file

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicFailure.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicFailure.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicFailure.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,76 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id: BasicResponse.java 91197 2009-07-14 09:48:24Z thomas.diesler at jboss.com $
+
+/**
+ * A basic {@link Failure} implementation. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public class BasicFailure implements Failure
+{
+   private static final long serialVersionUID = 1L;
+
+   private String message;
+   private Throwable exception;
+   private String className;
+   private String methodName;
+   
+   public BasicFailure(String message, Throwable exception)
+   {
+      this.message = message;
+      this.exception = exception;
+   }
+
+   public Throwable getException()
+   {
+      return exception;
+   }
+
+   public String getMessage()
+   {
+      return message;
+   }
+
+   public String getClassName()
+   {
+      return className;
+   }
+
+   public void setClassName(String className)
+   {
+      this.className = className;
+   }
+
+   public String getMethodName()
+   {
+      return methodName;
+   }
+
+   public void setMethodName(String methodName)
+   {
+      this.methodName = methodName;
+   }
+}

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicRequest.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicRequest.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicRequest.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -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.arquillian.bundle;
+
+// $Id$
+
+/**
+ * A basic {@link Request} implementation. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public class BasicRequest implements Request
+{
+   private static final long serialVersionUID = 1L;
+   
+   private String className;
+   private String methodName;
+
+   public BasicRequest(String className, String methodName)
+   {
+      if (className == null)
+         throw new IllegalArgumentException("Null className");
+      if (methodName == null)
+         throw new IllegalArgumentException("Null methodName");
+      
+      this.className = className;
+      this.methodName = methodName;
+   }
+
+   public String getClassName()
+   {
+      return className;
+   }
+
+   public String getMethodName()
+   {
+      return methodName;
+   }
+
+   @Override
+   public String toString()
+   {
+      String testName = className;
+      int dotIndex = testName.lastIndexOf(".");
+      if (dotIndex > 0)
+         testName = testName.substring(dotIndex + 1);
+      testName = testName + "." + methodName;
+      return "BasicRequest[" + testName + "]";
+   }
+}

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicResponse.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicResponse.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/BasicResponse.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,63 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A basic {@link Response} implementation. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public class BasicResponse implements Response
+{
+   private static final long serialVersionUID = 1L;
+
+   private List<Failure> failures = new ArrayList<Failure>();
+
+   public List<Failure> getFailures()
+   {
+      return Collections.unmodifiableList(failures);
+   }
+
+   public void addFailure(Failure failure)
+   {
+      failures.add(failure);
+   }
+
+   @Override
+   public String toString()
+   {
+      StringBuffer msgs = new StringBuffer();
+      for (int i = 0; i < failures.size(); i++)
+      {
+         Failure f = failures.get(i);
+         msgs.append((i > 0 ? "," : "") + f.getMessage());
+      }
+      return "BasicResponse[" + msgs + "]";
+   }
+}

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Connector.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Connector.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Connector.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,45 @@
+/*
+ * 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.arquillian.bundle;
+
+//$Id$
+
+/**
+ * A Connector is the receiving side of a test request.
+ * 
+ * It processes the test request by dispatching it to one of
+ * the associated {@link PackageListener}s.
+ * 
+ * It is an error if no {@link PackageListener} can handle the 
+ * incomming test request.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public interface Connector
+{
+   /**
+    * Handles the test request by dispatching to one of the 
+    * associated {@link PackageListener}s. 
+    */
+   Response process(Request req) throws Throwable;
+}

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Failure.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Failure.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Failure.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,59 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import java.io.Serializable;
+
+
+
+/**
+ * An abstraction of a test failure that is associated with a test {@link Response}. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public interface Failure extends Serializable
+{
+   /**
+    * Get the name of the test class that failed
+    */
+   String getClassName();
+   
+   /**
+    * Get the name of the test method that failed
+    */
+   String getMethodName();
+   
+   /**
+    * Get the test failure message
+    */
+   String getMessage();
+   
+   /**
+    * Get the exceoption that caused the failure.
+    * In case of a failure due to an assertion, this will be 
+    * RuntimeException or Error thrown by the test framework. 
+    */
+   Throwable getException();
+}
\ No newline at end of file

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnector.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnector.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnector.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,133 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * The JMX connector is a {@link Connector} that process Husky 
+ * requests via an JMX invocation. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 17-May-2009
+ */
+public class JMXConnector extends AbstractConnector implements JMXConnectorMBean
+{
+   // Provide Logging
+   private static final Logger logger = Logger.getLogger(JMXConnector.class.getName());
+
+   /** The ObjectName for this service: jboss.osgi.husky:service=jmx-connector */
+   public static ObjectName OBJECT_NAME;
+   static
+   {
+      try
+      {
+         OBJECT_NAME = ObjectName.getInstance("jboss.osgi.husky:service=jmx-connector");
+      }
+      catch (MalformedObjectNameException ex)
+      {
+         // ignore
+      }
+   }
+
+   public JMXConnector(BundleContext context)
+   {
+      super(context);
+   }
+
+   @Override
+   public void start() throws Exception
+   {
+      super.start();
+      
+      MBeanServer mbeanServer = getMBeanServer();
+      mbeanServer.registerMBean(this, OBJECT_NAME);
+
+      Properties props = new Properties();
+      props.setProperty("transport", "jmx");
+      getBundleContext().registerService(Connector.class.getName(), this, props);
+
+      logger.info("JMXConnector registered: " + OBJECT_NAME);
+   }
+
+   @Override
+   public void stop() throws Exception
+   {
+      super.stop();
+      
+      MBeanServer mbeanServer = getMBeanServer();
+      if (mbeanServer.isRegistered(OBJECT_NAME))
+         mbeanServer.unregisterMBean(OBJECT_NAME);
+   }
+
+   @Override
+   public InputStream process(InputStream reqStream)
+   {
+      return super.process(reqStream);
+   }
+
+   private MBeanServer getMBeanServer()
+   {
+      MBeanServer mbeanServer = null;
+      BundleContext context = getBundleContext();
+
+      // Check if there is an MBeanServer service already
+      ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
+      if (sref != null)
+      {
+         mbeanServer = (MBeanServer)context.getService(sref);
+         logger.fine("Found MBeanServer fom service: " + mbeanServer.getDefaultDomain());
+      }
+      else
+      {
+         ArrayList<MBeanServer> serverArr = MBeanServerFactory.findMBeanServer(null);
+         if (serverArr.size() > 1)
+            logger.warning("Multiple MBeanServer instances: " + serverArr);
+
+         if (serverArr.size() > 0)
+         {
+            mbeanServer = serverArr.get(0);
+            logger.fine("Found MBeanServer: " + mbeanServer.getDefaultDomain());
+         }
+
+         if (mbeanServer == null)
+         {
+            logger.fine("No MBeanServer, create one ...");
+            mbeanServer = MBeanServerFactory.createMBeanServer();
+         }
+      }
+      return mbeanServer;
+   }
+}
\ No newline at end of file

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnectorMBean.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnectorMBean.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/JMXConnectorMBean.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -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.arquillian.bundle;
+
+//$Id$
+
+import java.io.InputStream;
+
+/**
+ * The management interface of the {@link JMXConnector}.
+ * 
+ * @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);
+}
\ No newline at end of file

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Request.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Request.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Request.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,45 @@
+/*
+ * 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.arquillian.bundle;
+
+//$Id$
+
+import java.io.Serializable;
+
+/**
+ * An abstraction of a test request. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public interface Request extends Serializable
+{
+   /**
+    * Get the test case name 
+    */
+   String getClassName();
+   
+   /**
+    * Get the test method name 
+    */
+   String getMethodName();
+}

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Response.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Response.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Response.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,49 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import java.io.Serializable;
+import java.util.List;
+
+
+
+/**
+ * An abstraction of a test response. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public interface Response extends Serializable
+{
+   /**
+    * Get the list of test failures
+    * @return an empty list if the test was successful
+    */
+   List<Failure> getFailures();
+   
+   /**
+    * Add a failure to the response
+    */
+   void addFailure(Failure failure);
+}

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/SocketConnector.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/SocketConnector.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/SocketConnector.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,192 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The socket connector is a {@link Connector} that process Husky 
+ * requests via an socket invocations.
+ * 
+ * Both, the test runner process as well as the remote target process must 
+ * configure the properties {@link #PROP_SOCKET_CONNECTOR_HOST} and 
+ * {@link #PROP_SOCKET_CONNECTOR_PORT}. 
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 17-May-2009
+ */
+public class SocketConnector extends AbstractConnector
+{
+   // Provide Logging
+   private static final Logger logger = Logger.getLogger(SocketConnector.class.getName());
+   
+   /** The Husky socket connector host poperty: 'org.jboss.osgi.husky.runtime.connector.host' */
+   public static final String PROP_SOCKET_CONNECTOR_HOST = Connector.class.getName().toLowerCase() + ".host";
+   /** The Husky socket connector port poperty: 'org.jboss.osgi.husky.runtime.connector.port' */
+   public static final String PROP_SOCKET_CONNECTOR_PORT = Connector.class.getName().toLowerCase() + ".port";
+   
+   private ServiceRegistration sreg;
+   private ListenerThread listenerThread;
+
+   public SocketConnector(BundleContext context)
+   {
+      super(context);
+   }
+
+   public static boolean isRemoteConnection(BundleContext context)
+   {
+      return getHost(context) != null && getPort(context) != null;
+   }
+
+   private static String getPort(BundleContext context)
+   {
+      String port = context.getProperty(PROP_SOCKET_CONNECTOR_PORT);
+      return port;
+   }
+
+   private static String getHost(BundleContext context)
+   {
+      String host = context.getProperty(PROP_SOCKET_CONNECTOR_HOST);
+      return host;
+   }
+
+   @Override
+   public void start() throws Exception
+   {
+      super.start();
+      
+      BundleContext context = getBundleContext();
+      String host = getHost(context);
+      String port = getPort(context);
+
+      Properties props = new Properties();
+      props.setProperty("transport", "socket");
+      props.setProperty("host", host);
+      props.setProperty("port", port);
+
+      listenerThread = new ListenerThread(host, new Integer(port));
+      listenerThread.start();
+
+      sreg = context.registerService(Connector.class.getName(), this, props);
+      logger.info("SocketConnector registered: " + props);
+   }
+
+   @Override
+   public void stop() throws Exception
+   {
+      super.stop();
+      
+      if (sreg != null)
+         sreg.unregister();
+
+      if (listenerThread != null)
+         listenerThread.stopListener();
+   }
+
+   class ListenerThread extends Thread
+   {
+      private ServerSocket serverSocket;
+
+      public ListenerThread(String host, int port)
+      {
+         super("ConnectorThread");
+         try
+         {
+            serverSocket = new ServerSocket();
+            serverSocket.bind(new InetSocketAddress(host, port));
+         }
+         catch (IOException ex)
+         {
+            throw new IllegalStateException("Cannot create server socket", ex);
+         }
+      }
+
+      public void stopListener()
+      {
+         try
+         {
+            logger.fine("Stop SocketConnector");
+            serverSocket.close();
+         }
+         catch (IOException ex)
+         {
+            // ignore
+         }
+      }
+
+      @Override
+      public void run()
+      {
+         while (serverSocket.isClosed() == false)
+         {
+            Socket socket = null;
+            try
+            {
+               logger.fine("Waiting for connection ...");
+               socket = serverSocket.accept();
+               logger.fine("Connection accepted");
+            }
+            catch (IOException ex)
+            {
+               if (serverSocket.isClosed())
+                  break;
+            }
+
+            if (socket != null)
+            {
+               try
+               {
+                  InputStream resStream = process(socket.getInputStream());
+                  Util.copyStream(resStream, socket.getOutputStream());
+               }
+               catch (Exception ex)
+               {
+                  logger.log(Level.SEVERE, "Cannot process request", ex);
+               }
+               finally
+               {
+                  try
+                  {
+                     socket.close();
+                  }
+                  catch (IOException ex)
+                  {
+                     logger.log(Level.SEVERE, "Cannot close socket", ex);
+                  }
+               }
+            }
+         }
+      }
+   }
+}
\ No newline at end of file

Added: arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Util.java
===================================================================
--- arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Util.java	                        (rev 0)
+++ arquillian/trunk/bundle/src/main/java/org/jboss/arquillian/bundle/Util.java	2010-06-24 08:47:58 UTC (rev 4547)
@@ -0,0 +1,106 @@
+/*
+ * 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.arquillian.bundle;
+
+// $Id$
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.util.Properties;
+
+/**
+ * Loads the configured test {@link Bridge} instance.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public abstract class Util
+{
+   // Load an instance for a given class name.
+   // Use the SomeObject(Properties) ctor if present.
+   public static Object loadInstance(String className, Properties props)
+   {
+      // net bridge class
+      Class<?> instanceClass = loadClass(className);
+
+      // get instance with properties
+      Object instance = null;
+      try
+      {
+         Constructor<?> ctor = instanceClass.getConstructor(Properties.class);
+         instance = ctor.newInstance(props);
+      }
+      catch (NoSuchMethodException ex)
+      {
+         // ignore
+      }
+      catch (Exception ex)
+      {
+         throw new IllegalStateException("Cannot load: " + className, ex);
+      }
+
+      // get instance with default ctor
+      if (instance == null)
+      {
+         try
+         {
+            instance = instanceClass.newInstance();
+         }
+         catch (Exception ex)
+         {
+            throw new IllegalStateException("Cannot load: " + className, ex);
+         }
+      }
+
+      return instance;
+   }
+
+   // Load a given class name.
+   public static Class<?> loadClass(String className)
+   {
+      // net bridge class
+      Class<?> instanceClass;
+      try
+      {
+         instanceClass = Class.forName(className);
+      }
+      catch (ClassNotFoundException ex)
+      {
+         throw new IllegalStateException("Cannot load: " + className, ex);
+      }
+
+      return instanceClass;
+   }
+   
+   public static void copyStream(InputStream in, OutputStream out) throws IOException
+   {
+      byte[] bytes = new byte[1024];
+      int read = in.read(bytes);
+      while (read > 0)
+      {
+         out.write(bytes, 0, read);
+         read = in.read(bytes);
+      }
+   }
+}

Modified: arquillian/trunk/containers/osgi-embedded/pom.xml
===================================================================
--- arquillian/trunk/containers/osgi-embedded/pom.xml	2010-06-24 08:46:51 UTC (rev 4546)
+++ arquillian/trunk/containers/osgi-embedded/pom.xml	2010-06-24 08:47:58 UTC (rev 4547)
@@ -53,6 +53,11 @@
       <groupId>org.jboss.osgi</groupId>
       <artifactId>jboss-osgi-spi</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
     
     <dependency>
       <groupId>javax.inject</groupId>

Modified: arquillian/trunk/pom.xml
===================================================================
--- arquillian/trunk/pom.xml	2010-06-24 08:46:51 UTC (rev 4546)
+++ arquillian/trunk/pom.xml	2010-06-24 08:47:58 UTC (rev 4547)
@@ -61,6 +61,7 @@
 
     <module>frameworks</module>
     <module>examples</module>
+    <module>bundle</module>
 
     <module>doc/reference</module>
 </modules>



More information about the jboss-svn-commits mailing list