Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360427

Summary: Tycho JDT compiler does not support annotations
Product: z_Archived Reporter: Missing name <thomas.demande>
Component: TychoAssignee: Jan Sievers <jan.sievers>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: benjamin.jung, igor, jan.sievers, marcel.bruch, pascal, t-oberlies, vhaisman, wayne.beaton
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: hasPatch
Attachments:
Description Flags
Eclipse JDT APT jar
none
Patch that enabled annotation processing for tycho-jdt-compiler
none
reworked patch to apply to HEAD
none
APT project properties - screenshot
none
test failure log
none
patch with copyright headers added jan.sievers: iplog+

Description Missing name CLA 2011-10-10 08:01:39 EDT
Build Identifier: 

Although Maven compiler API does contain configuration for using APT during compilation, Tycho JDT implementation does not use any.

Activating it is rather simple, as the compiler does support it.

Reproducible: Always

Steps to Reproduce:
1. Configure the compiler to use an annotation processor
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
					<fork>false</fork>
					<compilerId>jdt</compilerId>
					<annotationProcessors>
						<annotationProcessor>com.acme.apt.AnnotationProcessor</annotationProcessor>
					</annotationProcessors>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.eclipse.tycho</groupId>
						<artifactId>tycho-compiler-jdt</artifactId>
						<version>0.14.0-SNAPSHOT</version>
					</dependency>
					<!-- dependency  containing the annotation processor specified in the annotationProcessor element -->
					<dependency>
						<groupId>com.acme.apt</groupId>
	      				<artifactId>com.acme.apt.super-processor</artifactId>
	      				<version>1.0.0-SNAPSHOT</version>
					</dependency>
				</dependencies>
			</plugin>

2. Launch the compile phase on a project whose sources contains annotations that should be processed by your processor.
3. Annotation processing is not triggered.
Comment 1 Missing name CLA 2011-10-10 08:03:39 EDT
Created attachment 204872 [details]
Eclipse JDT APT jar

As the org.eclipse.jdt.core-3.8.0.v_C03.jar does not contain APT-related classes, this one should also be used in the compiler project dependencies
Comment 2 Missing name CLA 2011-10-10 08:04:28 EDT
Created attachment 204873 [details]
Patch that enabled annotation processing for tycho-jdt-compiler
Comment 3 Missing name CLA 2011-10-10 08:04:57 EDT
Initially filled under https://issues.sonatype.org/browse/TYCHO-590
Comment 4 Jan Sievers CLA 2011-12-05 10:21:17 EST
Created attachment 207924 [details]
reworked patch to apply to HEAD

patch did not apply to HEAD anymore.

Questions/Remarks:

- it seems this patch mixes fixes for unrelated issues such as error parsing and compiler option defaults. I would like to keep these out of this bug (we can open other bugs for these)

- The test project currently fails for me and a test class which builds the test project was missing

- the patch only covers the usecase of using the JDT compiler in the context of packaging type "jar". The important case of packaging type "eclipse-plugin" is not covered (and we will need more modifications to the tycho copy of AbstractCompilerMojo to make this work... which brings back the question if we really want to maintain a fork of AbstractCompilerMojo :(

- note to committers: we will need to file CQs for new versions of plexus-compiler-api and plexus-compiler-manager (plus potentially respective dependencies)
Comment 5 Igor Fedorenko CLA 2011-12-05 10:59:30 EST
(In reply to comment #4)
> 
> - the patch only covers the usecase of using the JDT compiler in the context of
> packaging type "jar". The important case of packaging type "eclipse-plugin" is
> not covered (and we will need more modifications to the tycho copy of

I think APT support for eclipse-plugin is a separate usecase.

> AbstractCompilerMojo to make this work... which brings back the question if we
> really want to maintain a fork of AbstractCompilerMojo :(
> 

We never *wanted* to maintain a fork of AbstractCompilerMojo, so the real question is -- what it takes to get rid of the fork and who is going to do the work?

Another, related question, does PDE support APT inside workspace?
Comment 6 Jan Sievers CLA 2011-12-06 04:35:51 EST
(In reply to comment #5)
> Another, related question, does PDE support APT inside workspace?

It looks like there is generic support for APT from JDT which can also be added to a PDE workspace project (see screenshot). This will add a generated source folder and create a .settings/org.eclipse.jdt.apt.core.prefs.

From the PDE headless build, looks like it can be supported via custom callbacks.
Comment 7 Jan Sievers CLA 2011-12-06 04:36:22 EST
Created attachment 207960 [details]
APT project properties - screenshot
Comment 8 Missing name CLA 2011-12-06 05:26:13 EST
(In reply to comment #4)
> Created attachment 207924 [details]
> reworked patch to apply to HEAD
> 
> patch did not apply to HEAD anymore.
> 
> Questions/Remarks:
> 
> - it seems this patch mixes fixes for unrelated issues such as error parsing
> and compiler option defaults. I would like to keep these out of this bug (we
> can open other bugs for these)
> 

OK, I'll open separate issues for these concerns.

> - The test project currently fails for me and a test class which builds the
> test project was missing

Test might be failing because of a mismatch in properties.
In the org.eclipse.tycho.tychoits.TYCHO590 pom, the declared property 'tycho.version' should probably just be changed into tycho-version.
I you still get the issue, just send the result.

> - the patch only covers the usecase of using the JDT compiler in the context of
> packaging type "jar". The important case of packaging type "eclipse-plugin" is
> not covered (and we will need more modifications to the tycho copy of
> AbstractCompilerMojo to make this work... which brings back the question if we
> really want to maintain a fork of AbstractCompilerMojo :(
> 
> - note to committers: we will need to file CQs for new versions of
> plexus-compiler-api and plexus-compiler-manager (plus potentially respective
> dependencies)

Thanks anyway for reworking the patch to be usable with the current HEAD and some project-specific features I didn't see.
Comment 9 Jan Sievers CLA 2011-12-06 09:41:29 EST
Created attachment 207994 [details]
test failure log
Comment 10 Jan Sievers CLA 2011-12-06 09:43:55 EST
(In reply to comment #9)
tycho.version was just a leftover from the original patch, it's not used anymore.

How to reproduce?

- git clone http://git.eclipse.org/gitroot/tycho/org.eclipse.tycho.git
- apply patch using 'git am'
- build tycho using 'mvn clean install'
- run test using 'cd tycho-its; mvn clean test -Dtest=AnnotationProcessorTest'
Comment 11 Missing name CLA 2011-12-06 10:21:18 EST
(In reply to comment #10)
In am only able to reproduce the error if I remove the JDT apt JAR (org.eclipse.tycho:org.eclipse.jdt.core:jar:apt:3.8.0.v_C03) from the tycho-compiler-jdt module.

Eclipse compiler system will just skip annotation processing if classes aren't present in the classpath, without producing any errors.

I APT is triggered, you should see these lines in the non-debug Maven output, during compiler execution:

[APT] Source file already created : tycho590.processed.Processor
1. WARNING: No SupportedSourceVersion annotation found on tycho590.JSR269Processor, returning RELEASE_6.
1 problem (1 warning)

But seeing your test log, the JDT apt JAR does seem to be in the classpath for compilation. Is it possible that you used a different JAR than the one attached to this issue?
Comment 12 Jan Sievers CLA 2011-12-06 10:46:17 EST
(In reply to comment #11)
> But seeing your test log, the JDT apt JAR does seem to be in the classpath for
> compilation. Is it possible that you used a different JAR than the one attached
> to this issue?

d'oh. I used the wrong bundle org.eclipse.jdt.apt.core_3.3.500.v20110420-1015.jar

should be the fragment org.eclipse.jdt.compiler.apt instead. 

now it works :)
Comment 13 Jan Sievers CLA 2011-12-06 12:34:56 EST
Created attachment 208008 [details]
patch with copyright headers added

added copyright headers to patch and opened CQ 5867 for it
Comment 14 Missing name CLA 2011-12-14 03:22:16 EST
1.  Did you author 100% of the content you are contributing
Yes
2.  Do you have the rights to donate the content to Eclipse
Yes
3.  Are you contributing the content under the EPL
Yes

You will receive soon an e-mail validating the donation from BSB.
Comment 15 Jan Sievers CLA 2011-12-19 05:40:31 EST
created CQ 5898, 5899 for plexus-compiler-api 1.8.1 and plexus-compiler-manager 1.8.1
Comment 16 Benjamin Jung CLA 2011-12-19 10:53:16 EST
Hi Jan, hi Thomas!

When is the patched version expected to be released?
We're in desperate need of getting APT/Tycho/Maven up
and running. This bug is a real showstopper for us at
the moment. 

The last possible resort would be calling the eclipse
batch compiler using an ant task from maven.

We didn't expected the combination APT/Maven/Eclipse
to be such a pain :-( There are several serious open issues for the
apt compiler in in javac (at least for Java 1.6),
therefore we have to go the ecj way for automated builds,
too.

This patch be would really great :-)

Kind regards
Benjamin
Comment 17 Jan Sievers CLA 2011-12-19 11:48:00 EST
(In reply to comment #16)
> When is the patched version expected to be released?

I will try to get this into 0.14.0.

However this depends on the pending IP review of the used libraries plexus-compiler-api, plexus-compiler-manager 1.8.1 and I don't have influence on the priorities of the eclipse IP team.
Comment 18 Jan Sievers CLA 2012-01-30 08:14:55 EST
Adding Wayne on CC.
CQs 5898, 5899 are waiting for PMC approval.

Anything we still need to do about these CQs?
Comment 19 Benjamin Jung CLA 2012-02-08 03:54:36 EST
Hi,

if I guess right, according to the bug described
here https://bugs.eclipse.org/bugs/show_bug.cgi?id=360628
there won't be any nightly builds available for Tycho in 
the near future? 

In the version to which this bug here (360427) is left/set to
unspecified.

Does this mean that this patch won't be included in 0.14.0?
In this case, this would be a pitty, especially because
the patch looks very promising :-( 

Kind regards
Benjamin
Comment 20 Jan Sievers CLA 2012-02-08 04:24:51 EST
(In reply to comment #19)
> Hi,
> 
> if I guess right, according to the bug described
> here https://bugs.eclipse.org/bugs/show_bug.cgi?id=360628
> there won't be any nightly builds available for Tycho in 
> the near future? 

sure we have SNAPSHOT builds. They are available from
https://oss.sonatype.org/content/groups/public/

This patch did not make it into 0.14.0 simply because IP review for the dependent new libraries used by the patch (CQs 5898, 5899) is still pending.
Other than that the patch is fine.
I can't check in source code without IP review.
Comment 21 Jan Sievers CLA 2012-02-24 03:39:06 EST
CQs approved
Comment 22 Jan Sievers CLA 2012-03-29 10:04:11 EDT
*** Bug 375592 has been marked as a duplicate of this bug. ***
Comment 23 Jan Sievers CLA 2012-04-13 10:05:04 EDT
https://git.eclipse.org/r/#/c/5579/