diff options
author | Martin Lippert | 2013-03-18 11:20:26 +0000 |
---|---|---|
committer | Martin Lippert | 2013-03-18 11:20:26 +0000 |
commit | b67818202f7fb1c1c74c6f82dfa4c8ab05e296bf (patch) | |
tree | 5656f3dbe8546714fe6edcd364ef975bde540ab4 /bundles/org.eclipse.equinox.weaving.hook | |
parent | df6ca888743e9b5369c27778bf90a5f7f28ad046 (diff) | |
download | rt.equinox.bundles-b67818202f7fb1c1c74c6f82dfa4c8ab05e296bf.tar.gz rt.equinox.bundles-b67818202f7fb1c1c74c6f82dfa4c8ab05e296bf.tar.xz rt.equinox.bundles-b67818202f7fb1c1c74c6f82dfa4c8ab05e296bf.zip |
cleanup + avoid too early adaptor initialization in case of classloader creation
Diffstat (limited to 'bundles/org.eclipse.equinox.weaving.hook')
5 files changed, 181 insertions, 200 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java index 000f02f9c..9c5bb66f4 100644 --- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java +++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java @@ -15,7 +15,6 @@ package org.eclipse.equinox.weaving.adaptors; import java.net.URL; import org.eclipse.equinox.service.weaving.CacheEntry; -import org.eclipse.osgi.internal.loader.ModuleClassLoader; public interface IWeavingAdaptor { @@ -23,7 +22,7 @@ public interface IWeavingAdaptor { public void initialize(); - public void setModuleClassLoader(ModuleClassLoader moduleClassLoader); + public boolean isInitialized(); public boolean storeClass(String name, URL sourceFileURL, Class clazz, byte[] classbytes); diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java index 542f38543..79b5a0842 100644 --- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java +++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java @@ -74,7 +74,7 @@ public class WeavingAdaptor implements IWeavingAdaptor { private boolean initialized = false; - private ModuleClassLoader moduleLoader; + private final ModuleClassLoader moduleLoader; private final String symbolicName; @@ -83,18 +83,20 @@ public class WeavingAdaptor implements IWeavingAdaptor { public WeavingAdaptor(final Generation generation, final WeavingAdaptorFactory serviceFactory, final IWeavingService weavingService, - final ICachingService cachingService) { + final ICachingService cachingService, + final ModuleClassLoader classLoader) { this.generation = generation; this.factory = serviceFactory; this.symbolicName = generation.getRevision().getSymbolicName(); + this.moduleLoader = classLoader; if (Debug.DEBUG_GENERAL) - Debug.println("- AspectJAdaptor.AspectJAdaptor() bundle=" + Debug.println("- WeavingAdaptor.WeavingAdaptor() bundle=" + symbolicName); } public CacheEntry findClass(final String name, final URL sourceFileURL) { if (Debug.DEBUG_CACHE) - Debug.println("> AspectJAdaptor.findClass() bundle=" + symbolicName + Debug.println("> WeavingAdaptor.findClass() bundle=" + symbolicName + ", url=" + sourceFileURL + ", name=" + name); CacheEntry cacheEntry = null; @@ -105,7 +107,7 @@ public class WeavingAdaptor implements IWeavingAdaptor { } if (Debug.DEBUG_CACHE) - Debug.println("< AspectJAdaptor.findClass() cacheEntry=" + Debug.println("< WeavingAdaptor.findClass() cacheEntry=" + cacheEntry); return cacheEntry; } @@ -119,12 +121,12 @@ public class WeavingAdaptor implements IWeavingAdaptor { identifyRecursionSet.put(this); if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJAdaptor.initialize() bundle=" + Debug.println("> WeavingAdaptor.initialize() bundle=" + symbolicName + ", moduleLoader=" + moduleLoader); if (symbolicName.startsWith("org.aspectj")) { if (Debug.DEBUG_GENERAL) - Debug.println("- AspectJAdaptor.initialize() symbolicName=" + Debug.println("- WeavingAdaptor.initialize() symbolicName=" + symbolicName + ", moduleLoader=" + moduleLoader); @@ -136,20 +138,17 @@ public class WeavingAdaptor implements IWeavingAdaptor { final Bundle host = factory.getHost(bundle); if (Debug.DEBUG_GENERAL) - Debug.println("- AspectJAdaptor.initialize() symbolicName=" + Debug.println("- WeavingAdaptor.initialize() symbolicName=" + symbolicName + ", host=" + host); final Generation hostGeneration = (Generation) ((ModuleRevision) host .adapt(BundleRevision.class)).getRevisionInfo(); - // System.err.println("? AspectJAdaptor.initialize() bundleData=" + hostData); final BundleFile bundleFile = hostGeneration .getBundleFile(); if (bundleFile instanceof WeavingBundleFile) { final WeavingBundleFile hostFile = (WeavingBundleFile) bundleFile; - // System.err.println("? AspectJAdaptor.initialize() bundleFile=" + hostFile); final WeavingAdaptor hostAdaptor = (WeavingAdaptor) hostFile .getAdaptor(); - // System.err.println("? AspectJAdaptor.initialize() bundleFile=" + hostAdaptor); weavingService = hostAdaptor.weavingService; cachingService = factory.getCachingService( hostAdaptor.moduleLoader, bundle, @@ -157,7 +156,7 @@ public class WeavingAdaptor implements IWeavingAdaptor { } } else { if (Debug.DEBUG_GENERAL) - Debug.println("W AspectJAdaptor.initialize() symbolicName=" + Debug.println("W WeavingAdaptor.initialize() symbolicName=" + symbolicName + ", baseLoader=" + moduleLoader); } initialized = true; @@ -165,25 +164,22 @@ public class WeavingAdaptor implements IWeavingAdaptor { } if (Debug.DEBUG_GENERAL) - Debug.println("< AspectJAdaptor.initialize() weavingService=" + Debug.println("< WeavingAdaptor.initialize() weavingService=" + (weavingService != null) + ", cachingService=" + (cachingService != null)); } } - public void setModuleClassLoader(final ModuleClassLoader moduleClassLoader) { - this.moduleLoader = moduleClassLoader; - - if (Debug.DEBUG_GENERAL) - Debug.println("- AspectJAdaptor.setBaseClassLoader() bundle=" - + symbolicName + ", moduleLoader=" + moduleLoader); + public boolean isInitialized() { + return initialized; } public boolean storeClass(final String name, final URL sourceFileURL, final Class clazz, final byte[] classbytes) { if (Debug.DEBUG_CACHE) - Debug.println("> AspectJAdaptor.storeClass() bundle=" - + symbolicName + ", url=" + sourceFileURL + ", name=" + Debug.println("> WeavingAdaptor.storeClass() bundle=" //$NON-NLS-1$ + + symbolicName + ", url=" + sourceFileURL + + ", name=" + name + ", clazz=" + clazz); boolean stored = false; @@ -203,31 +199,31 @@ public class WeavingAdaptor implements IWeavingAdaptor { } else { weavingService.flushGeneratedClasses(moduleLoader); if (Debug.DEBUG_CACHE) - Debug.println("- AspectJAdaptor.storeClass() generatedClassesExistFor=true"); + Debug.println("- WeavingAdaptor.storeClass() generatedClassesExistFor=true"); //$NON-NLS-1$ } } else { - stored = cachingService.storeClass("", sourceFileURL, clazz, + stored = cachingService.storeClass("", sourceFileURL, clazz, //$NON-NLS-1$ classbytes); if (!stored) { if (Debug.DEBUG_CACHE) - Debug.println("E AspectJHook.storeClass() bundle=" - + symbolicName + ", name=" + name); + Debug.println("E WeavingAdaptor.storeClass() bundle=" //$NON-NLS-1$ + + symbolicName + ", name=" + name); //$NON-NLS-1$ } } } if (Debug.DEBUG_CACHE) - Debug.println("< AspectJAdaptor.storeClass() stored=" + stored); + Debug.println("< WeavingAdaptor.storeClass() stored=" + stored); //$NON-NLS-1$ return stored; } @Override public String toString() { - return "AspectJAdaptor[" + symbolicName + "]"; + return "WeavingAdaptor[" + symbolicName + "]"; } public byte[] weaveClass(final String name, final byte[] bytes) { if (Debug.DEBUG_WEAVE) - Debug.println("> AspectJAdaptor.weaveClass() bundle=" + Debug.println("> WeavingAdaptor.weaveClass() bundle=" + symbolicName + ", name=" + name + ", bytes=" + bytes.length); byte[] newBytes = null; @@ -242,7 +238,7 @@ public class WeavingAdaptor implements IWeavingAdaptor { } if (Debug.DEBUG_WEAVE) - Debug.println("< AspectJAdaptor.weaveClass() newBytes=" + newBytes); + Debug.println("< WeavingAdaptor.weaveClass() newBytes=" + newBytes); return newBytes; } diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java index 0fb75310c..1069ff068 100644 --- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java +++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java @@ -17,12 +17,10 @@ package org.eclipse.equinox.weaving.adaptors; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import org.eclipse.equinox.service.weaving.ICachingService; import org.eclipse.equinox.service.weaving.ICachingServiceFactory; @@ -44,15 +42,15 @@ import org.osgi.util.tracker.ServiceTracker; public class WeavingAdaptorFactory { - private static final Collection IGNORE_WEAVING_SERVICE_BUNDLES = Arrays - .asList(new String[] { "org.eclipse.equinox.weaving.aspectj", - "org.eclipse.equinox.weaving.caching", - "org.eclipse.equinox.weaving.caching.j9", - "org.eclipse.update.configurator", - "org.eclipse.equinox.simpleconfigurator", - "org.eclipse.equinox.common" }); + private static final Collection<String> IGNORE_WEAVING_SERVICE_BUNDLES = Arrays + .asList(new String[] { "org.eclipse.equinox.weaving.aspectj", //$NON-NLS-1$ + "org.eclipse.equinox.weaving.caching", //$NON-NLS-1$ + "org.eclipse.equinox.weaving.caching.j9", //$NON-NLS-1$ + "org.eclipse.update.configurator", //$NON-NLS-1$ + "org.eclipse.equinox.simpleconfigurator", //$NON-NLS-1$ + "org.eclipse.equinox.common" }); //$NON-NLS-1$ - private static final String WEAVING_SERVICE_DYNAMICS_PROPERTY = "equinox.weaving.service.dynamics"; + private static final String WEAVING_SERVICE_DYNAMICS_PROPERTY = "equinox.weaving.service.dynamics"; //$NON-NLS-1$ private ServiceTracker cachingServiceFactoryTracker; @@ -66,11 +64,7 @@ public class WeavingAdaptorFactory { private ServiceListener weavingServiceListener; - /** - * Bundle -> Local weaving service - */ - private final Map weavingServices = Collections - .synchronizedMap(new HashMap()); + private final Map<Bundle, IWeavingService> weavingServices = new ConcurrentHashMap<Bundle, IWeavingService>(); public WeavingAdaptorFactory() { } @@ -79,22 +73,22 @@ public class WeavingAdaptorFactory { context.removeServiceListener(weavingServiceListener); if (Debug.DEBUG_WEAVE) - Debug.println("> Removed service listener for weaving service."); + Debug.println("> Removed service listener for weaving service."); //$NON-NLS-1$ weavingServiceFactoryTracker.close(); if (Debug.DEBUG_WEAVE) - Debug.println("> Closed service tracker for weaving service."); + Debug.println("> Closed service tracker for weaving service."); //$NON-NLS-1$ cachingServiceFactoryTracker.close(); if (Debug.DEBUG_CACHE) - Debug.println("> Closed service tracker for caching service."); + Debug.println("> Closed service tracker for caching service."); //$NON-NLS-1$ } protected ICachingService getCachingService(final ModuleClassLoader loader, final Bundle bundle, final IWeavingService weavingService) { if (Debug.DEBUG_CACHE) - Debug.println("> AspectJAdaptorFactory.getCachingService() bundle=" - + bundle + ", weavingService=" + weavingService); + Debug.println("> WeavingAdaptorFactory.getCachingService() bundle=" //$NON-NLS-1$ + + bundle + ", weavingService=" + weavingService); //$NON-NLS-1$ ICachingService service = null; String key = ""; @@ -108,28 +102,27 @@ public class WeavingAdaptorFactory { bundle, key); } if (Debug.DEBUG_CACHE) - Debug.println("< AspectJAdaptorFactory.getCachingService() service=" - + service + ", key='" + key + "'"); + Debug.println("< WeavingAdaptorFactory.getCachingService() service=" //$NON-NLS-1$ + + service + ", key='" + key + "'"); //$NON-NLS-1$ return service; } public Bundle getHost(final Bundle fragment) { if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJAdaptorFactory.getHost() fragment=" - + fragment); + Debug.println("> WeavingAdaptorFactory.getHost() fragment=" + fragment); //$NON-NLS-1$ Bundle host = null; if (packageAdminService != null) host = packageAdminService.getHosts(fragment)[0]; if (Debug.DEBUG_GENERAL) - Debug.println("< AspectJAdaptorFactory.getHost() " + host); + Debug.println("< WeavingAdaptorFactory.getHost() " + host); //$NON-NLS-1$ return host; } protected IWeavingService getWeavingService(final ModuleClassLoader loader) { if (Debug.DEBUG_WEAVE) - Debug.println("> AspectJAdaptorFactory.getWeavingService() baseClassLoader=" + Debug.println("> WeavingAdaptorFactory.getWeavingService() baseClassLoader=" //$NON-NLS-1$ + loader); final Generation generation = loader.getClasspathManager() @@ -144,13 +137,14 @@ public class WeavingAdaptorFactory { weavingService = weavingServiceFactory.createWeavingService( loader, bundle, generation.getRevision(), supplementerRegistry); - } - synchronized (weavingServices) { - weavingServices.put(bundle, weavingService); + + if (weavingService != null) { + weavingServices.put(bundle, weavingService); + } } } if (Debug.DEBUG_WEAVE) - Debug.println("< AspectJAdaptorFactory.getWeavingService() service=" + Debug.println("< WeavingAdaptorFactory.getWeavingService() service=" //$NON-NLS-1$ + weavingService); return weavingService; } @@ -158,7 +152,7 @@ public class WeavingAdaptorFactory { public void initialize(final BundleContext context, final ISupplementerRegistry supplementerRegistry) { if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJAdaptorFactory.initialize() context=" + Debug.println("> WeavingAdaptorFactory.initialize() context=" //$NON-NLS-1$ + context); this.supplementerRegistry = supplementerRegistry; @@ -170,7 +164,7 @@ public class WeavingAdaptorFactory { IWeavingServiceFactory.class.getName(), null); weavingServiceFactoryTracker.open(); if (Debug.DEBUG_WEAVE) - Debug.println("> Opened service tracker for weaving service."); + Debug.println("> Opened service tracker for weaving service."); //$NON-NLS-1$ // Service listener for weaving service weavingServiceListener = new ServiceListener() { @@ -179,22 +173,16 @@ public class WeavingAdaptorFactory { if (event.getType() == ServiceEvent.REGISTERED) { final List<Bundle> bundlesToRefresh = new ArrayList<Bundle>(); - final Iterator bundleEntries = weavingServices.entrySet() - .iterator(); synchronized (weavingServices) { + final Iterator<Bundle> bundleEntries = weavingServices + .keySet().iterator(); while (bundleEntries.hasNext()) { - final Entry entry = (Entry) bundleEntries.next(); - final Bundle bundle = (Bundle) entry.getKey(); - if (entry.getValue() == null) { - bundleEntries.remove(); - System.err - .println("bundle update because of weaving service start: " - + bundle.getSymbolicName()); - bundlesToRefresh.add(bundle); - if (Debug.DEBUG_WEAVE) - Debug.println("> Updated bundle " - + bundle.getSymbolicName()); - } + final Bundle bundle = bundleEntries.next(); + bundleEntries.remove(); + bundlesToRefresh.add(bundle); + if (Debug.DEBUG_WEAVE) + Debug.println("> Updated bundle " //$NON-NLS-1$ + + bundle.getSymbolicName()); } } @@ -208,22 +196,16 @@ public class WeavingAdaptorFactory { && startLevelService.getStartLevel() > 0) { final List<Bundle> bundlesToRefresh = new ArrayList<Bundle>(); - final Iterator bundleEntries = weavingServices.entrySet() - .iterator(); synchronized (weavingServices) { + final Iterator<Bundle> bundleEntries = weavingServices + .keySet().iterator(); while (bundleEntries.hasNext()) { - final Entry entry = (Entry) bundleEntries.next(); - final Bundle bundle = (Bundle) entry.getKey(); - if (entry.getValue() != null) { - bundleEntries.remove(); - System.err - .println("bundle update because of weaving service stop: " - + bundle.getSymbolicName()); - bundlesToRefresh.add(bundle); - if (Debug.DEBUG_WEAVE) - Debug.println("> Updated bundle " - + bundle.getSymbolicName()); - } + final Bundle bundle = bundleEntries.next(); + bundleEntries.remove(); + bundlesToRefresh.add(bundle); + if (Debug.DEBUG_WEAVE) + Debug.println("> Updated bundle " //$NON-NLS-1$ + + bundle.getSymbolicName()); } } if (bundlesToRefresh.size() > 0) { @@ -234,15 +216,15 @@ public class WeavingAdaptorFactory { } }; - if (System.getProperty(WEAVING_SERVICE_DYNAMICS_PROPERTY, "false") - .equals("true")) { - try { - context.addServiceListener(weavingServiceListener, - "(" + Constants.OBJECTCLASS + "=" - + IWeavingService.class.getName() + ")"); - } catch (final InvalidSyntaxException e) { // This is correct! - } + // if (System.getProperty(WEAVING_SERVICE_DYNAMICS_PROPERTY, "false") + // .equals("true")) { + try { + context.addServiceListener(weavingServiceListener, "(" + + Constants.OBJECTCLASS + "=" + + IWeavingServiceFactory.class.getName() + ")"); + } catch (final InvalidSyntaxException e) { // This is correct! } + // } // Service tracker for caching service cachingServiceFactoryTracker = new ServiceTracker(context, @@ -254,7 +236,7 @@ public class WeavingAdaptorFactory { private void initializePackageAdminService(final BundleContext context) { if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJAdaptorFactory.initializePackageAdminService() context=" + Debug.println("> AdaptorFactory.initializePackageAdminService() context=" + context); final ServiceReference ref = context @@ -264,13 +246,13 @@ public class WeavingAdaptorFactory { } if (Debug.DEBUG_GENERAL) - Debug.println("< AspectJAdaptorFactory.initializePackageAdminService() " + Debug.println("< AdaptorFactory.initializePackageAdminService() " + packageAdminService); } private void initializeStartLevelService(final BundleContext context) { if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJAdaptorFactory.initializeStartLevelService() context=" + Debug.println("> AdaptorFactory.initializeStartLevelService() context=" + context); final ServiceReference ref = context @@ -280,7 +262,7 @@ public class WeavingAdaptorFactory { } if (Debug.DEBUG_GENERAL) - Debug.println("< AspectJAdaptorFactory.initializeStartLevelService() " + Debug.println("< AdaptorFactory.initializeStartLevelService() " + startLevelService); } } diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java index d089a11dd..0f7ae1b47 100644 --- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java +++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Martin Lippert and others. + * Copyright (c) 2008, 2013 Martin Lippert 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 @@ -28,6 +28,7 @@ import java.util.Set; import org.eclipse.equinox.service.weaving.ISupplementerRegistry; import org.eclipse.equinox.service.weaving.Supplementer; +import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor; import org.eclipse.osgi.util.ManifestElement; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -35,9 +36,14 @@ import org.osgi.framework.BundleException; import org.osgi.framework.Constants; import org.osgi.service.packageadmin.PackageAdmin; +/** + * The supplementer registry controls the set of installed supplementer bundles + * and calculates which other bundles are supplemented by them. + * + * @author mlippert + */ public class SupplementerRegistry implements ISupplementerRegistry { - //knibb /** * Manifest header (named "Supplement-Bundle") identifying the * names (and optionally, version numbers) of any bundles supplemented by @@ -82,7 +88,7 @@ public class SupplementerRegistry implements ISupplementerRegistry { private PackageAdmin packageAdmin; - private final Map<String, Supplementer> supplementers; // keys of type String (symbolic name of supplementer bundle), values of type Supplementer + private final Map<String, Supplementer> supplementers; // keys of type String (symbolic name of supplementer bundle) private final Map<Long, Supplementer[]> supplementersByBundle; @@ -126,22 +132,32 @@ public class SupplementerRegistry implements ISupplementerRegistry { try { final Dictionary<?, ?> manifest = bundle.getHeaders(); final ManifestElement[] imports = ManifestElement.parseHeader( - Constants.IMPORT_PACKAGE, (String) manifest - .get(Constants.IMPORT_PACKAGE)); + Constants.IMPORT_PACKAGE, + (String) manifest.get(Constants.IMPORT_PACKAGE)); final ManifestElement[] exports = ManifestElement.parseHeader( - Constants.EXPORT_PACKAGE, (String) manifest - .get(Constants.EXPORT_PACKAGE)); + Constants.EXPORT_PACKAGE, + (String) manifest.get(Constants.EXPORT_PACKAGE)); final List<Supplementer> supplementers = getMatchingSupplementers( bundle.getSymbolicName(), imports, exports); if (supplementers.size() > 0) { this.addSupplementedBundle(bundle, supplementers); } + this.supplementersByBundle.put(bundle.getBundleId(), supplementers .toArray(new Supplementer[supplementers.size()])); } catch (final BundleException e) { } } + private void addSupplementedBundle(final Bundle supplementedBundle, + final List<Supplementer> supplementers) { + for (final Iterator<Supplementer> iterator = supplementers.iterator(); iterator + .hasNext();) { + final Supplementer supplementer = iterator.next(); + supplementer.addSupplementedBundle(supplementedBundle); + } + } + /** * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#addSupplementer(org.osgi.framework.Bundle, * boolean) @@ -150,14 +166,14 @@ public class SupplementerRegistry implements ISupplementerRegistry { try { final Dictionary<?, ?> manifest = bundle.getHeaders(); final ManifestElement[] supplementBundle = ManifestElement - .parseHeader(SUPPLEMENT_BUNDLE, (String) manifest - .get(SUPPLEMENT_BUNDLE)); + .parseHeader(SUPPLEMENT_BUNDLE, + (String) manifest.get(SUPPLEMENT_BUNDLE)); final ManifestElement[] supplementImporter = ManifestElement - .parseHeader(SUPPLEMENT_IMPORTER, (String) manifest - .get(SUPPLEMENT_IMPORTER)); + .parseHeader(SUPPLEMENT_IMPORTER, + (String) manifest.get(SUPPLEMENT_IMPORTER)); final ManifestElement[] supplementExporter = ManifestElement - .parseHeader(SUPPLEMENT_EXPORTER, (String) manifest - .get(SUPPLEMENT_EXPORTER)); + .parseHeader(SUPPLEMENT_EXPORTER, + (String) manifest.get(SUPPLEMENT_EXPORTER)); if (supplementBundle != null || supplementImporter != null || supplementExporter != null) { @@ -231,22 +247,38 @@ public class SupplementerRegistry implements ISupplementerRegistry { } } + private boolean isSupplementerMatching(final String symbolicName, + final ManifestElement[] imports, final ManifestElement[] exports, + final Supplementer supplementer) { + final String supplementerName = supplementer.getSymbolicName(); + if (!supplementerName.equals(symbolicName)) { + if (supplementer.matchSupplementer(symbolicName) + || (imports != null && supplementer + .matchesSupplementImporter(imports)) + || (exports != null && supplementer + .matchesSupplementExporter(exports))) { + return true; + } + } + return false; + } + /** * Refreshes the given bundles * * @param bundles The bundles to refresh */ public void refreshBundles(final Bundle[] bundles) { - if (this.packageAdmin != null) { - if (AbstractWeavingHook.verbose) { - for (int i = 0; i < bundles.length; i++) { - System.out.println("refresh bundle: " - + bundles[i].getSymbolicName()); - } - } - - this.packageAdmin.refreshPackages(bundles); - } + // if (this.packageAdmin != null) { + // if (AbstractWeavingHook.verbose) { + // for (int i = 0; i < bundles.length; i++) { + // System.out.println("refresh bundle: " + // + bundles[i].getSymbolicName()); + // } + // } + // + // this.packageAdmin.refreshPackages(bundles); + // } } /** @@ -296,49 +328,10 @@ public class SupplementerRegistry implements ISupplementerRegistry { final List<Supplementer> supplementerList = new ArrayList<Supplementer>( Arrays.asList(this.supplementersByBundle.get(bundleId))); supplementerList.remove(supplementer); - this.supplementersByBundle.put(bundleId, supplementerList - .toArray(new Supplementer[0])); - } - } - } - - /** - * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setBundleContext(org.osgi.framework.BundleContext) - */ - public void setBundleContext(final BundleContext context) { - this.context = context; - } - - /** - * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setPackageAdmin(org.osgi.service.packageadmin.PackageAdmin) - */ - public void setPackageAdmin(final PackageAdmin packageAdmin) { - this.packageAdmin = packageAdmin; - } - - private void addSupplementedBundle(final Bundle supplementedBundle, - final List<Supplementer> supplementers) { - for (final Iterator<Supplementer> iterator = supplementers.iterator(); iterator - .hasNext();) { - final Supplementer supplementer = iterator.next(); - supplementer.addSupplementedBundle(supplementedBundle); - } - } - - private boolean isSupplementerMatching(final String symbolicName, - final ManifestElement[] imports, final ManifestElement[] exports, - final Supplementer supplementer) { - final String supplementerName = supplementer.getSymbolicName(); - if (!supplementerName.equals(symbolicName)) { - if (supplementer.matchSupplementer(symbolicName) - || (imports != null && supplementer - .matchesSupplementImporter(imports)) - || (exports != null && supplementer - .matchesSupplementExporter(exports))) { - return true; + this.supplementersByBundle.put(bundleId, + supplementerList.toArray(new Supplementer[0])); } } - return false; } private void removeSupplementedBundle(final Bundle bundle) { @@ -372,15 +365,17 @@ public class SupplementerRegistry implements ISupplementerRegistry { // find out which of the installed bundles matches the new supplementer final Dictionary<?, ?> manifest = bundle.getHeaders(); final ManifestElement[] imports = ManifestElement.parseHeader( - Constants.IMPORT_PACKAGE, (String) manifest - .get(Constants.IMPORT_PACKAGE)); + Constants.IMPORT_PACKAGE, + (String) manifest.get(Constants.IMPORT_PACKAGE)); final ManifestElement[] exports = ManifestElement.parseHeader( - Constants.EXPORT_PACKAGE, (String) manifest - .get(Constants.EXPORT_PACKAGE)); + Constants.EXPORT_PACKAGE, + (String) manifest.get(Constants.EXPORT_PACKAGE)); if (isSupplementerMatching(bundle.getSymbolicName(), imports, exports, supplementer)) { - if (this.adaptorProvider.getAdaptor(bundle.getBundleId()) != null) { + final IWeavingAdaptor adaptor = this.adaptorProvider + .getAdaptor(bundle.getBundleId()); + if (adaptor != null && adaptor.isInitialized()) { bundlesToRefresh.add(bundle); } else { supplementer.addSupplementedBundle(bundle); @@ -415,4 +410,18 @@ public class SupplementerRegistry implements ISupplementerRegistry { refreshBundles(bundles); } } + + /** + * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setBundleContext(org.osgi.framework.BundleContext) + */ + public void setBundleContext(final BundleContext context) { + this.context = context; + } + + /** + * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setPackageAdmin(org.osgi.service.packageadmin.PackageAdmin) + */ + public void setPackageAdmin(final PackageAdmin packageAdmin) { + this.packageAdmin = packageAdmin; + } } diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java index 27b2807b0..39596e7fd 100644 --- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java +++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java @@ -43,7 +43,8 @@ public class WeavingHook extends AbstractWeavingHook { private BundleContext bundleContext; public WeavingHook() { - if (Debug.DEBUG_GENERAL) Debug.println("- AspectJHook.<init>()"); + if (Debug.DEBUG_GENERAL) Debug.println("- WeavingHook.<init>()"); + this.adaptorFactory = new WeavingAdaptorFactory(); this.adaptors = new HashMap<Long, IWeavingAdaptor>(); } @@ -51,7 +52,7 @@ public class WeavingHook extends AbstractWeavingHook { @Override public void classLoaderCreated(final ModuleClassLoader classLoader) { if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJHook.initializedClassLoader() bundle=" + Debug.println("> WeavingHook.initializedClassLoader() bundle=" + classLoader.getBundle().getSymbolicName() + ", loader=" + classLoader @@ -59,34 +60,34 @@ public class WeavingHook extends AbstractWeavingHook { + classLoader.getClasspathManager().getGeneration() .getBundleFile()); - final IWeavingAdaptor adaptor = createAspectJAdaptor(classLoader - .getClasspathManager().getGeneration()); - adaptor.setModuleClassLoader(classLoader); - adaptor.initialize(); + final IWeavingAdaptor adaptor = createWeavingAdaptor(classLoader + .getClasspathManager().getGeneration(), classLoader); this.adaptors.put(classLoader.getBundle().getBundleId(), adaptor); if (Debug.DEBUG_GENERAL) - Debug.println("< AspectJHook.initializedClassLoader() adaptor=" + Debug.println("< WeavingHook.initializedClassLoader() adaptor=" + adaptor); } - private IWeavingAdaptor createAspectJAdaptor(final Generation generation) { + private IWeavingAdaptor createWeavingAdaptor(final Generation generation, + final ModuleClassLoader classLoader) { if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJHook.createAspectJAdaptor() location=" + Debug.println("> WeavingHook.createAspectJAdaptor() location=" + generation.getRevision().getRevisions().getModule() .getLocation()); IWeavingAdaptor adaptor = null; if (adaptorFactory != null) { - adaptor = new WeavingAdaptor(generation, adaptorFactory, null, null); + adaptor = new WeavingAdaptor(generation, adaptorFactory, null, + null, classLoader); } else { if (Debug.DEBUG_GENERAL) - Debug.println("- AspectJHook.createAspectJAdaptor() factory=" + Debug.println("- WeavingHook.createAspectJAdaptor() factory=" + adaptorFactory); } if (Debug.DEBUG_GENERAL) - Debug.println("< AspectJHook.createAspectJAdaptor() adaptor=" + Debug.println("< WeavingHook.createAspectJAdaptor() adaptor=" + adaptor); return adaptor; } @@ -109,7 +110,7 @@ public class WeavingHook extends AbstractWeavingHook { private void initialize(final BundleContext context) { if (Debug.DEBUG_GENERAL) - Debug.println("> AspectJHook.initialize() context=" + context); + Debug.println("> WeavingHook.initialize() context=" + context); this.bundleContext = context; @@ -136,7 +137,7 @@ public class WeavingHook extends AbstractWeavingHook { } if (Debug.DEBUG_GENERAL) - Debug.println("< AspectJHook.initialize() adaptorFactory=" + Debug.println("< WeavingHook.initialize() adaptorFactory=" + adaptorFactory); } @@ -196,7 +197,6 @@ public class WeavingHook extends AbstractWeavingHook { * @see org.eclipse.equinox.weaving.hooks.AbstractWeavingHook#frameworkStart(org.osgi.framework.BundleContext) */ public void start(final BundleContext context) throws BundleException { - // Debug.println("? AspectJHook.frameworkStart() context=" + context + ", fdo=" + FrameworkDebugOptions.getDefault()); initialize(context); } @@ -215,16 +215,12 @@ public class WeavingHook extends AbstractWeavingHook { final Generation generation, final boolean base) { BundleFile wrapped = null; if (Debug.DEBUG_BUNDLE) - Debug.println("> AspectJBundleFileWrapperFactoryHook.wrapBundleFile() bundle=" - + generation.getRevision().getSymbolicName() - + " bundleFile=" - + bundleFile - + ", generation=" - + generation - + ", base=" - + base - + ", baseFile=" - + bundleFile.getBaseFile()); + Debug.println("> WeavingHook.wrapBundleFile() bundle=" + + (generation.getRevision() != null ? generation + .getRevision().getSymbolicName() : generation + .getBundleInfo().getBundleId()) + " bundleFile=" + + bundleFile + ", generation=" + generation + ", base=" + + base + ", baseFile=" + bundleFile.getBaseFile()); if (base) { wrapped = new BaseWeavingBundleFile(new BundleAdaptorProvider( @@ -234,8 +230,7 @@ public class WeavingHook extends AbstractWeavingHook { generation, this), bundleFile); } if (Debug.DEBUG_BUNDLE) - Debug.println("< AspectJBundleFileWrapperFactoryHook.wrapBundleFile() wrapped=" - + wrapped); + Debug.println("< WeavingHook.wrapBundleFile() wrapped=" + wrapped); return wrapped; } |