Nim
Nim

Reputation: 631

Set ant property by invoking a shell script?

Is there any way to set an ant property by capturing the output of a shellscript? (or another ant task)

Something like this:

<property name="foo">
    <value>
        <exec executable="bar" />
    </value>
</property>

Thanks!

Upvotes: 6

Views: 3809

Answers (3)

Oscar Bravo
Oscar Bravo

Reputation: 280

To expand on @Nim's answer:

The tag can appear as an immediate child of the . It doesn't have to be inside a . This gives it global scope, like a tag.

Also, if you need a complex command, you can use arg tags.

For example, if you want to add the Git branch name to a jar manifest, you do something like this:

 <project>

    <property name="user" value="fred"/>

    <!-- git.branch gets set globally -->
    <exec executable="/usr/bin/git" outputproperty="git.branch">
      <arg value="rev-parse"/>
      <arg value="--abbrev-ref"/>
      <arg value="HEAD"/>
    </exec>

    <target name="make-jar">
      <jar jarfile="project.jar">
        <manifest>
          <attribute name="Built-By" value="${user}"/>
          <attribute name="Git-Branch" value="${git.branch}"/>
        </manifest>
        <fileset dir="${classes.dir}" includes="**/*.class"/>
      </jar>
    </target>
  </project>

Upvotes: 4

Pulak Agrawal
Pulak Agrawal

Reputation: 2481

From the ANT exec task

  1. Set the output attribute : Name of a file to which to write the output.
  2. As Marble has suggested - set the outputproperty

When I tested they came out to be mutually exclusive. So set only 1 of them at a time.

Upvotes: 8

Nim
Nim

Reputation: 631

It seems that exec task has an outputproperty-property, like so:

<exec executable="bar" outputproperty="foo" />

Upvotes: 9

Related Questions