You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "R. Mark Volkmann" <ma...@home.com> on 2000/11/26 23:41:37 UTC

accessing Ant project name

Is it possible to reference the name of a project within a target?
For example, can I do something like this?

<project name="My Project">
  <target name="getProjectName">
    <echo message="${project.name}"/>
  </target>
</project>

I made up the property name "project.name". This doesn't work but it seems
there should be some way I can use the name of the project within a target.


RE: accessing Ant project name

Posted by Peter Donald <do...@apache.org>.
At 04:43  27/11/00 +1100, you wrote:
>Pete,
>
>I think all such ant-related properties should start with "ant."
>
>so in this case ant.project.name rather than project.name
>
>Probably basedir should become ant.project.basedir but that would break a
>lot.

done

Cheers,

Pete

*------------------------------------------------------*
| "Computers are useless. They can only give you       |
|            answers." - Pablo Picasso                 |
*------------------------------------------------------*

RE: accessing Ant project name

Posted by Conor MacNeill <co...@ebinteractive.com.au>.
Pete,

I think all such ant-related properties should start with "ant."

so in this case ant.project.name rather than project.name

Probably basedir should become ant.project.basedir but that would break a
lot.

Conor

--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: Peter Donald [mailto:donaldp@apache.org]
> Sent: Monday, 27 November 2000 14:34
> To: ant-dev@jakarta.apache.org
> Subject: Re: accessing Ant project name
>
>
> Hi,
>
> At 08:21  26/11/00 -0600, you wrote:
> >Not right now.  But we can easily add such a property with the following
> >patch, which makes the ${project.name} property behave like the
> >${basedir} property:
> >
> >Index: Project.java
> >===================================================================
> >RCS file:
> >/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
> >retrieving revision 1.45
> >diff -c -r1.45 Project.java
> >*** Project.java	2000/11/25 02:38:34	1.45
> >--- Project.java	2000/11/27 00:55:32
> >***************
> >*** 286,291 ****
> >--- 286,292 ----
> >
> >      public void setName(String name) {
> >          this.name = name;
> >+         setProperty("project.name", name);
>
> I just changed this to setUserProperty so that the project name
> is not able
> to be overidden easily.
>
> Cheers,
>
> Pete
>
> *-----------------------------------------------------*
> | "Faced with the choice between changing one's mind, |
> | and proving that there is no need to do so - almost |
> | everyone gets busy on the proof."                   |
> |              - John Kenneth Galbraith               |
> *-----------------------------------------------------*
>
>


Re: accessing Ant project name

Posted by Peter Donald <do...@apache.org>.
Hi,

At 08:21  26/11/00 -0600, you wrote:
>Not right now.  But we can easily add such a property with the following
>patch, which makes the ${project.name} property behave like the
>${basedir} property:
>
>Index: Project.java
>===================================================================
>RCS file:
>/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
>retrieving revision 1.45
>diff -c -r1.45 Project.java
>*** Project.java	2000/11/25 02:38:34	1.45
>--- Project.java	2000/11/27 00:55:32
>***************
>*** 286,291 ****
>--- 286,292 ----
>  
>      public void setName(String name) {
>          this.name = name;
>+         setProperty("project.name", name);

I just changed this to setUserProperty so that the project name is not able
to be overidden easily.

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


Re: accessing Ant project name

Posted by Weiqi Gao <we...@networkusa.net>.
"R. Mark Volkmann" wrote:
> 
> Is it possible to reference the name of a project within a target?
> For example, can I do something like this?
> 
> <project name="My Project">
>   <target name="getProjectName">
>     <echo message="${project.name}"/>
>   </target>
> </project>
> 
> I made up the property name "project.name". This doesn't work but it seems
> there should be some way I can use the name of the project within a target.

Not right now.  But we can easily add such a property with the following
patch, which makes the ${project.name} property behave like the
${basedir} property:

Index: Project.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.45
diff -c -r1.45 Project.java
*** Project.java	2000/11/25 02:38:34	1.45
--- Project.java	2000/11/27 00:55:32
***************
*** 286,291 ****
--- 286,292 ----
  
      public void setName(String name) {
          this.name = name;
+         setProperty("project.name", name);
      }
  
      public String getName() {