You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Raja Nagendra Kumar <Na...@tejasoft.com> on 2009/09/27 09:32:12 UTC

project.replaceProperties()

In a custom task, when using replaceProperties() method is replacing the all
the properties, including those does exist. For properties which does not
exist, it replace them with null. Would it be possible to control not to
touch upon those properties which does not exist.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
-- 
View this message in context: http://www.nabble.com/project.replaceProperties%28%29-tp25631397p25631397.html
Sent from the Ant - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: project.replaceProperties()

Posted by Raja Nagendra Kumar <Na...@tejasoft.com>.
Nice to know that good changes happening in the next release of ant.

Thank you Stefan.

Regards,
Nagendra

-- 
View this message in context: http://www.nabble.com/project.replaceProperties%28%29-tp25631397p25677980.html
Sent from the Ant - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: project.replaceProperties()

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-09-30, Raja Nagendra Kumar <Na...@tejasoft.com> wrote:

> Stefan, you are correct.. We did make few modifcations to ant source and this
> has side effect else where..

> We are trying to support multiple property references resolutions with in a
> string some thing like this..

> Project p = getProject();
> p.setProperty("nagrama", "nagiest");
> p.setProperty("n", "nag");
> p.setProperty("m", "rama");
> p.replaceProperties("${${n}${m}}")//${${n}rama}

You will want Ant's trunk and a PropertyExpander like

http://svn.apache.org/viewvc/ant/sandbox/antlibs/props/trunk/src/main/org/apache/ant/props/NestedPropertyExpander.java

8-)

You can't have nested properties with Ant 1.7.1, but since you are
modifying Ant's source code anyway, you might as well switch to Ant's
trunk now - a release shouldn't be too far into the future.

> Pl. observe that there is misbehavior of replace properties.. i.e 2nd one
> gets replaced but not the first one..

No, there is not.  Ant parses ${} constructs by searching up to the next
closing brace, ignoring any newly opened ones by default.

${${n}${m}} is turned into

"value of property ${n" + "value of property m" + "literal }"

and since there is no property named "${n" it is expanded to ${${n}

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: project.replaceProperties()

Posted by Raja Nagendra Kumar <Na...@tejasoft.com>.
Stefan, you are correct.. We did make few modifcations to ant source and this
has side effect else where..

We are trying to support multiple property references resolutions with in a
string some thing like this..

Project p = getProject();
p.setProperty("nagrama", "nagiest");
p.setProperty("n", "nag");
p.setProperty("m", "rama");
p.replaceProperties("${${n}${m}}")//${${n}rama}
p.replaceProperties("${${m}${n}}") //${${m}nag}
p.replaceProperties("${${n}${m}${n}}")//${${n}ramanag}
p.replaceProperties("${nag${m}}")//${nag${m}}
p.replaceProperties("${nag${m}${n}}")//${nag${m}nag}
p.replaceProperties("${nag${m}${n}${m}}")//${nag${m}nagrama}
p.replaceProperties("${nag${m}${${n}${m}}}")//${nag${m}${${n}rama}}

the one in comments is current behaviors in original ant code.
Pl. observe that there is misbehavior of replace properties.. i.e 2nd one
gets replaced but not the first one..

May be it would be nice for properties and replaceProperties to support such
multi level property resolutions.

We are seeing such need to define the properties based on the module id,
this helps in writing macros and custom tasks based generic property names.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com










Stefan Bodewig wrote:
> 
> On 2009-09-27, Raja Nagendra Kumar <Na...@tejasoft.com> wrote:
> I haven't tested this but I'm pretty sure replaceProperties("${foo}")
> returns "${foo}" if there is no property named "foo", doesn't it?
> 

-- 
View this message in context: http://www.nabble.com/project.replaceProperties%28%29-tp25631397p25676498.html
Sent from the Ant - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: project.replaceProperties()

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-09-27, Raja Nagendra Kumar <Na...@tejasoft.com> wrote:

> In a custom task, when using replaceProperties() method is replacing the all
> the properties, including those does exist. For properties which does not
> exist, it replace them with null. Would it be possible to control not to
> touch upon those properties which does not exist.

I haven't tested this but I'm pretty sure replaceProperties("${foo}")
returns "${foo}" if there is no property named "foo", doesn't it?

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org