diff options
author | Martin Lippert | 2008-07-30 20:26:42 +0000 |
---|---|---|
committer | Martin Lippert | 2008-07-30 20:26:42 +0000 |
commit | a26d88054080cef5fba4a5c37c988cbf306820a0 (patch) | |
tree | 2726046041f3c5b17acdb2a9b3766f1061e3e6cf /bundles | |
parent | 0fc3608171cbe8fa852178ab6ea55bd1295fe22e (diff) | |
download | rt.equinox.bundles-a26d88054080cef5fba4a5c37c988cbf306820a0.tar.gz rt.equinox.bundles-a26d88054080cef5fba4a5c37c988cbf306820a0.tar.xz rt.equinox.bundles-a26d88054080cef5fba4a5c37c988cbf306820a0.zip |
formatted and cached classes are not stored again in cache
Diffstat (limited to 'bundles')
-rw-r--r-- | bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java | 299 |
1 files changed, 161 insertions, 138 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java index e11fbab28..de3f02a6a 100644 --- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java +++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java @@ -10,6 +10,7 @@ * Matthew Webster Eclipse 3.2 changes * Martin Lippert supplementing mechanism reworked *******************************************************************************/ + package org.eclipse.equinox.weaving.hooks; import java.io.IOException; @@ -32,143 +33,165 @@ import org.osgi.service.packageadmin.PackageAdmin; public class AspectJHook extends AbstractAspectJHook { - private BundleContext bundleContext; - private AspectJAdaptorFactory adaptorFactory; - - public AspectJHook () { - if (Debug.DEBUG_GENERAL) Debug.println("- AspectJHook.<init>()"); - adaptorFactory = new AspectJAdaptorFactory(); - } - - private void initialize (BundleContext context) { - if (Debug.DEBUG_GENERAL) Debug.println("> AspectJHook.initialize() context=" + context); - - this.bundleContext = context; - adaptorFactory.initialize(context, getSupplementerRegistry()); - - ServiceReference serviceReference = context.getServiceReference(PackageAdmin.class.getName()); - PackageAdmin packageAdmin = (PackageAdmin) context.getService(serviceReference); - - getSupplementerRegistry().setBundleContext(context); - getSupplementerRegistry().setPackageAdmin(packageAdmin); - context.addBundleListener(new SupplementBundleListener(getSupplementerRegistry())); - - if (Debug.DEBUG_GENERAL) Debug.println("< AspectJHook.initialize() adaptorFactory=" + adaptorFactory); - } - - public void frameworkStart(BundleContext context) throws BundleException { -// Debug.println("? AspectJHook.frameworkStart() context=" + context + ", fdo=" + FrameworkDebugOptions.getDefault()); - initialize(context); - } - - public void recordClassDefine(String name, Class clazz, byte[] classbytes, - ClasspathEntry classpathEntry, BundleEntry entry, - ClasspathManager manager) { - if (entry instanceof AspectJBundleEntry) { - AspectJBundleEntry ajBundleEntry = (AspectJBundleEntry)entry; - IAspectJAdaptor adaptor = ajBundleEntry.getAdaptor(); - URL sourceFileURL = ajBundleEntry.getBundleFileURL(); - adaptor.storeClass(name,sourceFileURL,clazz,classbytes); - } - } - - public void initializedClassLoader(BaseClassLoader baseClassLoader, - BaseData data) { - if (Debug.DEBUG_GENERAL) Debug.println("> AspectJHook.initializedClassLoader() bundle=" + data.getSymbolicName() + ", loader=" + baseClassLoader + ", data=" + data + ", bundleFile=" + data.getBundleFile()); - IAspectJAdaptor adaptor = null; - BundleFile bundleFile = data.getBundleFile(); - if (bundleFile instanceof BaseAjBundleFile) { - BaseAjBundleFile baseBundleFile = (BaseAjBundleFile)bundleFile; - adaptor = baseBundleFile.getAdaptor(); - adaptor.setBaseClassLoader(baseClassLoader); - } - - if (Debug.DEBUG_GENERAL) Debug.println("< AspectJHook.initializedClassLoader() adaptor=" + adaptor); - } - - public byte[] processClass(String name, byte[] classbytes, - ClasspathEntry classpathEntry, BundleEntry entry, - ClasspathManager manager) { - byte[] newClassytes = null; - if (entry instanceof AspectJBundleEntry) { - AspectJBundleEntry ajBundleEntry = (AspectJBundleEntry)entry; - if (!ajBundleEntry.dontWeave()) { - IAspectJAdaptor adaptor = ajBundleEntry.getAdaptor(); - newClassytes = adaptor.weaveClass(name,classbytes); - } - } - return newClassytes; - } - - public BundleFile wrapBundleFile(BundleFile bundleFile, Object content, - BaseData data, boolean base) throws IOException { - BundleFile wrapped = null; - if (Debug.DEBUG_BUNDLE) Debug.println("> AspectJBundleFileWrapperFactoryHook.wrapBundleFile() bundle=" + data.getSymbolicName() + " bundleFile=" + bundleFile + ", content=" + content + ", data=" + data + ", base=" + base + ", baseFile=" + bundleFile.getBaseFile()); - -// IAspectJAdaptor adaptor = null; -// if (base) { -// adaptor = createAspectJAdaptor(data); -// } -// else if (bundleContext != null) { -// adaptor = getAspectJAdaptor(data); -// } -// -// if (adaptor != null) { -// if (bundleFile instanceof DirBundleFile) { -// wrapped = new BaseAjBundleFile(adaptor,bundleFile); -// } -// else { -// wrapped = new AspectJBundleFile(adaptor,bundleFile); -// } -// } -// if (Debug.DEBUG_BUNDLE) Debug.println("< AspectJBundleFileWrapperFactoryHook.wrapBundleFile() wrapped=" + wrapped + ", adaptor=" + adaptor); - - if (base) { - IAspectJAdaptor adaptor = createAspectJAdaptor(data); - if (adaptor != null) { - wrapped = new BaseAjBundleFile(adaptor, bundleFile); - } - } - else { - IAspectJAdaptor adaptor = null; - if (bundleContext != null) { - adaptor = getAspectJAdaptor(data); - if (Debug.DEBUG_BUNDLE) Debug.println("- AspectJBundleFileWrapperFactoryHook.wrapBundleFile() adaptor=" + adaptor); -// if (adaptor == null) throw new RuntimeException(data.getSymbolicName()); - } - if (adaptor != null) { - wrapped = new AspectJBundleFile(adaptor,bundleFile); - } - } - if (Debug.DEBUG_BUNDLE) Debug.println("< AspectJBundleFileWrapperFactoryHook.wrapBundleFile() wrapped=" + wrapped); - return wrapped; - } - - private IAspectJAdaptor createAspectJAdaptor (BaseData baseData) { - if (Debug.DEBUG_GENERAL) Debug.println("> AspectJHook.createAspectJAdaptor() location=" + baseData.getLocation()); - IAspectJAdaptor adaptor = null; - - if (adaptorFactory != null) { - adaptor = new AspectJAdaptor(baseData,adaptorFactory,null,null,null); - } - else { - if (Debug.DEBUG_GENERAL) Debug.println("- AspectJHook.createAspectJAdaptor() factory=" + adaptorFactory); - } - - if (Debug.DEBUG_GENERAL) Debug.println("< AspectJHook.createAspectJAdaptor() adaptor=" + adaptor); - return adaptor; - } - - private IAspectJAdaptor getAspectJAdaptor (BaseData data) { - IAspectJAdaptor adaptor = null; - - BundleFile bundleFile = data.getBundleFile(); - if (bundleFile instanceof BaseAjBundleFile) { - BaseAjBundleFile baseBundleFile = (BaseAjBundleFile)bundleFile; - adaptor = baseBundleFile.getAdaptor(); - } - - return adaptor; - } + private BundleContext bundleContext; + + private AspectJAdaptorFactory adaptorFactory; + + public AspectJHook() { + if (Debug.DEBUG_GENERAL) Debug.println("- AspectJHook.<init>()"); + adaptorFactory = new AspectJAdaptorFactory(); + } + + private void initialize(BundleContext context) { + if (Debug.DEBUG_GENERAL) + Debug.println("> AspectJHook.initialize() context=" + context); + + this.bundleContext = context; + adaptorFactory.initialize(context, getSupplementerRegistry()); + + ServiceReference serviceReference = context + .getServiceReference(PackageAdmin.class.getName()); + PackageAdmin packageAdmin = (PackageAdmin) context + .getService(serviceReference); + + getSupplementerRegistry().setBundleContext(context); + getSupplementerRegistry().setPackageAdmin(packageAdmin); + context.addBundleListener(new SupplementBundleListener( + getSupplementerRegistry())); + + if (Debug.DEBUG_GENERAL) + Debug.println("< AspectJHook.initialize() adaptorFactory=" + + adaptorFactory); + } + + public void frameworkStart(BundleContext context) throws BundleException { + // Debug.println("? AspectJHook.frameworkStart() context=" + context + ", fdo=" + FrameworkDebugOptions.getDefault()); + initialize(context); + } + + public void recordClassDefine(String name, Class clazz, byte[] classbytes, + ClasspathEntry classpathEntry, BundleEntry entry, + ClasspathManager manager) { + if (entry instanceof AspectJBundleEntry) { + AspectJBundleEntry ajBundleEntry = (AspectJBundleEntry) entry; + if (!ajBundleEntry.dontWeave()) { + IAspectJAdaptor adaptor = ajBundleEntry.getAdaptor(); + URL sourceFileURL = ajBundleEntry.getBundleFileURL(); + adaptor.storeClass(name, sourceFileURL, clazz, classbytes); + } + } + } + + public void initializedClassLoader(BaseClassLoader baseClassLoader, + BaseData data) { + if (Debug.DEBUG_GENERAL) + Debug + .println("> AspectJHook.initializedClassLoader() bundle=" + + data.getSymbolicName() + ", loader=" + + baseClassLoader + ", data=" + data + + ", bundleFile=" + data.getBundleFile()); + IAspectJAdaptor adaptor = null; + BundleFile bundleFile = data.getBundleFile(); + if (bundleFile instanceof BaseAjBundleFile) { + BaseAjBundleFile baseBundleFile = (BaseAjBundleFile) bundleFile; + adaptor = baseBundleFile.getAdaptor(); + adaptor.setBaseClassLoader(baseClassLoader); + } + + if (Debug.DEBUG_GENERAL) + Debug.println("< AspectJHook.initializedClassLoader() adaptor=" + + adaptor); + } + + public byte[] processClass(String name, byte[] classbytes, + ClasspathEntry classpathEntry, BundleEntry entry, + ClasspathManager manager) { + byte[] newClassytes = null; + if (entry instanceof AspectJBundleEntry) { + AspectJBundleEntry ajBundleEntry = (AspectJBundleEntry) entry; + if (!ajBundleEntry.dontWeave()) { + IAspectJAdaptor adaptor = ajBundleEntry.getAdaptor(); + newClassytes = adaptor.weaveClass(name, classbytes); + } + } + return newClassytes; + } + + public BundleFile wrapBundleFile(BundleFile bundleFile, Object content, + BaseData data, boolean base) throws IOException { + BundleFile wrapped = null; + if (Debug.DEBUG_BUNDLE) + Debug + .println("> AspectJBundleFileWrapperFactoryHook.wrapBundleFile() bundle=" + + data.getSymbolicName() + + " bundleFile=" + + bundleFile + + ", content=" + + content + + ", data=" + + data + + ", base=" + + base + + ", baseFile=" + + bundleFile.getBaseFile()); + + if (base) { + IAspectJAdaptor adaptor = createAspectJAdaptor(data); + if (adaptor != null) { + wrapped = new BaseAjBundleFile(adaptor, bundleFile); + } + } else { + IAspectJAdaptor adaptor = null; + if (bundleContext != null) { + adaptor = getAspectJAdaptor(data); + if (Debug.DEBUG_BUNDLE) + Debug + .println("- AspectJBundleFileWrapperFactoryHook.wrapBundleFile() adaptor=" + + adaptor); + // if (adaptor == null) throw new RuntimeException(data.getSymbolicName()); + } + if (adaptor != null) { + wrapped = new AspectJBundleFile(adaptor, bundleFile); + } + } + if (Debug.DEBUG_BUNDLE) + Debug + .println("< AspectJBundleFileWrapperFactoryHook.wrapBundleFile() wrapped=" + + wrapped); + return wrapped; + } + + private IAspectJAdaptor createAspectJAdaptor(BaseData baseData) { + if (Debug.DEBUG_GENERAL) + Debug.println("> AspectJHook.createAspectJAdaptor() location=" + + baseData.getLocation()); + IAspectJAdaptor adaptor = null; + + if (adaptorFactory != null) { + adaptor = new AspectJAdaptor(baseData, adaptorFactory, null, null, + null); + } else { + if (Debug.DEBUG_GENERAL) + Debug.println("- AspectJHook.createAspectJAdaptor() factory=" + + adaptorFactory); + } + + if (Debug.DEBUG_GENERAL) + Debug.println("< AspectJHook.createAspectJAdaptor() adaptor=" + + adaptor); + return adaptor; + } + + private IAspectJAdaptor getAspectJAdaptor(BaseData data) { + IAspectJAdaptor adaptor = null; + + BundleFile bundleFile = data.getBundleFile(); + if (bundleFile instanceof BaseAjBundleFile) { + BaseAjBundleFile baseBundleFile = (BaseAjBundleFile) bundleFile; + adaptor = baseBundleFile.getAdaptor(); + } + + return adaptor; + } } |