<project name="TraceAgentLoader" basedir="." default="help">
	
  <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="./lib/ant-contrib-1.0b3.jar" />
	
  <target name="help">
    <java classname="org.apache.tools.ant.Main">
      <arg value="-projecthelp" />
    </java>
  </target>

  <target name="build" description="Comile classes">
    <delete dir="./bin"/>
    <mkdir dir="./bin" />

    <javac srcdir="./src" destdir="./bin" debug="true" source="1.6" target="1.6" nowarn="true" />
  </target>
	
  <target name="getgitdetails" >
    <exec executable="git" outputproperty="git.tagstring">
      <arg value="describe"/>
    </exec>
    <exec executable="git" outputproperty="git.revision">
      <arg value="rev-parse"/>
      <arg value="HEAD"/>
    </exec>
    <if>
      <contains string="${git.tagstring}" substring="cannot"/>
      <then>
        <property name="git.tag" value="none"/>
      </then>
      <else>
        <property name="git.tag" value="${git.tagstring}"/>
      </else>
    </if>
  </target>

  <target name="jar" description="Create the Agent Jar" depends="build,getgitdetails">
    <mkdir dir="./built/" />
    
    <!-- CUI Agent Loader -->
    <jar destfile="./built/cuiagentloader.jar" compress="false">
      <manifest>
        <attribute name="Main-Class" value="org.intrace.agentloader.AgentLoader" />
        <attribute name="Class-Path" value=". ./tools.jar" />
        <attribute name="Git-Revision" value="${git.revision}" />
        <attribute name="Implementation-Version" value="${git.tag}" />      	
      </manifest>
      <fileset dir="./bin" includes="**/*.class" />
    </jar>
  </target>
</project>
