Tuesday 11 March 2014

ANT - Build.xml to detect Operating System

Build.xml
<project name="MyProject" default="main">
   <target name="main" description="execute commands depending on OS">
       <condition property="isUnix">
          <os family="unix" />
       </condition>
       <condition property="isWindows">
          <os family="windows" />
       </condition>
       <antcall target="setUnixEnv" />
       <antcall target="setWindowsEnv" />
   </target>
 
   <target name="setUnixEnv" if="isUnix">
       <echo>This is an Unix machine.</echo>  
       <!-- Put your Logic here . An example is shown below-->
       <exec executable="sh">
          <arg value="-c" />
          <arg value="chmod 777 file.js" />
       </exec>
   </target>
 
   <target name="setWindowsEnv" if="isWindows">
       <echo>This is a Windows machine.</echo>
       <!-- Put your Logic here . An example is shown below-->
       <exec executable="cmd">
          <arg value="/c"/>
          <arg value="ipconfig"/>
       </exec>
   </target>
</project>

  

No comments:

Post a Comment