Dieses Blog durchsuchen

Dienstag, 20. September 2016

ant: create targets for different os

If you want to execute your ant task on different os like windows or linux you can use a special exec attribute "osfamily"

This attribute allows you to define targets for each os.

Here is a sample target to execute phpunit on linux and windows.

server.crt
<project name="Testproject" default="dist" basedir=".">
  <description>
    simple example build file
  </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist" location="dist"/>

  <target name="init">
    <antcall target="PHPUnit" />
  </target>


  <target  name="PHPUnit" description="Run PHP Unit">
    <exec osfamily="unix" executable="${basedir}/vendor/bin/phpunit" failonerror="true">
      <arg value="--configuration"/>
      <arg value="${basedir}/phpunit.xml"/>
    </exec>
      <exec osfamily="windows" executable="${basedir}/vendor/bin/phpunit.bat" failonerror="true">
          <arg value="--configuration"/>
          <arg value="${basedir}/phpunit.xml"/>
      </exec>
  </target>

  <target name="dist">
  </target> 
  <target name="clean"
        description="clean up">
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>

Simply run:

ant init

As you can see, there are 2 exec objects with a osfamily attribute for windows and linux.

This is simply awsome !

Keine Kommentare:

Kommentar veröffentlichen