From d54505947697088c05bad24a79cf084ec8d18891 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Wed, 16 Feb 2011 20:45:18 +0000 Subject: Merge wiring branch, fixes for the following bugs: Bug 334582 - OSGi changes to the wiring API Bug 334574 - OSGi renamed synthetic wiring capabilities to start with osgi.wiring. Bug 334591 - OSGi added AdaptPermission Bug 335673 - No FrameworkEvent generated for exceptions in a WeavingHook --- .../internal/baseadaptor/weaving/WeavingHookConfigurator.java | 9 +++++---- .../osgi/internal/baseadaptor/weaving/WovenClassImpl.java | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse') diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WeavingHookConfigurator.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WeavingHookConfigurator.java index 5f4b42bbe..78b8f44dc 100644 --- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WeavingHookConfigurator.java +++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WeavingHookConfigurator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. + * Copyright (c) 2010, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,8 +23,7 @@ import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate; import org.eclipse.osgi.framework.internal.core.Framework; import org.eclipse.osgi.internal.loader.BundleLoader; import org.eclipse.osgi.internal.serviceregistry.ServiceRegistry; -import org.osgi.framework.FrameworkEvent; -import org.osgi.framework.ServiceRegistration; +import org.osgi.framework.*; public class WeavingHookConfigurator implements HookConfigurator, ClassLoadingHook, ClassLoadingStatsHook { private BaseAdaptor adaptor; @@ -68,7 +67,9 @@ public class WeavingHookConfigurator implements HookConfigurator, ClassLoadingHo try { return wovenClass.callHooks(); } catch (Throwable t) { - adaptor.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, manager.getBaseData().getBundle(), t); + ServiceRegistration errorHook = wovenClass.getErrorHook(); + Bundle errorBundle = errorHook != null ? errorHook.getReference().getBundle() : manager.getBaseData().getBundle(); + adaptor.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, errorBundle, t); // fail hard with a class loading error ClassFormatError error = new ClassFormatError("Unexpected error from weaving hook."); //$NON-NLS-1$ error.initCause(t); diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java index 9198e8f29..12f2a4b26 100644 --- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java +++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java @@ -34,6 +34,7 @@ public final class WovenClassImpl implements WovenClass, HookContext { private byte[] bytes; private byte hookFlags = 0; private Throwable error; + private ServiceRegistration errorHook; private Class clazz; public WovenClassImpl(String className, byte[] bytes, ProtectionDomain domain, BundleLoader loader, ServiceRegistry registry, Map, Boolean> blacklist) { @@ -114,7 +115,7 @@ public final class WovenClassImpl implements WovenClass, HookContext { } public BundleWiring getBundleWiring() { - return loader.getLoaderProxy().getBundleDescription().getBundleWiring(); + return loader.getLoaderProxy().getBundleDescription().getWiring(); } public void call(final Object hook, ServiceRegistration hookRegistration) throws Exception { @@ -128,9 +129,11 @@ public final class WovenClassImpl implements WovenClass, HookContext { ((WeavingHook) hook).weave(this); } catch (WeavingException e) { error = e; + errorHook = hookRegistration; // do not blacklist on weaving exceptions } catch (Throwable t) { error = t; // save the error to fail later + errorHook = hookRegistration; // put the registration on the black list blackList.put(hookRegistration, Boolean.TRUE); } @@ -188,4 +191,8 @@ public final class WovenClassImpl implements WovenClass, HookContext { public String toString() { return className; } + + public ServiceRegistration getErrorHook() { + return errorHook; + } } -- cgit v1.2.3