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

Bug 144395

Summary: Eclipse ANT inconsistent with Apache ANT.
Product: [Eclipse Project] Platform Reporter: Nils Hammar <nils.hammar>
Component: AntAssignee: Darin Swanson <Darin_Swanson>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: francois, philippe_mulet, pombredanne
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Two projects exposing the bug.
none
More sample build files showing the problem none

Description Nils Hammar CLA 2006-05-30 05:05:44 EDT
When doing a build with the built-in ANT in Eclipse and one bild.xml file calling another in a second project there is an inconsistency between how Apache ANT behaves and Eclipse ANT behaves.

Actual behavior during build in Eclipse:
----

Buildfile: C:\Work\Tests\P1\build.xml

init:

build:
        [echo] P1:Step 1

init:

build:
        [echo] P2:Step 1
       [javac] Compiling 1 source file to C:\Work\Tests\P1\bin
       [javac] C:\Work\Tests\P1\src\C1.java:9: generics are not supported in -source 1.3
       [javac] (try -source 1.5 to enable generics)
       [javac] 		Vector<String> v1=new Vector<String>();
       [javac]                       ^
       [javac] 1 error

BUILD FAILED
C:\Work\Tests\P1\build.xml:21: The following error occurred while executing this line:
C:\Work\Tests\P2\build.xml:19: Compile failed; see the compiler error output for details.

Total time: 3 seconds
----


Expected behavior as in Apache ANT:
----
C:\Work\Tests\P1>ant
Buildfile: build.xml

init:
    [mkdir] Created dir: C:\Work\Tests\P1\bin

build:
     [echo] P1:Step 1

init:
    [mkdir] Created dir: C:\Work\Tests\P2\bin

build:
     [echo] P2:Step 1
    [javac] Compiling 1 source file to C:\Work\Tests\P2\bin
     [echo] P2:Step 2
     [echo] P1:Step 2
    [javac] Compiling 1 source file to C:\Work\Tests\P1\bin
     [echo] P1:Step 3

BUILD SUCCESSFUL
Total time: 2 seconds
----
Comment 1 Nils Hammar CLA 2006-05-30 05:07:46 EDT
Created attachment 42933 [details]
Two projects exposing the bug.

Provided archive contains two projects that exposes the problem using Eclipse ANT when building solutions with dependencies between projects.
Comment 2 Darin Swanson CLA 2006-05-30 10:48:04 EDT
The Eclipse Ant integration makes no changes to the Ant distribution. 
It is Ant 1.6.5.

Needs more investigation. Thank you for the test case.
Comment 3 Philippe Ombredanne CLA 2006-08-25 20:09:31 EDT
Created attachment 48803 [details]
More sample build files showing the problem

This problem is more SERIOUS than it seems, and might or not be dangerous.
I have logging my investigations here...
So the flow is that of discovery :-)

Running ant -version within Eclipse using a launch conf arg gives the same on both Ant: the Eclipse provided and the Ant proivided.
Apache Ant version 1.6.5 compiled on June 2 2005

Running a ant -projecthelp on the attached build files shows some symptoms of the problem. The desc and targets titles are all out of sync when using Eclipse ant.

With the sample projects running Ant from Ant 1.6.5 from Ant itself gives:
ant -f build.xml -projecthelp
Buildfile: build.xml
Main targets:
 build-all  Run brutally the build on all the components and all the assemblies...
 build-one  Runs a build for the component, assembly, or configuration with the ID passed as id
 clean      Clean all except the downloads cache
 reset      Makes a full clean reset, wiping all work folders including the downloads cache
Default target: main


When using the same files run with Eclipse (inside eclipse or using the antrunner:
Default target:
 main
Main targets:
 build-all  Clean all except the downloads cache
 build-one  Makes a full clean reset, wiping all work folders including the downloads cache
 clean      Run brutally the build on all the components and all the assemblies...
 reset      Runs a build for the component, assembly, or configuration with the ID passed as id
Subtargets:
 init



Which means that Eclipse Ant's is NOT the right one, or at least not the exact right one.
Note that doing a binary diff between the Ant plugin and the official ant distro gives the following differences (leaving aside all the non interesting license and doc files):
- the META-INF/MANIFEST.MF only in Eclipse
- /etc/ant-bootstrap.jar
- /lib/xercesImpl.jar
- /lib/xml-apis.jar
Since it is really the bootstrap jar code that does all that, the bug lies in your equivalent code. (And it is very possible that the missing Xerces could introduce other bias or bugs BTW)

The culprit seesm to be for me:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java

In org.eclipse.ant.internal.core.ant.InternalAntRunner.printTargets(Project):

		Collections.sort(subNames);
		Collections.sort(topNames);
		Collections.sort(topDescriptions);

... does the sorting independetly for each of the names and descriptions :-D

There may be other issues in that code, which seems to be OLD ant derived code.
The code in Ant Main class works differently.
Comment 4 Darin Swanson CLA 2006-08-25 21:28:14 EDT
Thanks Philippe.

Believe me all the executable code is Ant 1.6.5 EXCEPT that we have our own implementation of the Ant entry point as the Ant Main class is not or at least was not all that IDE friendly.

I could talk for days on Xerces. We dropped it as Eclipse used to ship it. Now the JRE libraries are shipping their own version of XML goop (Crimson, Xerces depending on the distro). Not likely to bring it back by default but you can of course add it in yourself or point to an external Ant install that includes it.
Comment 5 Philippe Ombredanne CLA 2006-08-26 03:46:36 EDT
Hi Darin!
(In reply to comment #4)
> Believe me all the executable code is Ant 1.6.5 
I believe you... I made a binary diff :-)

> I could talk for days on Xerces. We dropped it as Eclipse used to ship it. Now
> the JRE libraries are shipping their own version of XML goop (Crimson, Xerces
> depending on the distro). Not likely to bring it back by default but you 
> can of course add it in yourself or point to an external Ant install 
> that includes it.
That I am less concerned with.

Comment 6 Nils Hammar CLA 2006-12-06 13:01:26 EST
Any progress on this bug???
Comment 7 Darin Swanson CLA 2006-12-06 13:12:22 EST
No progress. Still planned to be investigated / addressed for 3.3
Comment 8 Darin Swanson CLA 2006-12-20 00:12:34 EST
The -projectHelp bug will be dealt with in via bug 163534.
Comment 9 Darin Swanson CLA 2007-02-19 19:16:52 EST
Tag for investigation in 3.3 M6
Comment 10 Darin Swanson CLA 2007-03-16 20:05:47 EDT
I can reproduce the problem.
Comment 11 Darin Swanson CLA 2007-04-23 15:31:15 EDT
The basedir is being inherited when the build is run as an external tool builder so the src directory for P2 is incorrect.

The workaround is to remove the specification of the Base Directory for the P1 builder:
Right click on the Project>Properties>Builders
Edit the builder
On the Main tab, remove the Base Directory specification
Comment 12 Darin Swanson CLA 2007-04-23 15:44:09 EDT
Looking at the Apache Ant implementation we are consistent.

If you specify -Dbasedir=C:\P1 for the Apache Ant build you will get the same behavior as what we are seeing within Eclipse when you explicitly set the basedir for the builder.

With inheritAll set to false, user specified properties are still set in the new project per the Ant task implementation of initializeProject
Comment 13 Nils Hammar CLA 2007-04-24 02:06:52 EDT
In that case - the default behavior in the ANT builder of Eclipse should be to work as if built externally.
Comment 14 Darin Swanson CLA 2007-04-24 10:32:35 EDT
I agree..and it is, and it does.

Testing on I20070418-1012, a newly Ant builder does not have the basedir set as a property (set from the launch configuration) and works exactly the same as an external build.

Please try it.