Bug 188105 - org.eclipse.jdt.apt.pluggable.core imported as source does not compile
Summary: org.eclipse.jdt.apt.pluggable.core imported as source does not compile
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 RC3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-21 11:14 EDT by Markus Keller CLA
Modified: 2007-05-30 14:02 EDT (History)
6 users (show)

See Also:
jerome_lanneluc: review+
frederic_fusier: review+
tjwatson: review+


Attachments
Proposed fix (2.12 KB, patch)
2007-05-26 21:16 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2007-05-21 11:14:02 EDT
3.3 RC1

- File > Import > Plugins and Fragments
- Import As > Projects with source folders
- Import org.eclipse.jdt.apt.pluggable.core
=> 34 compile errors, e.g.
"The import org.eclipse.jdt.internal.compiler.apt cannot be resolved" in org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeAnnotationProcessorManager.java

The problem is probably that org.eclipse.jdt.compiler.apt is not a proper plug-in dependency but is just added on the classpath as a Java project.
Comment 1 Walter Harley CLA 2007-05-22 02:38:05 EDT
Unfortunately org.eclipse.jdt.compiler.apt is a fragment rather than a plug-in, so PDE will not let me add it as a plug-in dependency.

I will try to find a workaround.  Any suggestions?
Comment 2 Markus Keller CLA 2007-05-22 04:50:06 EDT
CCing our PDE wizard. Wassim, do you know of a better way to add the packages from org.eclipse.jdt.apt.pluggable.core's Import-Package: manifest header to the classpath?
Comment 3 Wassim Melhem CLA 2007-05-22 22:34:00 EDT
The idea here is that since you cannot rely on a fragment being there at runtime (ie. you cannot explicitly make a dependency on it in the manifest), a downstream client or another fragment should not structure their code to get themselves into that situation.

More importantly, the Eclipse Supreme Court ruled (bug 45767 comment 31) that the tooling should not be optimized to promote such usage.

Plus, if fragment A and fragment B are associated with the same host X, then if you want fragment B to go on fragment A's host then it's only fair for fragment A to go on fragment B's path.  Why stop there?  technically, both fragments A and B should be on plug-in X's classpath.
And you end up in circular classpath hell.

That is why PDE promotes the right lifestyle:  a fragment gets its host on its classpath.  A host does not get its fragments on its classpath.  Fragments do not get each other on their classpath.

Markus seemed to have found a loophole with his Import-Package suggestion.  It may actually work to fool the tooling.
Comment 4 Walter Harley CLA 2007-05-23 00:34:32 EDT
Yes, this is a kind of bizarre case, that pushes the limits of the architecture.  The jdt.compiler.apt plug-in is a (Java 1.6 dependent) fragment of jdt.core, because jdt.core needs to load its classes reflectively at runtime, because it can't rely on the extension point mechanism, because it needs to be available in the batch compiler (ecj.jar).  But apt.pluggable.core is a regular old plug-in, that extends the base classes defined in jdt.compiler.apt.  Like jdt.compiler.apt, apt.pluggable.core requires Java 1.6, so at runtime there's no risk of the fragment not being there.  In a sense, apt.pluggable.core is like a fragment of jdt.compiler.apt, but its required EE is the Eclipse platform itself.

So, it's ugly.  I wonder if maybe the best solution is just to document (in a readme in the plug-in source) that apt.pluggable.core won't build unless the source for jdt.compiler.apt is also in the workspace?  Yuck.
Comment 5 Thomas Watson CLA 2007-05-23 15:47:17 EDT
Seems like org.eclipse.jdt.core is similar to SWT where additional fragments may supply more API.  If that is the case then org.eclipse.jdt.core should add the following header, right Wassim?  That fixes the issue in my workspace.

Eclipse-ExtensibleAPI: true

Note that this header *only* has meaning for PDE-UI.  At runtime fragments in integrated with the host and have access to eachother and down stream clients always have access to their content.
Comment 6 Wassim Melhem CLA 2007-05-23 15:52:25 EDT
oh I missed a vital piece of info in this bug report.

jdt.apt.pluggable.core is a plug-in, not a fragment of jdt.core

jdt.compiler.apt is a fragment of jdt.core.

In which case, then it's simple.

Just add Eclipse-ExtensibleAPI: true to the manifest.mf of jdt.core as Tom suggests and you're all set.
Comment 7 Walter Harley CLA 2007-05-23 18:01:27 EDT
Thanks, Tom and Wassim.  I'll move this to jdt.core.
Comment 8 Olivier Thomann CLA 2007-05-25 13:11:10 EDT
I'll provide a patch for it.
Comment 9 Olivier Thomann CLA 2007-05-25 13:25:21 EDT
It doesn't seem to be that simple.
When I add the line Eclipse-ExtensibleAPI: true inside the jdt/core manifest, then I get compile errors for duplicate entry in the classpath for the two projects:
org.eclipse.jdt.apt.pluggable.core
org.eclipse.jdt.compiler.tool.tests

I get the build path errors:

Severity and Description	Path	Resource	Location	Creation Time	Id
Build path contains duplicate entry: 'org.eclipse.jdt.compiler.apt' for project 'org.eclipse.jdt.apt.pluggable.core'		org.eclipse.jdt.apt.pluggable.core	Build path	1180113302769	2131753
Build path contains duplicate entry: 'org.eclipse.jdt.compiler.tool' for project 'org.eclipse.jdt.compiler.tool.tests'		org.eclipse.jdt.compiler.tool.tests	Build path	1180113302699	2131752

Any clue?
Comment 10 Olivier Thomann CLA 2007-05-25 14:57:03 EDT
If I have these 4 projects loaded from CVS, everything compiles fine.
org.eclipse.jdt.apt.core
org.eclipse.jdt.apt.pluggable.core
org.eclipse.jdt.compiler.apt
org.eclipse.jdt.core

I use Import-Package and Export-Package mecanism in order to make some packages defined in org.eclipse.jdt.compiler.apt visible from org.eclipse.jdt.apt.pluggable.core.

Could an OSGI/PDE expert tell us what is wrong in the way we defined our plugins/fragments?

These plugins/fragments are part of the eclipse builds for weeks now and they build fine.

I don't have anything against adding the Extensible-API to true if I can get rid of the build path errors in my configuration. I don't want to break Eclipse build to solve this issue.

For now I remove the target milestone as the fix doesn't appear to be that simple.
Comment 11 Thomas Watson CLA 2007-05-26 08:18:22 EDT
This is because org.eclipse.jdt.apt.pluggable.core has a strong reference to the org.eclipse.jdt.compiler.apt project in its .classpath.

<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.jdt.compiler.apt"/>

This conflicts with the PDE classpath container when it configures the classpath to have org.eclipse.jdt.compiler.apt on the org.eclipse.jdt.apt.pluggable.core project classpath.  If possible the PDE classpath container should be the only thing controlling your project's classpath.
Comment 12 Wassim Melhem CLA 2007-05-26 17:10:15 EDT
Olivier, this needs to be addressed for 3.3.  We need to be able to compile without errors of out the box when people import plug-ins with source.

1. Add:
Extensible-API: true
to the jdt.core manifest.

2. Remove any offending project classpath entry from the .classpath file as Tom suggests.  

That's it.
Comment 13 Olivier Thomann CLA 2007-05-26 21:16:41 EDT
Created attachment 68864 [details]
Proposed fix
Comment 14 Olivier Thomann CLA 2007-05-26 21:18:46 EDT
I'll test if the plugins with this patch can be successfully imported when using 
"Import As > Projects with source folders".
Comment 15 Olivier Thomann CLA 2007-05-27 16:28:11 EDT
The patch seems to work either when loaded from CVS or import with source folders.
Comment 16 Olivier Thomann CLA 2007-05-28 09:55:29 EDT
Jérôme, Frédéric and Tom, please review.
Comment 17 Jerome Lanneluc CLA 2007-05-28 13:15:26 EDT
+1 for 3.3 RC3. 

Just make sure you coordinate with JDT/APT when you release this patch so that they contribute at the same time as JDT/Core is contributing.
Comment 18 Olivier Thomann CLA 2007-05-28 19:32:39 EDT
Of course :-). I'll make the contribution of JDT/APT if needed.
Comment 19 Frederic Fusier CLA 2007-05-29 03:25:49 EDT
+1 for 3.3 RC3
Comment 20 Thomas Watson CLA 2007-05-29 08:45:41 EDT
+1 for 3.3 RC3.
Comment 21 Olivier Thomann CLA 2007-05-29 09:49:07 EDT
Released for 3.3RC3
Comment 22 Philipe Mulet CLA 2007-05-29 11:03:56 EDT
+1 for rc3
Comment 23 Walter Harley CLA 2007-05-29 12:19:55 EDT
Olivier and I are in contact regarding APT; he is releasing the APT changes at the same time as JDT, to ensure there are no glitches.
Comment 24 Olivier Thomann CLA 2007-05-30 14:02:59 EDT
Verified for 3.3RC3 using I20070530-0010.