Hi David, I see you also checked in .classpath and .project. Do you intend to check in these files or have I missed something?
Many thanks, Emily From: [email protected] To: [email protected] Date: 04/11/2010 13:52 Subject: svn commit: r1030988 - in /incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications: ./ .classpath .project META-INF/ META-INF/MANIFEST.MF build.properties src/ src/mytestbundle/ src/mytestbundle/Activator.java Author: davidb Date: Thu Nov 4 13:51:35 2010 New Revision: 1030988 URL: http://svn.apache.org/viewvc?rev=1030988&view=rev Log: Initial import. Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.classpath incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.project incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/META-INF/ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/META-INF/MANIFEST.MF incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/build.properties incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/src/ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/src/mytestbundle/ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/src/mytestbundle/Activator.java Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/ (props changed) Propchange: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Thu Nov 4 13:51:35 2010 @@ -0,0 +1 @@ +.settings Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.classpath URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.classpath?rev=1030988&view=auto ============================================================================== --- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.classpath (added) +++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.classpath Thu Nov 4 13:51:35 2010 @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.project URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.project?rev=1030988&view=auto ============================================================================== --- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.project (added) +++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/.project Thu Nov 4 13:51:35 2010 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>MyTestBundleModifications</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/META-INF/MANIFEST.MF?rev=1030988&view=auto ============================================================================== --- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/META-INF/MANIFEST.MF (added) +++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/META-INF/MANIFEST.MF Thu Nov 4 13:51:35 2010 @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: MyTestBundleModifications +Bundle-SymbolicName: MyTestBundleModifications +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.apache.aries.spifly.mysvc, + org.apache.aries.spifly.util, + org.osgi.framework;version="1.6.0", + org.osgi.framework.wiring;version="1.0.0", + org.osgi.util.tracker;version="1.5.0" Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/build.properties URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/build.properties?rev=1030988&view=auto ============================================================================== --- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/build.properties (added) +++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/build.properties Thu Nov 4 13:51:35 2010 @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/src/mytestbundle/Activator.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/src/mytestbundle/Activator.java?rev=1030988&view=auto ============================================================================== --- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/src/mytestbundle/Activator.java (added) +++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/MyTestBundleModifications/src/mytestbundle/Activator.java Thu Nov 4 13:51:35 2010 @@ -0,0 +1,103 @@ +/** + * 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 mytestbundle; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.ServiceLoader; + +import org.apache.aries.spifly.mysvc.SPIProvider; +import org.apache.aries.spifly.util.MultiDelegationClassloader; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleReference; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.wiring.BundleWiring; + +public class Activator implements BundleActivator { + public void start(BundleContext context) throws Exception { + callSPI_Around(); + } + + private void callSPI_Around() throws Exception { + ClassLoader cl = Activator.class.getClassLoader(); + if (!(cl instanceof BundleReference)) { + // can't do anything + System.out.println("cl is not an instance of BundleReference"); + callSPI(); + return; + } + + BundleReference bref = (BundleReference) cl; + BundleContext ctx = bref.getBundle().getBundleContext(); + +// ServiceReference<?>[] refs0 = ctx.getAllServiceReferences("org.osgi.service.packageadmin.PackageAdmin", null); +// System.out.println("References to org.osgi.service.packageadmin.PackageAdmin: " + Arrays.toString(refs0)); +// ServiceReference<?>[] refs1 = ctx.getAllServiceReferences("org.apache.aries.spifly.api.SPIClassloaderAdviceService", null); +// System.out.println("References to org.apache.aries.spifly.api.SPIClassloaderAdviceService: " + Arrays.toString(refs1)); +// ServiceReference<?>[] refs2 = ctx.getAllServiceReferences("org.apache.aries.spifly.mysvc.SPIProvider", null); +// System.out.println("References to org.apache.aries.spifly.mysvc.SPIProvider: " + Arrays.toString(refs2)); +// ServiceReference<?>[] refs3 = ctx.getAllServiceReferences(null, null); +// System.out.println("All Service References: " + Arrays.toString(refs3)); +// ServiceReference<?>[] refs4 = ctx.getAllServiceReferences("org.apache.aries.spifly.api.SPIClassloaderAdviceService", null); +// System.out.println("References to org.apache.aries.spifly.api.SPIClassloaderAdviceService: " + Arrays.toString(refs4)); + + String className = SPIProvider.class.getName(); // obtain through aspect + ServiceReference<?>[] refs = ctx.getAllServiceReferences(className, null); + System.out.println("References to " + className + ": " + Arrays.toString(refs)); + List<ClassLoader> loaders = new ArrayList<ClassLoader>(); + if (refs != null) { + for (ServiceReference<?> ref : refs) { + Bundle b = ref.getBundle(); + BundleWiring bw = b.adapt(BundleWiring.class); + loaders.add(bw.getClassLoader()); + } + } + + if (loaders.size() == 0) { + callSPI(); + return; + } + + ClassLoader targetLoader = loaders.size() > 1 ? new MultiDelegationClassloader(loaders.toArray(new ClassLoader[0])) : loaders.get(0); + ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); + try { + System.out.println("Setting thread context classloader to " + targetLoader); + Thread.currentThread().setContextClassLoader(targetLoader); + callSPI(); + return; + } finally { + Thread.currentThread().setContextClassLoader(prevCl); + } + } + + private void callSPI() { + System.out.println("(Modified) *** Loading the SPI..."); + ServiceLoader<SPIProvider> ldr = ServiceLoader.load(SPIProvider.class); + for (SPIProvider spiObject : ldr) { + System.out.println("*** Invoking the SPI..."); + spiObject.doit(); // invoke the SPI object + } + } + + public void stop(BundleContext context) throws Exception { + } +} Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
