Bug 42263

Summary: Built-in properties ${ant.version}, ${ant.core.lib} unset after <*ant* inheritall=false>
Product: Ant Reporter: Stephan Classen <stephan.classen>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: RESOLVED FIXED    
Severity: regression CC: caster, dave, jglick, rbaker
Priority: P2    
Version: 1.7.0   
Target Milestone: 1.7.1   
Hardware: PC   
OS: Linux   

Description Stephan Classen 2007-04-26 07:01:03 UTC
when calling subant without inheritall="true" ant.version is not set.

example

top level build file:
<target name="test1">
   <echo message="${ant.project.name}" />
   <echo message="${ant.version}" />
   <subant target="test" buildpathref="subpath" />
</target>

and in the build file specified by the path "subpath":
<target name="test1">
   <echo message="${ant.project.name}" />
   <echo message="${ant.version}" />
</target>



The output of "ant test" is:

test project
Apache Ant version 1.7.0 compiled on December 13 2006
test project subcomponent
${ant.version}
Comment 1 Steve Loughran 2007-05-14 06:03:11 UTC
I am seeing this too. 


===================================================================
= SSH 2.4.1, (C) Copyright 1998-2007 Hewlett-Packard Development Company, LP
(${ant.version})
Comment 2 Steve Loughran 2007-05-14 07:24:46 UTC
as you can see, we dont get ant.version passed down in subant, more importanly
we dont get any other ant built in props handed down.
]
What#s happening is that the Ant init code creates a new project and calls 
setJavaVersionProperty(), whereas it maybe ought to be doing something like
initProperties():


    public void initProperties() throws BuildException {
        setJavaVersionProperty();
        setSystemProperties();
        setPropertyInternal(MagicNames.ANT_VERSION, Main.getAntVersion());
        setAntLib();
    }


As it is, there's probably a fair bit of the initial state of a subant project
that isnt being set up right.

What to do?
(a) stay broken and hope nobody notices
(b) fix and hope nothing breaks.

if (b), what do we pass down? Everything from initProperties()?
Comment 3 Matt Benson 2007-05-14 07:37:22 UTC
(In reply to comment #2)
> as you can see, we dont get ant.version passed down in subant, more importanly
> we dont get any other ant built in props handed down.
> ]
> What#s happening is that the Ant init code creates a new project and calls 
> setJavaVersionProperty(), whereas it maybe ought to be doing something like
> initProperties():
> 
> 
>     public void initProperties() throws BuildException {
>         setJavaVersionProperty();
>         setSystemProperties();
>         setPropertyInternal(MagicNames.ANT_VERSION, Main.getAntVersion());
>         setAntLib();
>     }
> 
> 
> As it is, there's probably a fair bit of the initial state of a subant project
> that isnt being set up right.
> 
> What to do?
> (a) stay broken and hope nobody notices
> (b) fix and hope nothing breaks.
> 
> if (b), what do we pass down? Everything from initProperties()?

Yep, probably so.  Looks like the right thing to do is replace newProject.setJavaVersionProperty() with 
newProject.init() in Ant.init() IMO.
Comment 4 Peter Reilly 2007-05-14 08:30:44 UTC
It does look like a bug all right.
The code in Ant.java calls  newProject.setSystemProperties();
but does not call setJavaVersion() or 
 setPropertyInternal(MagicNames.ANT_VERSION, Main.getAntVersion())

The one thing I would be concerened about from Project#initProperties()
is setAntLib() which from some reason calls Locator.getClassSource()
which does some File IO and antlib.getAbsolutePath() which
does more FileIO.

Maybe the solution would be to make ant.version and the java version
properties to be user properties, these always get copied
to sub-projects.
Comment 5 Vlastimil Babka (Caster) 2007-05-16 13:07:07 UTC
Just note that at least ant.version worked fine in 1.6.5, so it's probably 1.7.0
regression.
Comment 6 Peter Reilly 2007-05-17 00:58:53 UTC
Yep,
you are correct, the problem does not happen with ant 1.6.5.
Comment 7 Peter Reilly 2007-05-17 01:28:58 UTC
ant.version was a user property
this change seems to have made it a normal version
http://svn.apache.org/viewvc?view=rev&revision=388848
Comment 8 Steve Loughran 2007-05-17 03:15:14 UTC
that's good, I can change it without fear of lots of things breaking.

Which properties were passed down in ant1.6.5?
Comment 9 Peter Reilly 2007-05-17 04:54:38 UTC
Doing a quick grep in the ant 1.6.5 codebase I see the following
uses of project.setUserProperty.

Main.java:    "ant.version", "ant.file"

ProjectHelper2.java "ant.file"

Project.java: "ant.project.name"

VAJBuildInfo.java: "ant.file"

Ant.java: "ant.file"
Comment 10 Steve Loughran 2007-05-17 09:17:32 UTC
Fixed in SVN_HEAD...with a test to catch any regressions.

I'm calling Oroject.initProperties() to do the initialisation, not Project.init(). 
Comment 11 Matt Benson 2007-05-17 09:28:39 UTC
Yeah, looks like initProperties() is better than init() for ComponentHelper reasons I'm sure you already 
deduced.  :)
Comment 12 Steve Loughran 2007-06-21 08:25:38 UTC
*** Bug 42715 has been marked as a duplicate of this bug. ***
Comment 13 Peter Reilly 2007-06-21 13:09:55 UTC
*** Bug 42715 has been marked as a duplicate of this bug. ***
Comment 14 Peter Reilly 2007-06-21 13:11:08 UTC
Updating title as this bug affects all <ant>, <subant> and <antcall>
Comment 15 Peter Reilly 2007-07-25 03:41:03 UTC
*** Bug 42970 has been marked as a duplicate of this bug. ***
Comment 16 Jesse Glick 2008-03-31 10:34:10 UTC
Also affected ${ant.core.lib} in Ant 1.7.0. Manually confirmed fixed in 1.7.1 and dev. Added test and updated WHATSNEW in trunk (#643076), just WHATSNEW in branch (#643079).