Bug 48829 - Javac task only accepts *.java files
Summary: Javac task only accepts *.java files
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.8.0
Hardware: PC Mac OS X 10.4
: P2 enhancement with 3 votes (vote)
Target Milestone: 1.8.2
Assignee: Ant Notifications List
Depends on:
Reported: 2010-03-01 04:49 UTC by Andrew Eisenberg
Modified: 2010-11-29 11:35 UTC (History)
0 users

First attempt at a patch (6.11 KB, patch)
2010-08-01 18:55 UTC, Andrew Eisenberg
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Eisenberg 2010-03-01 04:49:51 UTC
The javac task explicitly filters from the compiler all files that do not end in *.java.

This is a problem for CompilerAdapters classes that can compile more than just Java, for example compiler adapters for Groovy or AspectJ.  As an example of where this is important, Eclipse's pde build will soon support custom compiler adapters to be specified and we have just written one for AspectJ (and will soon do one for Groovy):


I propose that the Javac task accept a new attribute such as sourceFileExtensions that can take a comma separated list of source file extensions (eg- "*.java,*.aj,*.groovy").  And these are the source file extensions accepted by the Javac task.

An example is something like this:

<javac destdir="dest" compiler="org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter" sourceFileExtensions="*.java,*.aj">

And if the sourceFileExtensions attribute is not used, then the default is *.java (ie- the current behavior).

I believe that this is a fairly small fix to the javac task and if you think this is a reasonable proposal, I can probably submit a patch.

Comment 1 Antoine Levy-Lambert 2010-03-01 14:05:35 UTC
Hello Andrew,

the Eclipse/AspectJ project supplies ant tasks too.

see http://www.eclipse.org/aspectj/doc/released/devguide/antTasks.html

The AspectJ compiler task compiles both java and aspects.

Do you think that there is scope to do things differently/better in Ant ?

Comment 2 Andrew Eisenberg 2010-03-01 16:57:56 UTC
There are several reasons why the iajc task is not sufficient.

1. Eclipse PDE builds do not allow the use of the iajc task, only the javac task.  This kind of change would allow us to compile aspectj code using the javac task.  Moreover, this change would allow any language that compiles to java byte code to be compiled using PDE.

2. The ajc ant task is largely a copy of the javac ant task and so providing this functionality would make this copied code largely irrelevant.

3. There is the possibility to handle extensible Java compilers.  For example, groovy-eclipse ships with an extended JDT compiler that also handles groovy code.  The fix proposed in this bug would allow javac to handle this compiler as a compiler adapter without the need for a custom ant task.

4. This change would allow new compilers for JVM languages to take advantage of the full power of the javac task when used with ant, while only implementing a minimal amount of code.

5. More generally, it seems arbitrary to me that javac would only accept .java files when there is a proliferation of compilers that produce java byte code from non-Java code.
Comment 3 Steve Loughran 2010-03-02 13:20:57 UTC
Think its more something the compiler adapter should provide; a list of filetypes it likes
Comment 4 Andrew Eisenberg 2010-03-02 18:23:15 UTC
(In reply to comment #3)
> Think its more something the compiler adapter should provide; a list of
> filetypes it likes

That sounds like a reasonable way to go, but that would imply changing the CompilerAdapter interface to require an extra method, something like:

    String[] getSupportedFileExtensions();

The problem here is that adding this would break backwards compatibility for all those implementors that do not implement DefaultCompilerAdapter.  Suggestions around this problem are welcome.
Comment 5 Andrew Eisenberg 2010-08-01 18:55:15 UTC
Created attachment 25824 [details]
First attempt at a patch

Here is a first attempt at a patch.  As described above, I created a CompilerAdapterExtension interface and made the DefaultCompilerAdapter implement it.  

I have not tested this yet and the patch is still a little rough (eg- no tests and little documentation).  I am only submitting this right now to see if this is a kind of solution that you would accept.
Comment 6 Andrew Eisenberg 2010-08-07 18:24:54 UTC
Just wondering if there is anyone around who can comment on this patch as to whether or not it is appropriate for the next release.
Comment 7 Stefan Bodewig 2010-11-29 11:29:51 UTC
I've committed your code with some formatting changes as svn revisions 1040170 ,
svn revision 1040171 and svn revision 1040173

I've also removed your @author tag from CompilerAdapterExtension since we have a
no @author tag policy inside Ant.  Let me know if this is a problem for you.

Thank you for your persistence and the nagging.
Comment 8 Stefan Bodewig 2010-11-29 11:30:55 UTC
and svn revision 1040174 after I finally saved all my Emacs buffers.
Comment 9 Andrew Eisenberg 2010-11-29 11:35:18 UTC
Much appreciated...thanks.