ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: Conditionally passing property to <ant>
Date Wed, 30 Apr 2003 08:15:56 GMT
I am playing ...

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="test" basedir="." default="main">
    <target name="main">
        <!-- My properties for the called ant instance -->
        <property name="prop1" value="This is prop1" />
        <property name="prop3" value="And this the value of prop3" />

        <!-- helper -->
        <property name="br" value="${line.separator}" />

        <!-- create a property file -->
        <echo file="props.txt" append="false"
message="prop1=${prop1}${br}"/>
        <echo file="props.txt" append="true"
message="prop2=${prop2}${br}"/>
        <echo file="props.txt" append="true"
message="prop3=${prop3}${br}"/>
        <echo file="props.txt" append="true"
message="prop4=${prop4}${br}"/>
        <ant target="print" inheritAll="false">
            <property name="propfile" value="props.txt"/>
        </ant>
    </target>

    <target name="print">
        <!-- Load the properties; filtering ${name} -->
        <loadproperties srcFile="${propfile}">
            <filterchain>
                <linecontainsregexp>
                    <regexp pattern="=\$\{prop" />
                </linecontainsregexp>
            </filterchain>
        </loadproperties>
        <echoproperties prefix="prop"/>
    </target>
</project>


does nearly what I want:

main:

print:
[echoproperties] #Ant properties
[echoproperties] #Wed Apr 30 10:04:44 CEST 2003
[echoproperties] propfile=props.txt
[echoproperties] prop4=${prop4}
[echoproperties] prop2=${prop2}

BUILD SUCCESSFUL
Total time: 1 second


But I need the other two ... I don´t know how to invert the regexp. If there
is no way
you can write a filter "linenotcontainsregexp".
But I found some new stuff in CVS: TokenFilter, maybe I find a solution with
them ...


Jan Matèrne



> -----Ursprüngliche Nachricht-----
> Von: peter reilly [mailto:peter.reilly@corvil.com]
> Gesendet am: Mittwoch, 30. April 2003 09:54
> An: Ant Users List
> Betreff: Re: Conditionally passing property to <ant>
> 
> On Tuesday 29 April 2003 19:34, Jesse Stockall wrote:
> > On Tue, 2003-04-29 at 11:10, peter reilly wrote:
> > > This solution is not scalable for multiple
> > > properties.
> >
> > It wasn't designed to. The original use case mentioned 1 property.
> 
> Yes, but the original use case was an example to indicate the
> problem, the original author had 7 properties.
> 
> >
> > > The correct solution is to allow if and unless in
> > > the property task (or more general in all tasks).
> >
> > That's not a solution at all, it's an often debated topic 
> that doesn't
> > seem close to being accepted into ant.
> 
> True...., in any case allowing the if attribute for the property task
> would not work in this instance as the nested property task 
> in <ant/> is
> run in the context of the new project. The code would need to
> extend the proptery task and intercept the if and unless attributes
> and use them in the context of the original project. Easy to do but
> would need agreement from the "ant police".
> 
> >
> > In this case where there is a lot of conditional logic 
> required I would
> > suggest the <if> task from ant-contrib
> 
> This would not work in this instance
> 
> > http://sourceforge.net/projects/ant-contrib/ or refactor 
> the build files
> > so that 'inheritAll' can be true.
> 
> This is probally the best solution.
> 
> Peter
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

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