Search code examples
buildphing

Ending target early in Phing


I am trying to modify a Phing script and cannot see what I thought would be an obvious feature.

The Phing script has a generic 'confirm' target which checks for input at various stages of execution. I want to automate the script so that it can run without input. I would expect to be able to to this by inserting some kind of <break> or <end> type task within the target so that it returns early. The manual does't appear to list such functionality.

I know I can achieve this, by creating an intermediate target to check the cmd line argument first and then call the confirm target, but is there a more elegant way?

This is the target that needs automating and is called from multiple places. The trigger to skip would be a property set via cmd line -D.

 <!-- confirm a user action -->
<target name="confirm">
    <input propertyname="confirm" validargs="yes,no">
        ${confirm.message} ('yes' to continue)
    </input>
    <if>
        <not>
            <equals arg1="${confirm}" arg2="yes" />
        </not>
        <then>
            <fail message="You didn't say 'yes'" />
        </then>
    </if>
</target>

Solution

  • For the same purpose I'm using this tech:

    <if>
      <not>
        <isset property="confirm" />
      </not>
      <then>
        <input propertyname="confirm" validargs="yes,no">
            ${confirm.message} ('yes' to continue)
        </input>
        <if>
            <not>
                <equals arg1="${confirm}" arg2="yes" />
            </not>
            <then>
                <fail message="You didn't say 'yes'" />
            </then>
        </if>
      </then>
    </if>
    

    then you can execute

    phing build.xml -Dconfirm=yes
    

    without promt.