I want to overwrite the hosts file on the Windows machine if the user allows it:
<input message="Do you want to overwrite the HOSTS file?"
addproperty="overwrite.hosts" validargs="yes,no" />
<copy tofile="${env.WINDIR}/system32/drivers/etc/hosts.backup">
<fileset file="${env.WINDIR}/system32/drivers/etc/hosts" />
</copy>
<copy todir="${env.WINDIR}/system32/drivers/etc">
<fileset file="${trainer.dir}/hosts" />
</copy>
How do I do the copies only if the user says yes?
EDIT:
I tried this:
<input message="Do you want to overwrite the HOSTS file?" addproperty="overwrite.hosts" validargs="yes,no" />
<if>
<equals arg1="${overwrite.hosts}" arg2="yes" />
<then>
<copy tofile="${env.windir}/system32/drivers/etc/hosts.backup">
<fileset file="${env.windir}/system32/drivers/etc/hosts">
</fileset>
</copy>
<copy todir="${env.windir}/system32/drivers/etc">
<fileset file="${trainer.dir}/hosts">
</fileset>
</copy>
</then>
</if>
and I get this output:
C:\trainer\build.xml:16: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
I'm an ant rookie... What do I need to do?
A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors. PatternSets can be specified as nested <patternset> elements.
This object represents a path as used by CLASSPATH or PATH environment variable. A path might also be described as a collection of unique filesystem resources. and PathElement: Helper class, holds the nested <pathelement> values.
It allows you to reuse the same build file, with different property settings for different execution environment. For example, build properties file can be maintained separately for DEV, TEST, and PROD environments. It is useful, when you do not know the values for a property (in a particular environment) up-front.
You could use a condition
or a if
task for that. (The latter is part of the ant-contrib project.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With