Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 40261 invoked from network); 10 Jun 2010 22:39:01 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Jun 2010 22:39:01 -0000 Received: (qmail 35394 invoked by uid 500); 10 Jun 2010 22:39:01 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 35369 invoked by uid 500); 10 Jun 2010 22:39:01 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 35362 invoked by uid 99); 10 Jun 2010 22:39:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 22:39:01 +0000 X-ASF-Spam-Status: No, hits=-1705.8 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 22:38:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2B05D2388A66; Thu, 10 Jun 2010 22:38:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r953488 - in /felix/sandbox/rickhall/vb-bnd-test: ./ cnf/ cnf/repo/ cnf/repo/biz.aQute.bnd/ org.apache.felix.framework.vb/ org.apache.felix.framework.vb/recipes/ org.apache.felix.framework.vb/src/ org.apache.felix.framework.vb/src/org/ org.... Date: Thu, 10 Jun 2010 22:38:15 -0000 To: commits@felix.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100610223816.2B05D2388A66@eris.apache.org> Author: rickhall Date: Thu Jun 10 22:38:15 2010 New Revision: 953488 URL: http://svn.apache.org/viewvc?rev=953488&view=rev Log: Prepare for testing virtual bundles. Added: felix/sandbox/rickhall/vb-bnd-test/ felix/sandbox/rickhall/vb-bnd-test/cnf/ felix/sandbox/rickhall/vb-bnd-test/cnf/build.bnd felix/sandbox/rickhall/vb-bnd-test/cnf/build.xml felix/sandbox/rickhall/vb-bnd-test/cnf/repo/ felix/sandbox/rickhall/vb-bnd-test/cnf/repo/biz.aQute.bnd/ felix/sandbox/rickhall/vb-bnd-test/cnf/repo/biz.aQute.bnd/biz.aQute.bnd-latest.jar (with props) felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/build.xml felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b001.bnd felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/FelixTestCase.java 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/ 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/b001/JarVirtualModule.java felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringComparator.java felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringMap.java felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/resource/ felix/sandbox/rickhall/vb-bnd-test/pom.xml Added: felix/sandbox/rickhall/vb-bnd-test/cnf/build.bnd URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/cnf/build.bnd?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/cnf/build.bnd (added) +++ felix/sandbox/rickhall/vb-bnd-test/cnf/build.bnd Thu Jun 10 22:38:15 2010 @@ -0,0 +1,58 @@ +# Very general +project.dependson = ${p-dependson;:} +project.bootclasspath = ${p-bootclasspath;:} +project.buildpath = ${p-buildpath;:} +project.sourcepath = ${p-sourcepath;:} +project.allsourcepath = ${p-allsourcepath;:} +project.output = ${p-output} +project.testpath = ${p-testpath;:} +bin = ${target}/bin +verbose = false +project = ${basedir} +target = ${project}/${target-dir} +workspace = ${dir;${project}} +build = ${workspace}/cnf +repo = ${build}/repo +target-dir = tmp +p = ${basename;${project}} +project.name = ${p} +bin.includes = ${project.name}.jar + +# Java compiler options +java = java +javac = javac +javac.debug = on +javac.source = 1.5 +javac.target = 1.5 + +#Bnd options +-sources = true +-sourcepath = ${project}/src +-plugin = aQute.lib.deployer.FileRepo;location=${repo}, aQute.bnd.maven.MavenRepository, aQute.bnd.maven.MavenGroup; groupId=org.apache.felix +junit = junit.junit;version=3.8;export="junit.framework;version=3.8,junit.extensions;version=3.8" + +# Time options +# base.modified is used by bnd to not make when files are not changed +base.modified = ${fmodified;${build}/build.xml,${build}/build.bnd,${project}/build.properties,${project}/bnd.bnd,${project}/build.xml} +base.modified.readable = ${long2date;${base.modified}} +project.build = ${tstamp;yyyyMMddhhmm} + +-make : (*).jar; type=bnd; recipe=recipes/$1.bnd + +copyright = ... +copyright.html = ... + +# Documentation +Bundle-Vendor = The Apache Software Foundation +Bundle-DocURL = http://www.apache.org/ +Bundle-License = http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-Copyright = ${copyright} +Bundle-Vendor = Apache Felix +-removeheader = Include-Resource + + +# org.eclipse.osgi; version=3.5.0, \ +-runpath = \ + org.apache.felix.framework; version=3.1.0, \ + junit.junit; version=3.8; export="junit.framework;version=3.8" + Added: felix/sandbox/rickhall/vb-bnd-test/cnf/build.xml URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/cnf/build.xml?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/cnf/build.xml (added) +++ felix/sandbox/rickhall/vb-bnd-test/cnf/build.xml Thu Jun 10 22:38:15 2010 @@ -0,0 +1,187 @@ + + + + + + + + Exit project ${project.name} + + + + + + + + + + + + + + + + + + + + + + + + + + Enter project ${project.name} + + + + + + + + + + + + + + + + + + ${project.sourcepath} ${project.output} + + + + + + + + + + + + + + + + + + + JARs ${use.bnd} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + verbose: ${verbose} + project.name: ${project.name} + project.output: ${project.output} + project.sourcepath: ${project.sourcepath} + project.allsourcepath: ${project.allsourcepath} + project.buildpath: ${project.buildpath} + project.testpath: ${project.testpath} + project.dependson: ${project.dependson} + project.bootclasspath: ${project.bootclasspath} + javac: ${javac} + p: ${p} + jars.compile.order: ${jars.compile.order} + bin.includes: ${bin.includes} + base.modfied: ${base.modified} (${base.modified.readable}) + target: ${target} + licensed repo: ${licensed-repo} + repo: ${repo} + use.bnd: ${use.bnd} + nodeploy: ${nodeploy} + -dependson: ${-dependson} + + + + + + + + + + + + + Added: felix/sandbox/rickhall/vb-bnd-test/cnf/repo/biz.aQute.bnd/biz.aQute.bnd-latest.jar URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/cnf/repo/biz.aQute.bnd/biz.aQute.bnd-latest.jar?rev=953488&view=auto ============================================================================== Binary file - no diff available. Propchange: felix/sandbox/rickhall/vb-bnd-test/cnf/repo/biz.aQute.bnd/biz.aQute.bnd-latest.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: 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=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/bnd.bnd Thu Jun 10 22:38:15 2010 @@ -0,0 +1,13 @@ +-runvm = -Xdebug, "-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n" + +Private-Package: ${p} +Include-Resource: \ + vb.b001.jar + +-buildpath: \ + org.apache.felix.framework; version=3.1.0, \ + junit.junit + +-runproperties = report=true, felix.log.level=4 + +Test-Cases = ${classes;extending;*FelixTestCase} Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/build.xml URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/build.xml?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/build.xml (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/build.xml Thu Jun 10 22:38:15 2010 @@ -0,0 +1,4 @@ + + + + Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b001.bnd URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b001.bnd?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b001.bnd (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/recipes/vb.b001.bnd Thu Jun 10 22:38:15 2010 @@ -0,0 +1,2 @@ +Bundle-SymbolicName: org.apache.felix.framework.vb.b001 +Private-Package: org.apache.felix.framework.vb.b001 Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/FelixTestCase.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/FelixTestCase.java?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/FelixTestCase.java (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/FelixTestCase.java Thu Jun 10 22:38:15 2010 @@ -0,0 +1,78 @@ +/* + * 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; + +import junit.framework.TestCase; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkEvent; +import org.osgi.framework.FrameworkListener; +import org.osgi.service.packageadmin.PackageAdmin; + +public abstract class FelixTestCase extends TestCase +{ + private volatile BundleContext m_context; + private volatile PackageAdmin m_pa = null; + private volatile boolean m_isRefreshed = false; + + public BundleContext getBundleContext() + { + return m_context; + } + + public void setBundleContext(BundleContext context) + { + m_context = context; + m_context.addFrameworkListener(new FrameworkListener() { + public void frameworkEvent(FrameworkEvent event) + { + if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) + { + m_isRefreshed = true; + } + } + }); + } + + public PackageAdmin getPackageAdmin() + { + if (m_pa == null) + { + m_pa = (PackageAdmin) m_context.getService( + m_context.getServiceReference(PackageAdmin.class.getName())); + } + return m_pa; + } + + public void refreshAndWait() + { + m_isRefreshed = false; + getPackageAdmin().refreshPackages(null); + while (!m_isRefreshed) + { + try + { + Thread.sleep(100); + } + catch (InterruptedException ex) + { + // Ignore. + } + } + } +} Added: 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=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java Thu Jun 10 22:38:15 2010 @@ -0,0 +1,110 @@ +/* + * 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; + +import java.io.InputStream; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; +import org.osgi.service.packageadmin.ExportedPackage; +import org.osgi.service.packageadmin.PackageAdmin; + +public class TestVirtualBundle extends FelixTestCase +{ + private Bundle m_bundleA = null; + private Bundle m_bundleB = null; + private Bundle m_bundleC = null; + private Bundle m_bundleD = null; + + public void testVBResolve() throws Exception + { + InputStream is = null; + + try + { + is = this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar"); + m_bundleA = getBundleContext().installBundle("resolver.b001.jar", is); + + try + { + m_bundleA.start(); + } + catch (BundleException ex) + { + assertTrue("Bundle should resolve", false); + } + } + finally + { + cleanup(); + } + } + + private void cleanup() + { + if (m_bundleA != null) + { + try + { + m_bundleA.uninstall(); + } + catch (Exception ex) + { + // Ummm? + } + m_bundleA = null; + } + if (m_bundleB != null) + { + try + { + m_bundleB.uninstall(); + } + catch (Exception ex) + { + // Ummm? + } + m_bundleB = null; + } + if (m_bundleC != null) + { + try + { + m_bundleC.uninstall(); + } + catch (Exception ex) + { + // Ummm? + } + m_bundleC = null; + } + if (m_bundleD != null) + { + try + { + m_bundleD.uninstall(); + } + catch (Exception ex) + { + // Ummm? + } + m_bundleD = null; + } + refreshAndWait(); + } +} Added: 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=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java Thu Jun 10 22:38:15 2010 @@ -0,0 +1,48 @@ +package org.apache.felix.framework.vb.b001; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import org.apache.felix.framework.ext.FelixBundleContext; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; + +public class Activator implements BundleActivator +{ + public void start(BundleContext bc) throws BundleException + { + if (bc instanceof FelixBundleContext) + { + FelixBundleContext fbc = (FelixBundleContext) bc; + try + { + JarFile jarFile = new JarFile("/Users/rickhall/Projects/tmp/vb2/vb2.jar"); + // Get the embedded resource. + Manifest mf = jarFile.getManifest(); + // Use an empty map if there is no manifest. + 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)); + } + catch (IOException ex) + { + throw new BundleException("Error installing bundle", ex); + } + } + else + { + System.out.println("No FelixBundleContext!"); + } + } + + public void stop(BundleContext bc) + { + } +} Added: 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=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarFileClassLoader.java (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarFileClassLoader.java Thu Jun 10 22:38:15 2010 @@ -0,0 +1,371 @@ +/* + * 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.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.SecureClassLoader; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; +import org.apache.felix.framework.ext.ResourceNotFoundException; +import org.apache.felix.framework.ext.VBWire; + +public class JarFileClassLoader extends SecureClassLoader +{ + private final JarFile m_jarFile; + private final Map m_headers; + private final List m_wires; + + public JarFileClassLoader(JarFile jarFile, Map headers, List wires) + { + m_jarFile = jarFile; + m_headers = headers; + m_wires = wires; + } + + @Override + protected Class findClass(String name) throws ClassNotFoundException + { + Class clazz = null; + + // Search for class in module. + if (clazz == null) + { + String actual = name.replace('.', '/') + ".class"; + byte[] bytes = getEntryAsBytes(actual); + if (bytes != null) + { + // Get package name. + String pkgName = getClassPackage(name); + + // Before we actually attempt to define the class, grab + // the lock for this class loader and make sure than no + // other thread has defined this class in the meantime. + synchronized (this) + { + clazz = findLoadedClass(name); + + if (clazz == null) + { + // We need to try to define a Package object for the class + // before we call defineClass() if we haven't already + // created it. + if (pkgName.length() > 0) + { + if (getPackage(pkgName) == null) + { + Object[] params = definePackage(pkgName); + if (params != null) + { + definePackage( + pkgName, + (String) params[0], + (String) params[1], + (String) params[2], + (String) params[3], + (String) params[4], + (String) params[5], + null); + } + else + { + definePackage(pkgName, null, null, + null, null, null, null, null); + } + } + } + + if (clazz == null) + { + // If we have a security context, then use it to + // define the class with it for security purposes, + // otherwise define the class without a protection domain. +// TODO: VB - Consider security. +// if (m_protectionDomain != null) +// { +// clazz = defineClass(name, bytes, 0, bytes.length, +// m_protectionDomain); +// } +// else + { + clazz = defineClass(name, bytes, 0, bytes.length); + } + } + } + } + } + } + + return clazz; + } + + @Override + protected URL findResource(String string) + { + return super.findResource(string); + } + + private Object findClassOrResourceFromWires(String name, boolean isClass) + throws ClassNotFoundException, ResourceNotFoundException + { + Object result = null; + + // Boot delegate if necessary. + // TODO: VB - Note, this isn't 100% correct. We could possibly + // improve this by making boot delegation a wire. + String pkgName = getClassPackage(name); + try + { + // Get the appropriate class loader for delegation. + ClassLoader bdcl = ClassLoader.getSystemClassLoader(); + result = (isClass) + ? (Object) bdcl.loadClass(name) + : (Object) bdcl.getResource(name); + // If this is a java.* package, then always terminate the + // search; otherwise, continue to look locally if not found. + if (pkgName.startsWith("java.") || (result != null)) + { + return result; + } + } + catch (ClassNotFoundException ex) + { + // If this is a java.* package, then always terminate the + // search; otherwise, continue to look locally if not found. + if (pkgName.startsWith("java.")) + { + throw ex; + } + } + + for (int i = 0; (result == null) && (i < m_wires.size()); i++) + { + result = (isClass) + ? m_wires.get(i).getClass(name) + : m_wires.get(i).getResource(name); + } + if (result == null) + { + result = (isClass) + ? findClass(name) + : findResource(name); + } + return result; + } + + @Override + protected Enumeration findResources(String string) throws IOException + { + return super.findResources(string); + } + + @Override + protected Class loadClass(String name, boolean resolve) + throws ClassNotFoundException + { + Class clazz = null; + + // Make sure the class was not already loaded. + synchronized (this) + { + clazz = findLoadedClass(name); + } + + if (clazz == null) + { + try + { + clazz = (Class) findClassOrResourceFromWires(name, true); + } + catch (ResourceNotFoundException cnfe) + { + // This shouldn't happen. + } + catch (ClassNotFoundException cnfe) + { + ClassNotFoundException ex = cnfe; + throw ex; + } + } + + // Resolve the class and return it. + if (resolve) + { + resolveClass(clazz); + } + return clazz; + } + + @Override + protected void finalize() throws Throwable + { + m_jarFile.close(); + super.finalize(); + } + + byte[] getEntryAsBytes(String name) throws IllegalStateException + { + // Get the embedded resource. + InputStream is = null; + ByteArrayOutputStream baos = null; + + try + { + ZipEntry ze = m_jarFile.getEntry(name); + if (ze == null) + { + return null; + } + is = m_jarFile.getInputStream(ze); + if (is == null) + { + return null; + } + baos = new ByteArrayOutputStream(2048); + byte[] buf = new byte[2048]; + int n = 0; + while ((n = is.read(buf, 0, buf.length)) >= 0) + { + baos.write(buf, 0, n); + } + return baos.toByteArray(); + + } + catch (Exception ex) + { + System.out.println("JarFileClassLoader: Unable to read bytes - " + ex); + return null; + } + finally + { + try + { + if (baos != null) baos.close(); + } + catch (Exception ex) + { + } + try + { + if (is != null) is.close(); + } + catch (Exception ex) + { + } + } + } + + InputStream getEntryAsStream(String name) + throws IllegalStateException, IOException + { + // Get the embedded resource. + InputStream is = null; + + try + { + ZipEntry ze = m_jarFile.getEntry(name); + if (ze == null) + { + return null; + } + is = m_jarFile.getInputStream(ze); + if (is == null) + { + return null; + } + } + catch (Exception ex) + { + return null; + } + + return is; + } + + private Object[] definePackage(String pkgName) + { + String spectitle = (String) m_headers.get("Specification-Title"); + String specversion = (String) m_headers.get("Specification-Version"); + String specvendor = (String) m_headers.get("Specification-Vendor"); + String impltitle = (String) m_headers.get("Implementation-Title"); + String implversion = (String) m_headers.get("Implementation-Version"); + String implvendor = (String) m_headers.get("Implementation-Vendor"); + if ((spectitle != null) + || (specversion != null) + || (specvendor != null) + || (impltitle != null) + || (implversion != null) + || (implvendor != null)) + { + return new Object[] { + spectitle, specversion, specvendor, impltitle, implversion, implvendor + }; + } + return null; + } + + public static String getClassName(String className) + { + if (className == null) + { + className = ""; + } + return (className.lastIndexOf('.') < 0) + ? "" : className.substring(className.lastIndexOf('.') + 1); + } + + public static String getClassPackage(String className) + { + if (className == null) + { + className = ""; + } + return (className.lastIndexOf('.') < 0) + ? "" : className.substring(0, className.lastIndexOf('.')); + } + + public static String getResourcePackage(String resource) + { + if (resource == null) + { + resource = ""; + } + // NOTE: The package of a resource is tricky to determine since + // resources do not follow the same naming conventions as classes. + // This code is pessimistic and assumes that the package of a + // resource is everything up to the last '/' character. By making + // this choice, it will not be possible to load resources from + // imports using relative resource names. For example, if a + // bundle exports "foo" and an importer of "foo" tries to load + // "/foo/bar/myresource.txt", this will not be found in the exporter + // because the following algorithm assumes the package name is + // "foo.bar", not just "foo". This only affects imported resources, + // local resources will work as expected. + String pkgName = (resource.startsWith("/")) ? resource.substring(1) : resource; + pkgName = (pkgName.lastIndexOf('/') < 0) + ? "" : pkgName.substring(0, pkgName.lastIndexOf('/')); + pkgName = pkgName.replace('/', '.'); + return pkgName; + } +} Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarVirtualModule.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/JarVirtualModule.java?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarVirtualModule.java (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/JarVirtualModule.java Thu Jun 10 22:38:15 2010 @@ -0,0 +1,90 @@ +/* + * 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; +import java.net.URL; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.jar.JarFile; +import org.apache.felix.framework.ext.VBWire; +import org.apache.felix.framework.ext.VirtualModule; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleException; + +class JarVirtualModule implements VirtualModule +{ + private final Map m_headers; + private final JarFile m_jarFile; + private volatile JarFileClassLoader m_loader; + + public JarVirtualModule(Map headers, JarFile jarFile) + { + m_headers = headers; + m_jarFile = jarFile; + } + + public void resolve(List wires) throws BundleException + { + m_loader = new JarFileClassLoader(m_jarFile, m_headers, wires); + } + + public BundleActivator getActivator() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Class loadClass(String name) throws ClassNotFoundException + { + return m_loader.loadClass(name); + } + + public URL getResource(String name) + { + return m_loader.getResource(name); + } + + public Enumeration getResources(String name) + { + try + { + return m_loader.getResources(name); + } + catch (IOException ex) + { + return null; + } + } + + public URL getEntry(String name) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Enumeration getEntryPaths(String name) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Enumeration findEntries(String path, String filePattern, boolean recurse) + { + throw new UnsupportedOperationException("Not supported yet."); + } +} Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringComparator.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/StringComparator.java?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringComparator.java (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringComparator.java Thu Jun 10 22:38:15 2010 @@ -0,0 +1,48 @@ +/* + * 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.util.Comparator; + +public class StringComparator implements Comparator +{ + private final boolean m_isCaseSensitive; + + public StringComparator(boolean b) + { + m_isCaseSensitive = b; + } + + public int compare(Object o1, Object o2) + { + if (m_isCaseSensitive) + { + return o1.toString().compareTo(o2.toString()); + } + else + { + return o1.toString().compareToIgnoreCase(o2.toString()); + } + } + + public boolean isCaseSensitive() + { + return m_isCaseSensitive; + } +} Added: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringMap.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/StringMap.java?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringMap.java (added) +++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/StringMap.java Thu Jun 10 22:38:15 2010 @@ -0,0 +1,134 @@ +/* + * 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.util.*; + +/** + * Simple utility class that creates a map for string-based keys. + * This map can be set to use case-sensitive or case-insensitive + * comparison when searching for the key. Any keys put into this + * map will be converted to a String using the + * toString() method, since it is only intended to + * compare strings. +**/ +public class StringMap implements Map +{ + private TreeMap m_map; + + public StringMap() + { + this(true); + } + + public StringMap(boolean caseSensitive) + { + m_map = new TreeMap(new StringComparator(caseSensitive)); + } + + public StringMap(Map map, boolean caseSensitive) + { + this(caseSensitive); + putAll(map); + } + + public boolean isCaseSensitive() + { + return ((StringComparator) m_map.comparator()).isCaseSensitive(); + } + + public void setCaseSensitive(boolean b) + { + if (isCaseSensitive() != b) + { + TreeMap map = new TreeMap(new StringComparator(b)); + map.putAll(m_map); + m_map = map; + } + } + + public int size() + { + return m_map.size(); + } + + public boolean isEmpty() + { + return m_map.isEmpty(); + } + + public boolean containsKey(Object arg0) + { + return m_map.containsKey(arg0); + } + + public boolean containsValue(Object arg0) + { + return m_map.containsValue(arg0); + } + + public Object get(Object arg0) + { + return m_map.get(arg0); + } + + public Object put(Object key, Object value) + { + return m_map.put(key.toString(), value); + } + + public void putAll(Map map) + { + for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) + { + Map.Entry entry = (Map.Entry) it.next(); + put(entry.getKey(), entry.getValue()); + } + } + + public Object remove(Object arg0) + { + return m_map.remove(arg0); + } + + public void clear() + { + m_map.clear(); + } + + public Set keySet() + { + return m_map.keySet(); + } + + public Collection values() + { + return m_map.values(); + } + + public Set entrySet() + { + return m_map.entrySet(); + } + + public String toString() + { + return m_map.toString(); + } +} Added: felix/sandbox/rickhall/vb-bnd-test/pom.xml URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/pom.xml?rev=953488&view=auto ============================================================================== --- felix/sandbox/rickhall/vb-bnd-test/pom.xml (added) +++ felix/sandbox/rickhall/vb-bnd-test/pom.xml Thu Jun 10 22:38:15 2010 @@ -0,0 +1,83 @@ + + + + + org.apache + apache + 4 + + + 4.0.0 + org.apache.felix + build.dependencies + 1.0 + + Apache Felix Build Dependencies + + + + aQute + http://www.aqute.biz/repo + + + + + + biz.aQute + bnd + 0.0.397 + + + ${pom.groupId} + org.apache.felix.framework + 2.0.2 + + + org.osgi + org.osgi.core + 4.2.0 + + + ${pom.groupId} + org.osgi.foundation + 1.2.0 + + + junit + junit + 3.8 + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + install + + copy + + + + + biz.aQute + bnd + 0.0.397 + jar + true + ${basedir}/cnf/repo/biz.aQute.bnd/ + biz.aQute.bnd-latest.jar + + + + + + + + + +