Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 180819 - Unable to load aspectj in netbinox
Unable to load aspectj in netbinox
Status: RESOLVED FIXED
Product: platform
Classification: Unclassified
Component: Netigso
6.x
Other Linux
: P4 (vote)
: 6.x
Assigned To: Jaroslav Tulach
issues@platform
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-02-17 03:20 UTC by bobuse
Modified: 2011-01-29 15:45 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bobuse 2010-02-17 03:20:08 UTC
Hi,

I'm trying to use aspectj in netbinox. I think it's the last missing thing to enable the integration of our equinox-based project in the NetBeans Platform. So I've created two sample equinox bundles :
 - org.simexplorer.netbinox.aspect that contains:
   - an annotation @ObjectConstructed
   - an aspect triggered when an annotated constructor is called
 - org.simexplorer.netbinox.example that have an Activator that use an 
annotated constructor

When I run my sample with pure equinox osgi console (without netbinox) with 
this command:
---------8<----------------------------------------------
java -Dosgi.bundles=aspectj-test-aspect-0.3.jar@start,\
aspectj-test-example-0.3.jar@5:start,\
com.springsource.org.aspectj.runtime-1.6.6.RELEASE.jar,\
com.springsource.org.aspectj.weaver-1.6.6.RELEASE.jar,\
org.eclipse.equinox.weaving.aspectj_1.0.0.jar@start,\
org.eclipse.equinox.weaving.hook_1.0.0.jar\
     -Dosgi.bundles.defaultStartLevel=4 \
     -Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook \
     -Daj.weaving.verbose=true \
     -Dorg.aspectj.weaver.showWeaveInfo=true \
     -Dorg.aspectj.osgi.verbose=true \
     -cp \
     org.eclipse.osgi_3.5.1.jar:org.eclipse.equinox.weaving.hook_1.0.0.jar \
     org.eclipse.core.runtime.adaptor.EclipseStarter
------------------------------------------------->8--------

I got this output :
---------8<----------------------------------------------
[org.eclipse.equinox.weaving.hook] info adding AspectJ hooks ...
[org.eclipse.equinox.weaving.aspectj] info Starting AspectJ weaving service 
...
[org.simexplorer.netbinox.example] info AspectJ Weaver Version 1.6.6 built on 
Wednesday Sep 30, 2009 at 18:55:14 GMT
[org.simexplorer.netbinox.example] info register aspect 
org.simexplorer.netbinox.aspect.ObjectConstructedAspect
[org.eclipse.equinox.weaving.aspectj] info weaving bundle 
'org.simexplorer.netbinox.example'
11 févr. 2010 17:18:00 org.simexplorer.netbinox.example.Activator start
INFO: Module started
[org.simexplorer.netbinox.example] weaveinfo Join point 'constructor-
execution(void org.simexplorer.netbinox.example.MyObject.<init>())' in Type 
'org.simexplorer.netbinox.example.MyObject' (MyObject.java:9) advised by after 
advice from 'org.simexplorer.netbinox.aspect.ObjectConstructedAspect' 
(ObjectConstructedAspect.aj:7)
11 févr. 2010 17:18:00 org.simexplorer.netbinox.example.MyObject <init>
INFO: Object creation
11 févr. 2010 17:18:00 org.simexplorer.netbinox.aspect.ObjectConstructedAspect 
ajc$after$org_simexplorer_netbinox_aspect_ObjectConstructedAspect$1$70ce0fd
INFO: Aspect triggered at object created
------------------------------------------------->8--------

Then I've create a module suite with netbinox, created a module with 
ModuleInstall that print modules states, and added as cluster my equinox 
bundles. But I got this output:
---------8<----------------------------------------------
     [exec] INFO [org.simexplorer.netbinox.example.Activator]: Module started
     [exec] INFO [org.simexplorer.netbinox.example.MyObject]: Object creation
     [exec] Module started.
     [exec] Available modules:
     [exec]   com.springsource.org.aspectj.runtime
     [exec]   com.springsource.org.aspectj.weaver
     [exec]   org.apidesign.netbinox (enabled)
     [exec]   org.eclipse.equinox.weaving.aspectj (enabled)
     [exec]   org.eclipse.equinox.weaving.hook
     [exec]   org.netbeans.bootstrap (enabled)
     [exec]   org.netbeans.core.netigso (enabled)
     [exec]   org.netbeans.core.startup (enabled)
     [exec]   org.netbeans.libs.osgi (enabled)
     [exec]   org.openide.filesystems (enabled)
     [exec]   org.openide.modules (enabled)
     [exec]   org.openide.util (enabled)
     [exec]   org.openide.util.lookup (enabled)
     [exec]   org.simexplorer.netbinox (enabled)
     [exec]   org.simexplorer.netbinox.aspect (enabled)
     [exec]   org.simexplorer.netbinox.example (enabled)
     [exec] [org.eclipse.equinox.weaving.aspectj] info Starting AspectJ 
weaving service ...
------------------------------------------------->8--------

As you can see, the aspect isn't triggered. 
org.eclipse.equinox.weaving.aspectj is well started, but its log info is 
printed at the end even if it is setted as eager.
How to startorg.eclipse.equinox.weaving.aspectj  before other bundles.
Indeed the required order is :
 1. org.eclipse.equinox.weaving.aspectj
 2. org.simexplorer.netbinox.aspect for registering the aspect defined
 3. org.simexplorer.netbinox.example the consumer

Then, I'm not sure that the fragment org.eclipse.equinox.weaving.hook is well 
loaded, even if I've added in run.args.extra :
 - -J-Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook
 - -cp:a ${basedir}/clusters/equinox-
bundles/plugins/org.eclipse.equinox.weaving.hook_1.0.0.jar to follow these 
explanations https://bugs.eclipse.org/bugs/show_bug.cgi?id=302429#c2

*** How to reproduce ***

svn co http://svn.simexplorer.org/SimExplorer/misc/aspectj-test
mvn install && ant run

Thanks a lot
Comment 1 bobuse 2010-03-19 10:56:20 UTC
Hi,

I guess that you haven't found time for my report. As this bug is highly blocker for our application, we are ready to invest time on it, but we need some hints to start debug sessions.
Do you have ideas for looking to what's wrong ?

Thank you
Comment 2 Jaroslav Tulach 2010-03-23 14:06:47 UTC
Last time I tried, I was on bad internet connection and could not pass the 12MB download step. I'll try it now.

If you want to help me, I'll be glad. I expect that you want to debug equinox. Open its sources (I guess import project from eclipse shall work). And then just start debugging your own application. Plus open the source view and add equinox sources as a source roots. That shall be it.
Comment 3 Jaroslav Tulach 2010-03-23 14:21:05 UTC
It would help to know the stacktrace when your aspect is being loaded, but I don't know how to run the standalone sample.
Comment 4 bobuse 2010-03-26 15:51:44 UTC
We've found a solution :-)

The problem was effectively that the weaving.hook library wasn't loaded from the startup classloader. So I've added this library as wrapped library in the netbinox module, and now my sample is working as excepted.

For instance, I've published this patched netbinox on our maven repository, we need to make test on our application.
I don't know if this solution is clean enough for you … maybe this requirement is general for the equinox extensions, and you may add a more clever feature.
Comment 5 Jaroslav Tulach 2010-03-29 11:35:46 UTC
What is the stack trace that loads your hook now? Something along these lines in equinox shall be fixed to not expect the hook be loaded by the same classloader as equinox...
Comment 6 bobuse 2010-03-29 14:28:09 UTC
I haven't found how to plug equinox sources in Netbeans debugger.
I don't remember any specific task that I've done in the past when I did it successfully.
I've opened equinox sources in a netbeans project, and putted some breakpoints, but nothing append… if you have some hints, I've no enough time yet for that.

Thank you
Comment 7 bobuse 2010-03-31 13:57:26 UTC
I've redesigned my sample, so to get the module suite:

svn co http://svn.simexplorer.org/SimExplorer/misc/aspectj-test
cd aspectj-test
mvn install

It will built my sample equinox bundles and download needed bundles for aspectj, and netbinox.
Then you have a netbeans module suite in the sub-directory "netbeans-suite" that is configured to be built with the extracted netbinox.

If anyone want inspect it… :-)
Comment 8 Jaroslav Tulach 2010-03-31 15:19:03 UTC
(In reply to comment #7)
> I've redesigned my sample, so to get the module suite:

If I do this, we the aspectj work or will it be broken? I still need a stacktrace from successful showing how the aspect class will get loaded.
Comment 9 bobuse 2010-04-02 13:37:50 UTC
If you get my sources and built the module suite, it may working … aspectj is well loaded when message log "info Starting AspectJ weaving service" is displayed at the begin.

The subfolder equinox-product contains a working equinox environment that make aspects working for sure. I've tried to import the aspectj hook sources to debug, but without success …
Comment 10 bobuse 2010-04-28 10:17:41 UTC
Well, I have the stacktrace of the message "info Starting AspectJ weaving service" when started in raw equinox environment, so with a correct behaviour:

[java.lang.Thread.getStackTrace(Thread.java:1436), org.eclipse.equinox.weaving.aspectj.AspectJWeavingActivator.start(AspectJWeavingActivator.java:77), org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783), java.security.AccessController.doPrivileged(Native Method), org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774), org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755), org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352), org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:370), org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1068), org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:557), org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:464), org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:248), org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:445), org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227), org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:337)]

It was difficult for me to get a correct environment for working with equinox sources in eclipse, but I have found a good way. I have installed aspectj from this update site http://download.eclipse.org/tools/ajdt/35/update including source (in the installation options). Then I have opened the window "Plug-in dev -> Plug-ins", found the bundle org.eclipse.equinox.weaving.aspectj, right-click "Import as->Source project".

This afternoon, I'll try to get the stacktrace when started from netbinox.
Comment 11 bobuse 2010-04-28 13:06:25 UTC
And the stacktrace in netbinox environment is:
java.lang.Exception: Stack trace
	at java.lang.Thread.dumpStack(Thread.java:1206)
	at org.eclipse.equinox.weaving.aspectj.AspectJWeavingActivator.start(AspectJWeavingActivator.java:77)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:370)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1068)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:557)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:464)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:248)
	at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalStart(EquinoxLauncher.java:281)
	at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.start(EquinoxLauncher.java:251)
	at org.eclipse.osgi.launch.Equinox.start(Equinox.java:169)
	at org.netbeans.core.netigso.Netigso.start(Netigso.java:133)
	at org.netbeans.NetigsoFramework.turnOn(NetigsoFramework.java:137)
	at org.netbeans.ModuleManager.enable(ModuleManager.java:928)
	at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:315)
	at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:251)
	at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:283)
	at org.netbeans.core.startup.Main.getModuleSystem(Main.java:169)
	at org.netbeans.core.startup.Main.start(Main.java:299)
	at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:111)
	at java.lang.Thread.run(Thread.java:619)

It is the same when it fails or success, so I assume that the netbeans module system doesn't have enough priority information do load it early.

From stacktrace, I can only observe that they differ before entering in org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:248)

I don't know if it helps you to understand what's wrong…
Comment 12 bobuse 2010-04-28 13:43:28 UTC
I've done the same for the module org.eclipse.equinox.weaving.hook:

In raw equinox environment:
java.lang.Exception: Stack trace
        at java.lang.Thread.dumpStack(Thread.java:1206)
        at org.eclipse.equinox.weaving.hooks.AbstractAspectJHook.addHooks(AbstractAspectJHook.java:78)
        at org.eclipse.osgi.baseadaptor.HookRegistry.loadConfigurators(HookRegistry.java:178)
        at org.eclipse.osgi.baseadaptor.HookRegistry.initialize(HookRegistry.java:100)
        at org.eclipse.osgi.baseadaptor.BaseAdaptor.<init>(BaseAdaptor.java:96)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.createAdaptor(EclipseStarter.java:747)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:282)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:175)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:150)


In netbinox environment:
java.lang.Exception: Stack trace
        at java.lang.Thread.dumpStack(Thread.java:1206)
        at org.eclipse.equinox.weaving.hooks.AbstractAspectJHook.addHooks(AbstractAspectJHook.java:78)
        at org.eclipse.osgi.baseadaptor.HookRegistry.loadConfigurators(HookRegistry.java:178)
        at org.eclipse.osgi.baseadaptor.HookRegistry.initialize(HookRegistry.java:100)
        at org.eclipse.osgi.baseadaptor.BaseAdaptor.<init>(BaseAdaptor.java:96)
        at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalInit(EquinoxLauncher.java:68)
        at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.init(EquinoxLauncher.java:38)
        at org.eclipse.osgi.launch.Equinox.init(Equinox.java:89)
        at org.netbeans.core.netigso.Netigso.prepare(Netigso.java:110)
        at org.netbeans.NetigsoFramework.turnOn(NetigsoFramework.java:133)
        at org.netbeans.ModuleManager.enable(ModuleManager.java:928)
        at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:315)
        at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:251)
        at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:283)
        at org.netbeans.core.startup.Main.getModuleSystem(Main.java:169)
        at org.netbeans.core.startup.Main.start(Main.java:299)
        at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:111)
        at java.lang.Thread.run(Thread.java:619)
[org.eclipse.equinox.weaving.hook] info adding AspectJ hooks ...
Comment 13 Jaroslav Tulach 2010-05-07 07:13:41 UTC
OK, so I think the problem is in HookRegistry:

private void loadConfigurators(ArrayList configurators, ArrayList errors) {
  for (Iterator iHooks = configurators.iterator();iHooks.hasNext();) {
    String hookName = (String) iHooks.next();
    Class clazz = Class.forName(hookName);

it is using Class.forName. That means only classes directly visible by the equinox.jar are accessible. This is not really suitable for modular system and implies that you basically need to load equinox.jar and aspectj weaving module by the same classloader (which you did).

If the above code used 

    ClassLoader l = Thread.currentThread().getContextClassLoader();
    Class.forName(hookName, true, l);

then the loading succeeded even in case the aspectj weaving module would be in its own JAR with dependency on the module providing equinox.jar (your original setup).

So right now there does not seem to be anything I can do on our side (except writing a blog). Try to talk to the equinox guys and convince them to load the hooks via context classloader (that will be compatible for them and open up doors to integrate equinox in modular environment). Good luck!

Btw. there is buddy classloading (see http://wiki.eclipse.org/Context_Class_Loader_Enhancements), but that is probably not going to work on loading the framework itself.
Comment 14 Jaroslav Tulach 2010-05-07 08:24:46 UTC
Blog published: http://wiki.apidesign.org/wiki/BootstrappingEquinox

Now it is up to you to deal with Equinox team.
Comment 15 bobuse 2010-05-07 13:53:56 UTC
Thanks a lot for your investigations !!
Your conclusions are enlightening.

So, I've tried to patch equinox with your proposition, and to made a new archive of netbinox to build my modules suite.

I've made some tests, and it seems to work.

Thank you very much.
Comment 16 bobuse 2010-05-07 14:54:11 UTC
Hmmm, in fact, it doesn't work at each time.
Do you think that the code you've pointed is the single problem for loading the weaver?
Or maybe, I've made a misconfiguration in my modules suite:
http://www.simexplorer.org/browser/misc/aspectj-test/netbeans-suite
Comment 17 bobuse 2010-05-07 15:28:09 UTC
Well, I've added some debug info to the HookRegistry class and get this output:
-----------8<----------------------------------------------
Equinox loading a hook: org.eclipse.osgi.internal.baseadaptor.BaseHookConfigurator
Equinox loading a hook: org.eclipse.osgi.internal.baseadaptor.DevClassLoadingHook
Equinox loading a hook: org.eclipse.core.runtime.internal.adaptor.EclipseStorageHook
Equinox loading a hook: org.eclipse.core.runtime.internal.adaptor.EclipseLogHook
Equinox loading a hook: org.eclipse.core.runtime.internal.adaptor.EclipseErrorHandler
Equinox loading a hook: org.eclipse.core.runtime.internal.adaptor.EclipseAdaptorHook
Equinox loading a hook: org.eclipse.core.runtime.internal.adaptor.EclipseClassLoadingHook
Equinox loading a hook: org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter
Equinox loading a hook: org.eclipse.core.runtime.internal.stats.StatsManager
Equinox loading a hook: org.eclipse.osgi.internal.signedcontent.SignedBundleHook
Equinox loading a hook: org.eclipse.osgi.internal.composite.CompositeConfigurator
Equinox loading a hook: org.eclipse.equinox.weaving.hooks.WeavingHook
[org.eclipse.equinox.weaving.hook] info adding AspectJ hooks ...
Equinox loading a hook: org.apidesign.netbinox.NetigsoHooks
INFO [org.simexplorer.netbinox.example.Activator]: Module started
INFO [org.simexplorer.netbinox.example.MyObject]: Object creation
Module started.
Available modules:
  com.springsource.org.aspectj.runtime
  com.springsource.org.aspectj.weaver
  org.apidesign.netbinox (enabled)
  org.eclipse.equinox.weaving.aspectj (enabled)
  org.eclipse.equinox.weaving.hook
  org.netbeans.bootstrap (enabled)
  org.netbeans.core.netigso (enabled)
  org.netbeans.core.osgi
  org.netbeans.core.startup (enabled)
  org.netbeans.libs.osgi (enabled)
  org.openide.filesystems (enabled)
  org.openide.modules (enabled)
  org.openide.util (enabled)
  org.openide.util.lookup (enabled)
  org.simexplorer.netbinox (enabled)
  org.simexplorer.netbinox.aspect (enabled)
  org.simexplorer.netbinox.example (enabled)
[org.eclipse.equinox.weaving.aspectj] info Starting AspectJ weaving service ...
---------------------->8-------------------------------------------

I don't understand why the weaving service is started too late…
But maybe, I should ask the question to the equinox staff ;-)
… next week
Comment 18 Jaroslav Tulach 2011-01-29 14:53:21 UTC
I am working on a fix that will allow anyone to add new additional HookConfigurator.
Comment 19 Jaroslav Tulach 2011-01-29 15:45:08 UTC
Fixed in 1.16.7 version of Netbinox:
http://wiki.apidesign.org/wiki/NetbinoxHook


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo