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: parsing param in for each
Date Wed, 18 Jun 2003 05:31:40 GMT
AFAIK you can┬┤t ... directly.

I wrote a workaround which extract the value from your parameter.
- write the value to file <echo>
- convert the file to needed format <replaceregexp>
- load the new 'properties'file <property>
- delete the temporary 'properties'file <delete>
- use the value


    <target name="geteach">
        <property name="config" value="defaultValue:defaultType"/>
        <!-- Property conversion START -->
        <echo file="${tmp.file}" message="configNew=${config}"/>
        <replaceregexp file="${tmp.file}" match=":.*" replace="" />
        <property file="${tmp.file}"/>
        <delete file="${tmp.file}"/>
        <!-- Property conversion END -->
        <echo>$${config}    = &gt;${config}&lt;</echo>
        <echo>$${configNew} = &gt;${configNew}&lt;</echo>
    </target>


Another way is to split the value via java.util.StringTokenizer and <script>
task.

    <target name="geteach2">
        <script language="javascript"> <![CDATA[
            config = project.getProperty("config");
            st = new java.util.StringTokenizer(config, ":");
            value = st.nextToken();
            type  = st.nextToken();

            echo = project.createTask("echo");
            echo.setMessage("config="+config + " value="+value + "
type="+type);
            echo.perform();
        ]]> </script>
    </target>



Called with
    <target name="main">
        <foreach list="${configs}" delimiter="," target="geteach"
param="config"/>
        <foreach list="${configs}" delimiter="," target="geteach2"
param="config"/>
    </target>
I got


main:

geteach:
   [delete] Deleting: C:\temp\tmp.txt
     [echo] ${config}    = >FooName1:FooType1<
     [echo] ${configNew} = >FooName1<

geteach:
   [delete] Deleting: C:\temp\tmp.txt
     [echo] ${config}    = >FooName2:FooType2<
     [echo] ${configNew} = >FooName2<

geteach2:
     [echo] config=FooName1:FooType1 value=FooName1 type=FooType1

geteach2:
     [echo] config=FooName2:FooType2 value=FooName2 type=FooType2




Hope this helps


Jan

> -----Urspr├╝ngliche Nachricht-----
> Von: Xiaohong Wang [mailto:xwang@esri.com]
> Gesendet am: Dienstag, 17. Juni 2003 19:06
> An: 'Ant Users List'
> Betreff: parsing param in for each
> 
> Hi,
> 
> In my for each loop,  
> <foreach list="${configs}" delimiter=" ," target="geteach"
> 			param="config"/>
> 
> ${configs}="FooName1:FooType1,FooName2:FooType2",
> 
> is there any way that when geteach task is invoked, I can only have
> FooName1, FooName2 passed as param, not the whole FooName1:FooType1.
> Appreciate any ideas!
> 
> Thanks
> Xiao
> 
> ---------------------------------------------------------------------
> 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