Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313386 - Project Export to Ant Buildfiles for project with linked source folder produces multiple javac tasks
Summary: Project Export to Ant Buildfiles for project with linked source folder produc...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.8 M4   Edit
Assignee: Michael Rennie CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2010-05-18 12:13 EDT by Mike Heinrichs CLA
Modified: 2011-11-07 16:49 EST (History)
2 users (show)

See Also:


Attachments
Fixed source: SourceAnalyzer.java (3.34 KB, application/zip)
2011-10-13 14:11 EDT, Richard . CLA
no flags Details
patch (2.18 KB, application/octet-stream)
2011-10-17 12:50 EDT, Michael Rennie CLA
Michael_Rennie: iplog+
Details
Fixed sources: BuildFileCreator.java, DataTransferMessages.properties (13.32 KB, application/zip)
2011-11-01 06:11 EDT, Richard . CLA
no flags Details
updated patch (7.92 KB, patch)
2011-11-07 16:34 EST, Michael Rennie CLA
Michael_Rennie: iplog+
Michael_Rennie: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Heinrichs CLA 2010-05-18 12:13:49 EDT
Build Identifier: 20090920-1017

I have a Java project with one source folder, and another linked source folder.  There is a circular dependency between the two source folders (i.e., each source folder will not compile without the other).  This project builds in Eclipse.  When I export the project to Ant Buildfiles, the generated build.xml contains two javac tasks: one for each source folder.  Of course, the Ant build is unsuccessful:

    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="classes" source="${source}" target="${target}">
            <src path="${src-common.link}"/>
            <classpath refid="TestProject.classpath"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="classes" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="TestProject.classpath"/>
        </javac>
    </target>

If I manually combine the two javac tasks, the build succeeds:

    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="classes" source="${source}" target="${target}">
            <src path="${src-common.link}"/>
            <src path="src"/>
            <classpath refid="TestProject.classpath"/>
        </javac>
    </target>

The Ant Buildfile should reproduce the Eclipse build, which compiles the two source folders together, just like the combined javac task.  The exporter should only produce one javac task.

Reproducible: Always

Steps to Reproduce:
1. Create project with two source folders that depend on each other.
2. Export project to Ant Buildfiles
Comment 1 Richard . CLA 2011-10-13 14:11:32 EDT
Created attachment 205147 [details]
Fixed source: SourceAnalyzer.java

The buildfile is created without warning that there is a cycle.
My patch will now detect the cycle.

Mike, your suggested solution to generate one javac tag is not as simple as it looks:
Each source directory may be compiled to a different classes directory. Therefore I decided to generate a javac tag for each source directory. Of course, your case only has one classes directory, so merging to one javac task is possible. But to support cyclic code for separate javac tags (with different classes directories) it would require to add duplicate source entries. This will produce duplicate classes and even worse: The compile time increases significantly; at least when I did the test some years ago ;-)
And what if there are inclusion/exclusion patterns?

Therefore I decided to stay with the nice 1:1 mapping sourceDir <-> javac.
Comment 2 Michael Rennie CLA 2011-10-17 12:50:05 EDT
Created attachment 205349 [details]
patch
Comment 3 Michael Rennie CLA 2011-10-17 13:15:11 EDT
The patch does detect the cycle and warn the user [OK], but could we not do some simple inspections and create a javac task that would allow src folders with cyclic deps build? Especially if the src folders will share an output folder?
Comment 4 Richard . CLA 2011-11-01 06:11:50 EDT
Created attachment 206258 [details]
Fixed sources: BuildFileCreator.java, DataTransferMessages.properties

Michael, of course it is possible to optimize this sole case:
Two or more cyclic source directories with the same classes directory.

For different classes directories it would require Ant to compile portions of the sources twice. So I don't consider that. I hope you agree.

What about inclusion and exclusion filters?
Eclipse projects specify filters for each source directory, but Ant assumes that filters are global:

<javac destdir="bin">
    <src path="src"/>
    <src path="src2"/>
    <exclude name="**/Excluded*.java"/>
</javac>

The exclusion applies to 'src' _and_ 'src2'. So this might lead to an unexpected behavior.
IMHO filters are rarely used, but in case of bug reports, can we reject them, because this is an Ant restriction?  

Nevertheless here are the updated sources.

Note:
I haven't removed the check for a cycle, I simply changed the text to 'buildfile _might_ not compile'. This saved many lines of code.
Comment 5 Michael Rennie CLA 2011-11-07 16:34:39 EST
Created attachment 206552 [details]
updated patch

Path created from attachment #206258 [details]
Comment 6 Michael Rennie CLA 2011-11-07 16:49:08 EST
pushed patch to master, thanks Richard.