tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r692666 - in /tuscany/java/sca/modules/extensibility-equinox/src: main/java/org/apache/tuscany/sca/extensibility/equinox/ test/java/org/apache/tuscany/sca/extensibility/equinox/
Date Sat, 06 Sep 2008 15:43:28 GMT
Author: jsdelfino
Date: Sat Sep  6 08:43:27 2008
New Revision: 692666

URL: http://svn.apache.org/viewvc?rev=692666&view=rev
Log:
Minor code cleanup. Added class comments and ref/date tags. Moved test class to src/test/java.

Added:
    tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHostTestCase.java
    tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java
Modified:
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/BundleFileWrapperFactory.java
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHookConfigurator.java
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/URLClassLoadingHook.java
    tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java

Modified: tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/BundleFileWrapperFactory.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/BundleFileWrapperFactory.java?rev=692666&r1=692665&r2=692666&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/BundleFileWrapperFactory.java
(original)
+++ tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/BundleFileWrapperFactory.java
Sat Sep  6 08:43:27 2008
@@ -28,8 +28,10 @@
 import org.eclipse.osgi.baseadaptor.hooks.BundleFileWrapperFactoryHook;
 
 /**
- * Bundle file wrapper factory that converts plain jars into OSGi bundles 
- */
+ * A bundle file wrapper that we can use later to adjust to different bundle schemes.
+ *
+ * @version $Rev: $ $Date: $
+*/
 public class BundleFileWrapperFactory implements BundleFileWrapperFactoryHook, BundleFileFactoryHook
{
 
     public BundleFile createBundleFile(Object content, BaseData data, boolean base) throws
IOException {

Modified: tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHookConfigurator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHookConfigurator.java?rev=692666&r1=692665&r2=692666&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHookConfigurator.java
(original)
+++ tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHookConfigurator.java
Sat Sep  6 08:43:27 2008
@@ -23,11 +23,17 @@
 import org.eclipse.osgi.baseadaptor.HookRegistry;
 
 /**
- * Hook Configurator for Equinox
+ * Hook Configurator for Equinox.
+ *
+ * @version $Rev: $ $Date: $
  */
 public class EquinoxHookConfigurator implements HookConfigurator {
+    
     public void addHooks(HookRegistry registry) {
+        
+        // Register our BundleFileWrapperFactory and ClassLoading hooks
         registry.addBundleFileWrapperFactoryHook(new BundleFileWrapperFactory());
+        registry.addClassLoadingHook(new URLClassLoadingHook());
     }
 
 }

Modified: tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java?rev=692666&r1=692665&r2=692666&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
(original)
+++ tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
Sat Sep  6 08:43:27 2008
@@ -45,6 +45,8 @@
 
 /**
  * The ServiceDiscoverer that find META-INF/services/... in installed bundles
+ *
+ * @version $Rev: $ $Date: $
  */
 public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
     private static final Logger logger = Logger.getLogger(EquinoxServiceDiscoverer.class.getName());

Modified: tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java?rev=692666&r1=692665&r2=692666&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
(original)
+++ tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
Sat Sep  6 08:43:27 2008
@@ -25,6 +25,8 @@
 
 /**
  * The Bundle Activator that creates the Equinox-based service discoverer 
+ *
+ * @version $Rev: $ $Date: $
  */
 public class EquinoxServiceDiscoveryActivator implements BundleActivator {
     private static BundleContext bundleContext;

Modified: tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/URLClassLoadingHook.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/URLClassLoadingHook.java?rev=692666&r1=692665&r2=692666&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/URLClassLoadingHook.java
(original)
+++ tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/URLClassLoadingHook.java
Sat Sep  6 08:43:27 2008
@@ -32,67 +32,45 @@
 import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
 
 /**
- * 
+ * A URLClassLoadingHook that enables Tuscany bundles to load classes from non-OSGi third
+ * party JARs.
+ *
+ * @version $Rev: $ $Date: $
  */
 public class URLClassLoadingHook implements ClassLoadingHook {
 
-    /* (non-Javadoc)
-     * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#addClassPathEntry(java.util.ArrayList,
java.lang.String, org.eclipse.osgi.baseadaptor.loader.ClasspathManager, org.eclipse.osgi.baseadaptor.BaseData,
java.security.ProtectionDomain)
-     */
     public boolean addClassPathEntry(ArrayList cpEntries,
                                      String cp,
                                      ClasspathManager hostmanager,
                                      BaseData sourcedata,
                                      ProtectionDomain sourcedomain) {
-        // TODO Auto-generated method stub
         return false;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#createClassLoader(java.lang.ClassLoader,
org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate, org.eclipse.osgi.framework.adaptor.BundleProtectionDomain,
org.eclipse.osgi.baseadaptor.BaseData, java.lang.String[])
-     */
     public BaseClassLoader createClassLoader(ClassLoader parent,
                                              ClassLoaderDelegate delegate,
                                              BundleProtectionDomain domain,
                                              BaseData data,
                                              String[] bundleclasspath) {
-        // TODO Auto-generated method stub
         return null;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#findLibrary(org.eclipse.osgi.baseadaptor.BaseData,
java.lang.String)
-     */
     public String findLibrary(BaseData data, String libName) {
-        // TODO Auto-generated method stub
         return null;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#getBundleClassLoaderParent()
-     */
     public ClassLoader getBundleClassLoaderParent() {
-        // TODO Auto-generated method stub
         return null;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#initializedClassLoader(org.eclipse.osgi.baseadaptor.loader.BaseClassLoader,
org.eclipse.osgi.baseadaptor.BaseData)
-     */
     public void initializedClassLoader(BaseClassLoader baseClassLoader, BaseData data) {
-        // TODO Auto-generated method stub
-
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#processClass(java.lang.String,
byte[], org.eclipse.osgi.baseadaptor.loader.ClasspathEntry, org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry,
org.eclipse.osgi.baseadaptor.loader.ClasspathManager)
-     */
     public byte[] processClass(String name,
                                byte[] classbytes,
                                ClasspathEntry classpathEntry,
                                BundleEntry entry,
                                ClasspathManager manager) {
-        // TODO Auto-generated method stub
         return null;
     }
 

Added: tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHostTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHostTestCase.java?rev=692666&view=auto
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHostTestCase.java
(added)
+++ tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHostTestCase.java
Sat Sep  6 08:43:27 2008
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.extensibility.equinox;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Test start/stop the Equinox runtime.
+ * 
+ * @version $Rev: $ $Date: $
+ */
+public class EquinoxHostTestCase {
+    @Test
+    public void testStartThenStop() {
+        TestEquinoxHost host = new TestEquinoxHost();
+        BundleContext context = host.start();
+        Assert.assertNotNull(context);
+        for (Bundle b : context.getBundles()) {
+            System.out.println(toString(b, false));
+        }
+        host.stop();
+    }
+
+    @Test
+    public void testStartTwice() {
+        TestEquinoxHost host = new TestEquinoxHost();
+        host.start();
+        try {
+            host.start();
+            Assert.fail();
+        } catch (IllegalStateException e) {
+            Assert.assertTrue(IllegalStateException.class.isInstance(e.getCause()));
+        } finally {
+            host.stop();
+        }
+    }
+
+    public static String toString(Bundle b, boolean verbose) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
+        int s = b.getState();
+        if ((s & Bundle.UNINSTALLED) != 0) {
+            sb.append(" UNINSTALLED");
+        }
+        if ((s & Bundle.INSTALLED) != 0) {
+            sb.append(" INSTALLED");
+        }
+        if ((s & Bundle.RESOLVED) != 0) {
+            sb.append(" RESOLVED");
+        }
+        if ((s & Bundle.STARTING) != 0) {
+            sb.append(" STARTING");
+        }
+        if ((s & Bundle.STOPPING) != 0) {
+            sb.append(" STOPPING");
+        }
+        if ((s & Bundle.ACTIVE) != 0) {
+            sb.append(" ACTIVE");
+        }
+
+        sb.append(" ").append(b.getLocation());
+        if (verbose) {
+            Dictionary<Object, Object> dict = b.getHeaders();
+            Enumeration<Object> keys = dict.keys();
+            while (keys.hasMoreElements()) {
+                Object key = keys.nextElement();
+                sb.append(" ").append(key).append("=").append(dict.get(key));
+            }
+        }
+        return sb.toString();
+    }
+}

Modified: tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java?rev=692666&r1=692665&r2=692666&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java
(original)
+++ tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java
Sat Sep  6 08:43:27 2008
@@ -40,12 +40,14 @@
 import org.osgi.framework.BundleContext;
 
 /**
+ * Test the Equinox service discoverer.
  * 
+ * @version $Rev: $ $Date: $
  */
 public class EquinoxServiceDiscovererTestCase {
     private static EquinoxServiceDiscoverer discoverer;
     private static Bundle testBundle;
-    private static EquinoxOSGiHost host;
+    private static TestEquinoxHost host;
 
     private static String getState(Bundle b) {
         StringBuffer sb = new StringBuffer();
@@ -77,7 +79,7 @@
      */
     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
-        host = new EquinoxOSGiHost();
+        host = new TestEquinoxHost();
         BundleContext context = host.start();
 
         InputStream is = EquinoxServiceDiscovererTestCase.class.getResourceAsStream("/test-bundle.jar");

Added: tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java?rev=692666&view=auto
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java
(added)
+++ tuscany/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java
Sat Sep  6 08:43:27 2008
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.extensibility.equinox;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.eclipse.core.runtime.adaptor.LocationManager;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A test host that starts/stops Equinox.
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class TestEquinoxHost  {
+
+    private final static String systemPackages =
+        "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0,
"
+            + "org.osgi.service.startlevel; version=1.0.0, "
+            + "org.osgi.service.url; version=1.0.0, "
+            + "org.osgi.util.tracker; version=1.3.2, "
+            + "javax.xml, "
+            + "javax.xml.datatype, "
+            + "javax.xml.namespace, "
+            + "javax.xml.parsers, "
+            + "javax.xml.transform, "
+            + "javax.xml.transform.dom, "
+            + "javax.xml.transform.sax, "
+            + "javax.xml.transform.stream, "
+            + "javax.xml.validation, "
+            + "javax.xml.xpath, "
+            // Force the classes to be imported from the system bundle
+            + "javax.xml.stream, "
+            + "javax.xml.stream.util, "
+            + "javax.sql,"
+            + "org.w3c.dom, "
+            + "org.xml.sax, "
+            + "org.xml.sax.ext, "
+            + "org.xml.sax.helpers, "
+            + "javax.security.auth, "
+            + "javax.security.cert, "
+            + "javax.security.auth.login, "
+            + "javax.security.auth.callback, "
+            + "javax.naming, "
+            + "javax.naming.spi, "
+            + "javax.naming.directory, "
+            + "javax.management, "
+            + "javax.imageio, "
+            + "sun.misc, "
+            + "javax.net, "
+            + "javax.net.ssl, "
+            + "javax.crypto, "
+            + "javax.rmi, "
+            + "javax.transaction, "
+            + "javax.transaction.xa";
+
+    public BundleContext start() {
+        try {
+            return startup();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    public void stop() {
+        try {
+            shutdown();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private BundleContext startup() throws Exception {
+        String args[] = {};
+        Map<Object, Object> props = new HashMap<Object, Object>();
+        props.put("org.osgi.framework.system.packages", systemPackages);
+        props.put(EclipseStarter.PROP_CLEAN, "true");
+        props.put(LocationManager.PROP_INSTANCE_AREA, new File("target/workspace").toURI().toString());
+        props.put(LocationManager.PROP_INSTALL_AREA, new File("target/eclipse").toURI().toString());
+        EclipseStarter.setInitialProperties(props);
+        BundleContext context = EclipseStarter.startup(args, null);
+        return context;
+    }
+
+    private void shutdown() throws Exception {
+        EclipseStarter.shutdown();
+    }
+
+}



Mime
View raw message