phing

Adding suffix to a list with foreach


I am including a .properties file, which has a list of properties:

configuration.files = file1, file2

configuration.files.file1.source      = config/filename1
configuration.files.file2.source      = config/filename2

Now I need the paths for each file changed to something like this:

vendor/project/config/filename1
vendor/project/config/filename2

To achieve that, I tried to foreach this list and prepend that suffix and overriding the existing property:

<foreach list="${configuration.files}" target="_prepend-vendor-path" param="file" >
    <property name="configuration.files.${file}.source" value="/vendor/project/${configuration.files.${file}.source}" override="true"/>
</foreach>

<target name="_prepend-vendor-path" >
    <echo msg="${configuration.files.${file}.source}" />
</target>

This doesn't work and I can't figure out why. Is it even possible to use target names like ${suffix}.name ? If not, how could I achive my goal here?


Solution

  • I just did some workaround for this, writing out the properties and their values to a file and readin them after the loop has finished with override = true:

    <target name="_prepend-vendor-path" >
        <exec dir="${project.basedir}" command="echo configuration.files.${file}.source = /vendor/project/${configuration.files.${file}.source} >> ${project.temp.config}" passthru="true" checkreturn="true" />
    </target>
    

    and after the foreach simply:

    <property file="${project.temp.config}" override="true"/>
    

    For some reason the properties won't be overridden in the foreach and I just can't figgure out why, but this little trick made it for me.