Bug 169857 - AJDT build should implement the CompilationParticipant API
Summary: AJDT build should implement the CompilationParticipant API
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal with 3 votes (vote)
Target Milestone: 2.1.2   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 170476 323454 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-01-08 11:47 EST by Sergey Olefir CLA
Modified: 2012-06-03 03:17 EDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Olefir CLA 2007-01-08 11:47:12 EST
Steps to reproduce:
(1) Install plain Eclipse SDK (3.2.1)
(2) Install AspectJ from update site (http://download.eclipse.org/tools/ajdt/32/update)
(3) Create new Java project (not AJ project for the next step to work, otherwise it is impossible to verify that APT actually works).
(4) Follow demo APT instructions (http://www.eclipse.org/jdt/apt/index.html), ensure that squiggles appear, that file is being generated. One step that might be missing on that page is that you might need to also add downloaded JAR file to project class path.
(5) Right-click project, AspectJ Tools -> Convert to AspectJ project...

At this point APT processing stops working -- you can verify this by removing/adding demo APT annotations.

If default Java builder is added to the .project file (in addition to the AspectJ builder), then APT processing will work again. However it becomes impossible to edit AJ files -- they look like one big 'error' to the default Java builder.


Of additional note -- I also tried the same on Eclipse 3.3M4 with AJDT 1.5.0 -- it results in the same problem -- APT stops working.
Comment 1 Matt Chapman CLA 2007-01-08 12:22:40 EST
Passing over to AspectJ compiler.
I suspect this is because the compiler is currently based on JDT from Eclipse 3.1.
Comment 2 Andrew Clement CLA 2007-01-08 13:36:17 EST
yep
Comment 3 Matt Chapman CLA 2007-01-15 10:13:02 EST
*** Bug 170476 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Clement CLA 2008-01-22 12:35:15 EST
Needs testing on AJDT 1.5.2 (AspectJ1.6.0m1) - as that is now Eclipse 3.3 based. That may fix it.
Comment 5 Andrew Eisenberg CLA 2008-08-22 17:00:44 EDT
Note that this is an issue with the jdt-apt, not the apt.  JDT-apt requires a 1.5-aware (or maybe it's even 1.6 now) execution environment.  The AJDT plugins expect 1.4.

So, this *might* be an AJDT problem.
Comment 6 Stephen Haberman CLA 2009-01-10 17:30:44 EST
For others affected by this, I came across:

http://www.eclipse.org/newsportal/article.php?id=1966&group=eclipse.technology.ajdt#1966

Which notes you can work around this bug by listing both the javabuilder and ajbuilder in your .project file.
Comment 7 Andrew Eisenberg CLA 2010-08-24 23:52:06 EDT
*** Bug 323454 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Eisenberg CLA 2010-08-25 00:13:18 EDT
(In reply to comment #6)
> Which notes you can work around this bug by listing both the javabuilder and
> ajbuilder in your .project file.

I'm guessing that this will work in some situations, but may cause some instability in others.  For example, the JavaBuilder is better at producing incremental state than the AJBuilder.  If the AJbuilder fails to compile certain files due to some interaction with an aspect, the JavaBuilder may still be able to build the file (albeit without weaving it).  So, the file will *look* built but it really won't be.  I can think of some other problems too.

Regardless, if you want to live on the edge, and be prepared to do full builds when things go haywire, it will likely work.  Make sure that the JavaBuilder is the second in the .project file.  

As to a possible solution, it looks like JDT implements APT through the use of a CompilationParticipant.  AJBuilder would need to be aware of Compilation participants and execute all the appropriate callbacks.  So, it looks to me like this really is an AJDT issue.  It may not be entirely difficult to implement and the AptCompilationParticipant may just work.
Comment 9 Walter Harley CLA 2010-08-25 01:07:10 EDT
(In reply to comment #8)
> As to a possible solution, it looks like JDT implements APT through the use of
> a CompilationParticipant.  AJBuilder would need to be aware of Compilation
> participants and execute all the appropriate callbacks.  So, it looks to me
> like this really is an AJDT issue.  It may not be entirely difficult to
> implement and the AptCompilationParticipant may just work.

If someone on AJDT is interested in working on this, I can help you get the compilationParticipant part working.

Also, re the question in Comment 5: APT requires a 1.5 environment in order to run Java 5 (com.sun.mirror.apt) processors, and a 1.6 environment in order to run Java 6 (javax.annotation.processing) processors.

Note that annotation processors can contribute additional Java files (which is why APT needs to use compilationParticipant rather than just being a separate builder).  Presumably those files would need to be entered into the weaving process; it becomes a loop (or a recursion) rather than a linear step.
Comment 10 Andrew Clement CLA 2010-08-25 10:47:54 EDT
> As to a possible solution, it looks like JDT implements APT through the use of
> a CompilationParticipant.  AJBuilder would need to be aware of Compilation
> participants and execute all the appropriate callbacks.  So, it looks to me
> like this really is an AJDT issue.  It may not be entirely difficult to
> implement and the AptCompilationParticipant may just work.

That's interesting, because I previously prototyped the full solution to this following JDTs usage pattern (for Spring Roo), got it working, and never changed AJDT directly...  in the end they didn't need it so I didn't finish it off.
Comment 11 Andrew Eisenberg CLA 2010-10-15 22:50:48 EDT
This is becoming more important for integration with GWT.
Comment 12 Andrew Eisenberg CLA 2010-10-18 19:37:41 EDT
Current status:

I have something in my workspace that appears to be working for a subset of the CompilationParticipant API.  It is far from being ready to commit and will not make the 2.1.1 release.  When this is complete, the following methods of BuildContext will work as expected:

getContents() : will get the contents of the file
getFile() : will get the IFile
recordDependencies(String[]) : will record a new dependency
recordNewProblems(CategorizedProblem[]) : will record new problems on this compilation unit, and these problems will appear in the file

The following pieces will not work:

hasAnnotations() : we ignore this method and always return false
recordAddedGeneratedFiles(IFile) : ignored (no-op)
recordDeletedGeneratedFiles(IFiel) : ignored (no-op)

On the CompilationParticipant class, the following methods will be respected:

aboutToBuild(IJavaProject) : called when the build is starting
buildFinished(IJavaProject) : called when the build has finished
buildStarting(BuildContext[]) : this method is actually called after the build finishes and we know exactly what has been compiled.
cleanStarting(IJavaProject) : called when a clean is starting
isActive(IJavaProject) : used to determine which participants are active for a given project
reconcile(ReconcileContext) : called after a reconcile and can register additional problems to the reconcile

Note that the compiler is not run in a loop and so that files generated by a participant are not added to the build.
The following methods are not respected
isAnnotationProcessor() : ignored.  does not process annotations
processAnnotations(BuildContext[]) : ignored
Comment 13 Andrew Eisenberg CLA 2010-11-03 16:53:45 EDT
This is now working as described in the previous comment and is a good enough implementation for now.

If we need a more complete implementation in the future, then we will work on it then.
Comment 14 Asad CLA 2011-09-26 18:59:13 EDT
It seems like I have run into this bug. Which version has the fix? I am using version 2.2.0.e36x-20110908-0800 of AJDT.
Comment 15 Andrew Eisenberg CLA 2011-09-26 19:17:41 EDT
What exactly is the problem that you are having?  The version of AJDT that you are using has all of the most recent changes for this issue.  But, the full API is has not been implemented.  Most importantly, we do not run the compiler in a loop if new files are added.  You may be hitting something like this that we do not support.

Please be specific about what problem you are seeing.
Comment 16 Asad CLA 2011-09-26 21:48:24 EDT
Here is my scenario. I have my own annotation processor which generates some code and works fine in a plain Java project. When I turn this into an AspectJ project (using Configure-> Convert to AspectJ Project), my annotation processor no longer gets invoked and the generated sources from the previous run (before the conversion) also get deleted. If I disable AspectJ for that project (using AspectJ Tools-> Remove AspectJ Capability command), my annotation processor starts working again.

(In reply to comment #15)
> What exactly is the problem that you are having?  The version of AJDT that you
> are using has all of the most recent changes for this issue.  But, the full API
> is has not been implemented.  Most importantly, we do not run the compiler in a
> loop if new files are added.  You may be hitting something like this that we do
> not support.
> 
> Please be specific about what problem you are seeing.
Comment 17 Andrew Eisenberg CLA 2011-09-26 22:44:09 EDT
Is this a Java 5 style Annotation processor or Java 6 style?  Java 6 style annotation processors are not supported.

If it is Java 5 style, then there is something that we should work on here.
Comment 18 Asad CLA 2011-09-27 17:35:27 EDT
I am using Java 6 style annotation processor and wont be able to switch to Java 5 at this time. Are you saying that AspectJ is not supported on Java 6?

Is there any workaround other than re-implementing our annotation processor using Java 5 api?
Comment 19 Andrew Eisenberg CLA 2011-09-28 11:59:57 EDT
AspectJ supports Java 6.  It is built on top of a Java 6 compiler.  However, annotation processing has not been completely implemented.
Comment 20 Asad CLA 2011-09-28 18:35:58 EDT
Thanks for the prompt responses. 
Are there plans to support this anytime soon?
Comment 21 Andrew Eisenberg CLA 2011-09-28 18:50:26 EDT
The best thing to do is to contact the aspectj-users mailing list.  Describe your problem as precisely as possible.  There may be a workaround for your purposes.  

It's not out of the question that this feature will be added in the future, but this feature is not scheduled for AspectJ 1.6.12.
Comment 22 Andrew Eisenberg CLA 2011-09-28 18:51:16 EDT
The mailing lists are here:
http://eclipse.org/aspectj/userlists.php
Comment 23 Andrew Clement CLA 2011-09-28 19:30:06 EDT
I'll comment here (as AspectJ lead).  If you mean the feature discussed as https://bugs.eclipse.org/bugs/show_bug.cgi?id=252199 - it is very unlikely to get in anytime soon, I'm afraid.
Comment 24 Piotr Sobczyk CLA 2012-06-03 03:17:40 EDT
(In reply to comment #8)
> Regardless, if you want to live on the edge, and be prepared to do full builds
> when things go haywire, it will likely work.  Make sure that the JavaBuilder is
> the second in the .project file.  

I'm using GWT Request Factory annotation processor (http://code.google.com/p/google-web-toolkit/wiki/RequestFactoryInterfaceValidation) with Eclipse and AspectJ and the only configuration in which both aspects and APT work for me is using both java builder and aspectj builder. 

But what's strange, classes are woven only if I arrange builders in opposite sequence as Andrew described - java builder before aspectj builder. It seemed for me like when javac builder is second, it overrides classes generated by aspectj (but it's only my presumption).

Support for java 6 style APT would be really useful because all Spring Roo generated GWT applications uses both AspectJ and RequestFactory which requires running java 6 style APT processor.