ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: Bug 3304
Date Wed, 24 Sep 2003 07:19:11 GMT
Workaround:

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="test" basedir="." default="main">

    <target name="main">
        <script language="javascript"> <![CDATA[
            name = self.getOwningTarget().getName();
            project.setProperty("target.name",name);
        ]]></script>
        <echo>target.name=${target.name}</echo>
        <antcall target="script"/>
    </target>

    <target name="script">
        <script language="javascript"> <![CDATA[
            name = self.getOwningTarget().getName();
            project.setProperty("target.name",name);
        ]]></script>
        <echo>target.name=${target.name}</echo>
    </target>

</project>


But it´s not the fine way to overwrite the property ...

I think it is no problem to implement. But then we will brake to golden
rule "properties are immutable" (see example).
If you have to specify the property in which the target name should be
stored,
you can code that in a normal <property/>. (... I got an idea ...)
If you want to have a "global" property (like ant.project.name) the value
has
to overwritten in each target (otherwise it wouldn´t be really useful).


Back to my idea:
A task which gets the current target name and tries to store it into a 
property. Maybe it should fail if that property is already set (to a
different
value).

<target name="helloWorld">
    <getTargetName property="tname"/>
    <echo>${tname}</echo>
</target>

would print "helloWorld"

<getTargetName property="tname" fail="never|differ|isset"/>
control the behaviour if the property tname is already set
- never:   don´t throw a BuildException (log in verbose); don´t set the
property
           --> "properties are immutable"
- differ:  throw a BE if the value differs from the current target name;
           don´t set the property (useless, has the "right" value :-)
- isset:   throw a BE if the property is set; set the property


Would that help?



Jan


> -----Original Message-----
> From: Sean Rohead [mailto:sean.rohead@nextpage.com]
> Sent: Wednesday, September 24, 2003 1:42 AM
> To: dev@ant.apache.org
> Subject: Bug 3304
> 
> 
> I wanted to lobby for bug 3304 as an enhancement.  I have an 
> ant script
> which calls subordinate ant scripts using the <ant> task.  I 
> would like
> to pass the build target to the subordinate scripts so they 
> can execute
> the same target as the parent (ie. 'ant compile' calls the compile
> target on the subordinate projects).  Without a means of accessing the
> target name, I would have to hardcode the target and therefore need to
> place <ant> tasks within every single target in the parent build file.
> Am I missing something?  Is there another way to accomplish 
> this without
> a standard ant.target.name property?
> 
>  
> 
> Thanks,
> 
>  
> 
> Sean Rohead
> 
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message