Community
Participate
Working Groups
Created attachment 250406 [details] Patch for AspectJ weaver to enable dynamic weaver attachment Currently the weaving agent in aspectjweaver.jar does not contain an 'agentmain' method and a corresponding manifest entry. I added those to the code and patched my JAR with the updated Agent.class and MANIFEST.MF. Now dynamically attaching the agent to the current classloader works. I am attaching - a patch against current Git master, - an Eclipse sample project showing the effect. You need to adjust the path of tools.jar (needed for compilation). A patched version of aspectjweaver.jar and a sample aspect.jar with a 'before() : execution(* *(..))' pointcut (so we have something to weave) are contained in the 'lib' subdirectory. If you just run the 'Application' class as a Java, it will determine that the aspect weaver has not been loaded and attach it dynamically. Subsequently defined/loaded classes will then be subject to weaving as can be seen in the console output: Hello world! java.lang.UnsupportedOperationException: AspectJ weaving agent was neither started via '-javaagent' (preMain) nor attached via 'VirtualMachine.loadAgent' (agentMain) [AppClassLoader@2d63c5bb] info AspectJ Weaver Version 1.8.4 built on Thursday Nov 6, 2014 at 20:19:21 GMT [AppClassLoader@2d63c5bb] info register classloader sun.misc.Launcher$AppClassLoader@2d63c5bb [AppClassLoader@2d63c5bb] info using configuration file:/C:/Users/Alexander/Documents/java-src/SO_AJ_LTW_CheckIfWeaverIsLoaded/lib/aspect.jar!/META-INF/aop.xml [AppClassLoader@2d63c5bb] info register aspect com.aspect.generic.GenericAspect [AppClassLoader@2d63c5bb] weaveinfo Join point 'method-execution(void de.scrum_master.app.Dummy.doSomething())' in Type 'de.scrum_master.app.Dummy' (Dummy.java:4) advised by before advice from 'com.aspect.generic.GenericAspect' (GenericAspect.aj) [AppClassLoader@2d63c5bb] weaveinfo Join point 'method-execution(int de.scrum_master.app.Dummy.square(int))' in Type 'de.scrum_master.app.Dummy' (Dummy.java:9) advised by before advice from 'com.aspect.generic.GenericAspect' (GenericAspect.aj) execution(void de.scrum_master.app.Dummy.doSomething()) Do something execution(int de.scrum_master.app.Dummy.square(int)) Square of 7 = 49 [AppClassLoader@2d63c5bb] weaveinfo Join point 'method-execution(void de.scrum_master.app.Application$1.run())' in Type 'de.scrum_master.app.Application$1' (Application.java:50) advised by before advice from 'com.aspect.generic.GenericAspect' (GenericAspect.aj) execution(void de.scrum_master.app.Application.1.run()) Anonymous runnable Hello world!
Created attachment 250407 [details] Sample Eclipse project showing how to dynamically attach the weaving agent
Cool stuff. Have you signed the eclipse CLA?
LOL. Maybe I will as soon as AspectJ has a clean Maven build. ;-P
BTW, just so as not to spark false hopes in anyone reading this ticket, I want to mention that reloading or retransforming already loaded classes without aspects and replacing them by woven classes will not work because reloading/retransforming only works if no members or methods are added to the class in question. But AspectJ does change the class structure that way, so theoretically it would only be possible to reload/retransform classes which already contain aspect code (e.g. via CTW) under the condition that the newly LT-woven class has the same structure as the previously CT-woven one.
Well I did a local build and tested with the changes and it works (aspectjweaver produced by the build satisfies your test program). So I could take the change without any regression tests (which isn't totally ideal but I guess they are tricky to write) but I would still need to have the CLA signed to accept it.
Seriously? I thought that was a joke. OMG, next time maybe I just create a bug ticket without a patch attached. I am nkt a committer, I just shggested a minor improvement. Just out of curiosity: Where do I find this CLA and how the heck do I sign it?
Unfortunately not a joke. It shouldn't be too painful but it is part of the process. It is now embedded in bugzilla so you can see my comments have a CLA icon next to them with a green tick. Whilst yours do not, if you click that icon, I think it takes you to where to sign it. From the CLA page: "The Eclipse Foundation has implemented Contributor License Agreements (CLA) to improve its intellectual property (IP) management and workflow. In part, CLAs are a portion of the work required to implement signed-off-by for all contributions coming to Eclipse via Git or Gerrit. All contributors are required to sign the CLA before contributing to any Eclipse project they are not a committer on." I'd like to take the change if you are able to sign that. Should be once and not for every contribution.
Sorry, I was busy. I have just signed the CLA. As AspectJ 1.8.5 is already out, my changed will only make it into 1.8.6, I figure. My bad. :-)
Ha Ha. Just wanted to request the same fix. +1 for merging this into one of the upcoming releases.
Andy, is anything blocking this one? It could have been in 1.8.6, but does not seem to be.
It is in for 1.8.7