You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "M.A.Dunphy" <ma...@bigfoot.com> on 2001/03/13 16:38:59 UTC

Property scope

Hi guys,

Sorry to be bringing this subject up again, but I'm not getting the expected
behaviour. Firstly, I have read thr' previous discussions in the archive and
I think I understand how property set works, but I'm not getting what I
want!!. As an example, heres the test build file

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v3.5 NT (http://www.xmlspy.com) by Michael Dunphy
-->
<!DOCTYPE project SYSTEM "ant-project.dtd">
<project name="test" default="">
    <target name="test1">
        <antcall target="test2"/>
        <antcall target="test3"/>
    </target>
    <target name="test2">
        <property name="srd.fetch.complete" value="true"/>
        <echo message="the value is ${srd.fetch.complete}"/>
    </target>
    <target name="test3" if="srd.fetch.complete">
        <echo message="the value is ${srd.fetch.complete}"/>
    </target>
</project>

When I run it using: ant -verbose -buildfile test.xml test1

I get:

C:\TEMP>ant -verbose -buildfile test.xml test1
Ant version 1.3 compiled on March 2 2001

Buildfile: test.xml
Detected Java Version: 1.3
Detected OS: Windows 2000
parsing buildfile C:\TEMP\test.xml with URI = file:C:/TEMP/test.xml
resolving systemId: file:C:/TEMP/ant-project.dtd
Project base dir set to: C:\TEMP
Build sequence for target `test1' is [test1]
Complete build sequence is [test1, test3, test2]

test1:
Project base dir set to: C:\TEMP
parsing buildfile C:\TEMP\test.xml with URI = file:C:/TEMP/test.xml
resolving systemId: file:C:/TEMP/ant-project.dtd
Project base dir set to: C:\TEMP
Build sequence for target `test2' is [test2]
Complete build sequence is [test2, test3, test1]

test2:
     [echo] the value is true
Project base dir set to: C:\TEMP
parsing buildfile C:\TEMP\test.xml with URI = file:C:/TEMP/test.xml
resolving systemId: file:C:/TEMP/ant-project.dtd
Project base dir set to: C:\TEMP
Build sequence for target `test3' is [test3]
Complete build sequence is [test3, test2, test1]

test3:
Skipped because property 'srd.fetch.complete' not set.

BUILD SUCCESSFUL

Total time: 1 second
C:\TEMP>


My first observation is why does it say "Complete build sequence is [test1,
test3, test2]"?

any insight would be much appreciated..

Thanks

Mick

PS: in the generated DTD file, a property is defined as 

<!ATTLIST property
    id ID #IMPLIED
    refid IDREF #IMPLIED
    name CDATA #IMPLIED
    classpath CDATA #IMPLIED
    file CDATA #IMPLIED
    userproperty %boolean; #IMPLIED
    resource CDATA #IMPLIED
    environment CDATA #IMPLIED
    classpathref IDREF #IMPLIED
    taskname CDATA #IMPLIED
    value CDATA #IMPLIED
    location CDATA #IMPLIED
    description CDATA #IMPLIED
>

but the docs do not specify these attributes, so are the docs
incorrect/incomplete?


Re: Property scope

Posted by Diane Holt <ho...@yahoo.com>.
You have the <property> task inside a target, and that target is only
executed within an <antcall> task, so the property is only set for the
duration of that <antcall> execution, which is why the "test3" target sees
the property as not set.

Not sure about why the build sequence has the "test3" target before the
"test2" one -- but then, I've never really understood the whole "Complete
build sequence" thing or why it's included (ie., what it's usefullness
is).

Diane

--- "M.A.Dunphy" <ma...@bigfoot.com> wrote:
> Hi guys,
> 
> Sorry to be bringing this subject up again, but I'm not getting the
> expected
> behaviour. Firstly, I have read thr' previous discussions in the archive
> and
> I think I understand how property set works, but I'm not getting what I
> want!!. As an example, heres the test build file
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- edited with XML Spy v3.5 NT (http://www.xmlspy.com) by Michael
> Dunphy
> -->
> <!DOCTYPE project SYSTEM "ant-project.dtd">
> <project name="test" default="">
>     <target name="test1">
>         <antcall target="test2"/>
>         <antcall target="test3"/>
>     </target>
>     <target name="test2">
>         <property name="srd.fetch.complete" value="true"/>
>         <echo message="the value is ${srd.fetch.complete}"/>
>     </target>
>     <target name="test3" if="srd.fetch.complete">
>         <echo message="the value is ${srd.fetch.complete}"/>
>     </target>
> </project>
> 
> When I run it using: ant -verbose -buildfile test.xml test1
> 
> I get:
> 
> C:\TEMP>ant -verbose -buildfile test.xml test1
> Ant version 1.3 compiled on March 2 2001
> 
> Buildfile: test.xml
> Detected Java Version: 1.3
> Detected OS: Windows 2000
> parsing buildfile C:\TEMP\test.xml with URI = file:C:/TEMP/test.xml
> resolving systemId: file:C:/TEMP/ant-project.dtd
> Project base dir set to: C:\TEMP
> Build sequence for target `test1' is [test1]
> Complete build sequence is [test1, test3, test2]
> 
> test1:
> Project base dir set to: C:\TEMP
> parsing buildfile C:\TEMP\test.xml with URI = file:C:/TEMP/test.xml
> resolving systemId: file:C:/TEMP/ant-project.dtd
> Project base dir set to: C:\TEMP
> Build sequence for target `test2' is [test2]
> Complete build sequence is [test2, test3, test1]
> 
> test2:
>      [echo] the value is true
> Project base dir set to: C:\TEMP
> parsing buildfile C:\TEMP\test.xml with URI = file:C:/TEMP/test.xml
> resolving systemId: file:C:/TEMP/ant-project.dtd
> Project base dir set to: C:\TEMP
> Build sequence for target `test3' is [test3]
> Complete build sequence is [test3, test2, test1]
> 
> test3:
> Skipped because property 'srd.fetch.complete' not set.
> 
> BUILD SUCCESSFUL
> 
> Total time: 1 second
> C:\TEMP>
> 
> 
> My first observation is why does it say "Complete build sequence is
> [test1,
> test3, test2]"?
> 
> any insight would be much appreciated..
> 
> Thanks
> 
> Mick
> 
> PS: in the generated DTD file, a property is defined as 
> 
> <!ATTLIST property
>     id ID #IMPLIED
>     refid IDREF #IMPLIED
>     name CDATA #IMPLIED
>     classpath CDATA #IMPLIED
>     file CDATA #IMPLIED
>     userproperty %boolean; #IMPLIED
>     resource CDATA #IMPLIED
>     environment CDATA #IMPLIED
>     classpathref IDREF #IMPLIED
>     taskname CDATA #IMPLIED
>     value CDATA #IMPLIED
>     location CDATA #IMPLIED
>     description CDATA #IMPLIED
> >
> 
> but the docs do not specify these attributes, so are the docs
> incorrect/incomplete?
> 


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/