You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/06/11 23:03:38 UTC
svn commit: r953866 - in
/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb: ./
recipes/ src/org/apache/felix/framework/vb/
src/org/apache/felix/framework/vb/b001/
src/org/apache/felix/framework/vb/b002/ src/org/apache/felix/framework/vb...
Author: rickhall
Date: Fri Jun 11 21:03:38 2010
New Revision: 953866
URL: http://svn.apache.org/viewvc?rev=953866&view=rev
Log:
Further improvements to virtual bundle tests, added client bundle.
Added:
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b003.bnd
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b003/
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b003/Activator.java
Modified:
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarFileClassLoader.java
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/Activator.java
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/ServiceImpl.java
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/service/Service.java
Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd?rev=953866&r1=953865&r2=953866&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd (original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd Fri Jun 11 21:03:38 2010
@@ -1,8 +1,8 @@
--runvm = -Xdebug, "-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n"
+-runvm = -Xdebug, "-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y"
Private-Package: ${p}
Include-Resource: \
- vb.b001.jar, vb.b002.jar
+ vb.b001.jar, vb.b002.jar, vb.b003.jar
-buildpath: \
org.apache.felix.framework; version=3.1.0, \
Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b003.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b003.bnd?rev=953866&view=auto
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b003.bnd (added)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b003.bnd Fri Jun 11 21:03:38 2010
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: org.apache.felix.framework.vb.b003
+Bundle-Activator: org.apache.felix.framework.vb.b003.Activator
+Private-Package: org.apache.felix.framework.vb.b003
Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java?rev=953866&r1=953865&r2=953866&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java (original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java Fri Jun 11 21:03:38 2010
@@ -31,16 +31,15 @@ public class TestVirtualBundle extends F
private Bundle m_bundleC = null;
private Bundle m_bundleD = null;
- public void testVBResolve() throws Exception
+ public void testVirtualBundleStart() throws Exception
{
InputStream is = null;
try
{
- // Install and start handler bundle, which will install a
- // virtual bundle.
+ // Install and start handler bundle, which will install a virtual bundle.
is = this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar");
- m_bundleA = getBundleContext().installBundle("resolver.b001.jar", is);
+ m_bundleA = getBundleContext().installBundle("vb.b001.jar", is);
int before = getBundleContext().getBundles().length;
try
@@ -49,30 +48,162 @@ public class TestVirtualBundle extends F
}
catch (BundleException ex)
{
- assertTrue("Bundle should resolve", false);
+ assertTrue("Handler should start", false);
}
assertEquals("A virtual bundle should have been installed.",
before + 1, getBundleContext().getBundles().length);
// Get the virtual bundle.
- Bundle vb = getBundle("org.apache.felix.framework.vb.b002");
- assertEquals("Virtual bundle should be INSTALLED", Bundle.INSTALLED, vb.getState());
+ m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+ assertEquals("Virtual bundle should be INSTALLED", Bundle.INSTALLED, m_bundleB.getState());
// Resolve the virtual bundle.
PackageAdmin pa = getPackageAdmin();
- pa.resolveBundles(new Bundle[] { vb });
- assertEquals("Virtual bundle should be RESOLVED", Bundle.RESOLVED, vb.getState());
+ pa.resolveBundles(new Bundle[] { m_bundleB });
+ assertEquals("Virtual bundle should be RESOLVED", Bundle.RESOLVED, m_bundleB.getState());
// Resolve the virtual bundle.
try
{
- vb.start();
+ m_bundleB.start();
+ assertEquals("Virtual bundle should be ACTIVE", Bundle.ACTIVE, m_bundleB.getState());
}
catch (BundleException ex)
{
assertTrue("Virtual bundle should start: " + ex, false);
}
- assertEquals("Virtual bundle should be ACTIVE", Bundle.ACTIVE, vb.getState());
+
+ // Install and start client bundle.
+ is = this.getClass().getClassLoader().getResourceAsStream("vb.b003.jar");
+ m_bundleC = getBundleContext().installBundle("vb.b003.jar", is);
+ m_bundleC.start();
+ }
+ finally
+ {
+ cleanup();
+ }
+ }
+
+ public void testVirtualBundleRestart001() throws Exception
+ {
+ InputStream is = null;
+
+ try
+ {
+ // Install and start handler bundle, which will install a virtual bundle.
+ is = this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar");
+ m_bundleA = getBundleContext().installBundle("vb.b001.jar", is);
+
+ int before = getBundleContext().getBundles().length;
+ try
+ {
+ m_bundleA.start();
+ }
+ catch (BundleException ex)
+ {
+ assertTrue("Handler should start", false);
+ }
+ assertEquals("A virtual bundle should have been installed.",
+ before + 1, getBundleContext().getBundles().length);
+
+ // Get the virtual bundle.
+ m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+ assertEquals("Virtual bundle should be INSTALLED", Bundle.INSTALLED, m_bundleB.getState());
+
+ // Resolve the virtual bundle.
+ PackageAdmin pa = getPackageAdmin();
+ pa.resolveBundles(new Bundle[] { m_bundleB });
+ assertEquals("Virtual bundle should be RESOLVED", Bundle.RESOLVED, m_bundleB.getState());
+
+ // Resolve the virtual bundle.
+ try
+ {
+ m_bundleB.start();
+ assertEquals("Virtual bundle should start", Bundle.ACTIVE, m_bundleB.getState());
+ m_bundleB.stop();
+ assertEquals("Virtual bundle should stop", Bundle.RESOLVED, m_bundleB.getState());
+ m_bundleB.start();
+ assertEquals("Virtual bundle should restart", Bundle.ACTIVE, m_bundleB.getState());
+ }
+ catch (BundleException ex)
+ {
+ assertTrue("Virtual bundle should start: " + ex, false);
+ }
+
+ // Install and start client bundle.
+ is = this.getClass().getClassLoader().getResourceAsStream("vb.b003.jar");
+ m_bundleC = getBundleContext().installBundle("vb.b003.jar", is);
+ m_bundleC.start();
+ }
+ finally
+ {
+ cleanup();
+ }
+ }
+
+ public void testVirtualBundleRestart002() throws Exception
+ {
+ InputStream is = null;
+
+ try
+ {
+ // Install and start handler bundle, which will install a virtual bundle.
+ is = this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar");
+ m_bundleA = getBundleContext().installBundle("vb.b001.jar", is);
+
+ int before = getBundleContext().getBundles().length;
+ try
+ {
+ m_bundleA.start();
+ }
+ catch (BundleException ex)
+ {
+ assertTrue("Handler should start", false);
+ }
+ assertEquals("A virtual bundle should have been installed.",
+ before + 1, getBundleContext().getBundles().length);
+
+ // Get the virtual bundle.
+ m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+ assertEquals(
+ "Virtual bundle should be INSTALLED", Bundle.INSTALLED, m_bundleB.getState());
+
+ // Uninstall handler.
+ m_bundleA.uninstall();
+ assertEquals(
+ "Handler should be UNINSTALLED", Bundle.UNINSTALLED, m_bundleA.getState());
+
+ // Resolve the virtual bundle.
+ PackageAdmin pa = getPackageAdmin();
+ pa.refreshPackages(null);
+ m_bundleA = getBundle("org.apache.felix.framework.vb.b001");
+ assertNull("Handler shouldn't be installed", m_bundleA);
+
+ // Resolve the virtual bundle.
+ try
+ {
+ m_bundleB.start();
+ }
+ catch (BundleException ex)
+ {
+ // Expected
+ }
+ assertEquals(
+ "Virtual bundle shouldn't resolve", Bundle.INSTALLED, m_bundleB.getState());
+
+ // Install and start client bundle.
+ is = this.getClass().getClassLoader().getResourceAsStream("vb.b003.jar");
+ m_bundleC = getBundleContext().installBundle("vb.b003.jar", is);
+ try
+ {
+ m_bundleC.start();
+ }
+ catch (BundleException ex)
+ {
+ // Expected
+ }
+ assertEquals(
+ "Client bundle shouldn't resolve", Bundle.INSTALLED, m_bundleC.getState());
}
finally
{
Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java?rev=953866&r1=953865&r2=953866&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java (original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java Fri Jun 11 21:03:38 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.felix.framework.vb.b001;
import java.io.IOException;
@@ -26,10 +44,21 @@ public class Activator implements Bundle
Map headers = (mf == null) ? new HashMap() : mf.getMainAttributes();
// Create a case insensitive map of manifest attributes.
headers = new StringMap(headers, false);
- fbc.installBundle(
- "virtualbundle",
- headers,
- new JarVirtualModule(headers, jarFile));
+ try
+ {
+ fbc.installBundle(
+ "virtualbundle",
+ headers,
+ new JarVirtualModule(headers, jarFile));
+ }
+ catch (BundleException ex)
+ {
+ if (ex.getType() != BundleException.DUPLICATE_BUNDLE_ERROR)
+ {
+ throw ex;
+ }
+ System.out.println("Virtual bundle needs to be reinstalled.");
+ }
}
catch (IOException ex)
{
Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarFileClassLoader.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarFileClassLoader.java?rev=953866&r1=953865&r2=953866&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarFileClassLoader.java (original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarFileClassLoader.java Fri Jun 11 21:03:38 2010
@@ -121,9 +121,30 @@ public class JarFileClassLoader extends
}
@Override
- protected URL findResource(String string)
+ protected URL findResource(String name)
{
- return super.findResource(string);
+// TODO: VB - Fix resource loading.
+ URL url = null;
+
+ // Remove leading slash, if present, but special case
+ // "/" so that it returns a root URL...this isn't very
+ // clean or meaninful, but the Spring guys want it.
+ if (name.equals("/"))
+ {
+ // Just pick a class path index since it doesn't really matter.
+// url = createURL(1, name);
+ }
+ else if (name.startsWith("/"))
+ {
+ name = name.substring(1);
+ }
+
+ if (hasEntry(name))
+ {
+// url = createURL(i + 1, name);
+ }
+
+ return url;
}
private Object findClassOrResourceFromWires(String name, boolean isClass)
@@ -224,6 +245,22 @@ public class JarFileClassLoader extends
super.finalize();
}
+ boolean hasEntry(String name) throws IllegalStateException
+ {
+ try
+ {
+ ZipEntry ze = m_jarFile.getEntry(name);
+ return ze != null;
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
+ finally
+ {
+ }
+ }
+
byte[] getEntryAsBytes(String name) throws IllegalStateException
{
// Get the embedded resource.
Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/Activator.java?rev=953866&r1=953865&r2=953866&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/Activator.java (original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/Activator.java Fri Jun 11 21:03:38 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.felix.framework.vb.b002;
import org.apache.felix.framework.vb.b002.service.Service;
Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/ServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/ServiceImpl.java?rev=953866&r1=953865&r2=953866&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/ServiceImpl.java (original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/ServiceImpl.java Fri Jun 11 21:03:38 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.felix.framework.vb.b002;
import org.apache.felix.framework.vb.b002.service.Service;
Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/service/Service.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/service/Service.java?rev=953866&r1=953865&r2=953866&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/service/Service.java (original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b002/service/Service.java Fri Jun 11 21:03:38 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.felix.framework.vb.b002.service;
public interface Service
Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b003/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b003/Activator.java?rev=953866&view=auto
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b003/Activator.java (added)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b003/Activator.java Fri Jun 11 21:03:38 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.felix.framework.vb.b003;
+
+import org.apache.felix.framework.vb.b002.service.Service;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class Activator implements BundleActivator
+{
+ public void start(BundleContext bc) throws Exception
+ {
+ ServiceReference ref = bc.getServiceReference(Service.class.getName());
+ Service svc = (Service) bc.getService(ref);
+ svc.sayHello();
+ }
+
+ public void stop(BundleContext bc) throws Exception
+ {
+ }
+}
\ No newline at end of file