SJS
SJS

Reputation: 5667

Ant insert prompt values into files

I am trying to make a Ant script that would promote the SA for some values and it would add them to files. If you run the following script the property name gets added to the files not the value?

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="run-count" name="run">
    <!--this file was created by Eclipse Runnable JAR Export Wizard-->
    <!--Ant 1.7 is required      
                               -->
    <target name="run-count">
         <input
            message="Please enter db-username:"
            addproperty="db.user"
          />
    </target>

    <concat destfile="input.txt" append="true">"${db.user}"</concat>

    <echo file="file.txt" append="true">
    <![CDATA[
      <h1>"${db.user}"</h1>
    ]]>
    </echo>
</project>

Upvotes: 0

Views: 209

Answers (1)

ewan.chalmers
ewan.chalmers

Reputation: 16235

The problem is that you output to the file outside the scope of the target in which the property is set.

The content outside any target is executed first.

So it means that the file output is already done before you have prompted for the user to input the username.

Solutions...

  • move the concat and echo inside your run-count target, or
  • include them in some other target which depends on run-count, or
  • move the input element before them, outside any target.

Upvotes: 1

Related Questions