<?xml version="1.0" encoding="UTF-8" ?>
<!--
   Copyright (c) 2013, 2019 Red Hat, Inc. and others

   All rights reserved. This program and the accompanying materials
   are made available under the terms of the Eclipse Public License 2.0
   which accompanies this distribution, and is available at
   https://www.eclipse.org/legal/epl-2.0/

   SPDX-License-Identifier: EPL-2.0
-->
<!--
Most traces are taken from the Wireshark website and are available under the GNU General Public License.
http://wiki.wireshark.org/SampleCaptures
-->

<project name="Extract Traces" default="main" >

<target name="main">
  <antcall>
    <target name="checkAnyTraceExists"/>
    <target name="verifyChecksum"/>
    <target name="deleteFailedCheckSumTraces"/>
  </antcall>
  <antcall target="downloadTraceFiles"/>
  <condition property="tracesExist">
    <and>
      <available file="Short_LittleEndian.pcap.zip" />
    </and>
  </condition>
  <antcall target="extractTraces"/>
</target>

<target name="checkAnyTraceExists">
  <pathconvert property="anyTraceExists" setonempty="false" pathsep=" ">
    <path>
      <fileset dir="." includes="*.zip *.bz2" />
    </path>
  </pathconvert>
</target>

<target name="verifyChecksum">
  <echo message="Verifying: ${anyTraceExists}"/>
  <condition property="failedCheckSum">
    <and>
      <isset property="anyTraceExists"/>
      <not>
        <and>
          <checksum>
            <fileset dir="." includes="*.zip *.bz2" />
          </checksum>
        </and>
      </not>
    </and>
  </condition>
</target>


<target name="deleteFailedCheckSumTraces" if="failedCheckSum">
  <echo message="Some traces have failed the checksum tests. Deleting traces."/>
  <delete verbose="true">
    <fileset dir="." includes="*.zip *.bz2" />
  </delete>
</target>

<target name="warnFailedCheckSum" if="failedCheckSum">
  <echo message="WARNING: Some downloaded traces failed the checkum."/>
</target>

<target name="downloadTraceFiles">
  <echo message="Attempting to download test traces"/>
  <get ignoreerrors="true" maxtime="1200" dest="Short_LittleEndian.pcap.zip" skipexisting="true" src="http://wiki.eclipse.org/images/1/18/Short_LittleEndian.pcap.zip" />
  <get ignoreerrors="true" maxtime="1200" dest="Short_BigEndian.pcap.zip" skipexisting="true" src="http://wiki.eclipse.org/images/2/25/Short_BigEndian.pcap.zip" />
  <get ignoreerrors="true" maxtime="1200" dest="MostlyUDP.pcap.zip" skipexisting="true" src="http://wiki.eclipse.org/images/6/64/MostlyUDP.pcap.zip" />
  <get ignoreerrors="true" maxtime="1200" dest="MostlyTCP.pcap.zip" skipexisting="true" src="http://wiki.eclipse.org/images/8/8d/MostlyTCP.pcap.zip" />
  <get ignoreerrors="true" maxtime="1200" dest="EmptyPcap.pcap.zip" skipexisting="true" src="http://wiki.eclipse.org/images/c/c1/EmptyPcap.pcap.zip" />
  <get ignoreerrors="true" maxtime="1200" dest="BadPcapFile.pcap.zip" skipexisting="true" src="http://wiki.eclipse.org/images/5/5e/BadPcapFile.pcap.zip" />
  <get ignoreerrors="true" maxtime="2400" dest="BenchmarkTrace.pcap.zip" skipexisting="true" src="http://wiki.eclipse.org/images/1/12/BenchmarkTrace.pcap.zip" />
  <get ignoreerrors="true" maxtime="1200" dest="sample-ctf-trace-20120412.tar.bz2" skipexisting="true" src="http://lttng.org/files/samples/sample-ctf-trace-20120412.tar.bz2"/>
</target>

<target name="extractTraces" if="tracesExist">
    <antcall>
      <target name="checkAnyTraceExists"/>
      <target name="verifyChecksum"/>
      <target name="warnFailedCheckSum"/>
    </antcall>
    <unzip src="Short_LittleEndian.pcap.zip" dest="." />
    <unzip src="Short_BigEndian.pcap.zip" dest="." />
    <unzip src="MostlyUDP.pcap.zip" dest="." />
    <unzip src="MostlyTCP.pcap.zip" dest="." />
    <unzip src="EmptyPcap.pcap.zip" dest="." />
    <unzip src="BadPcapFile.pcap.zip" dest="." />
    <unzip src="BenchmarkTrace.pcap.zip" dest="." />
    <bunzip2 src="sample-ctf-trace-20120412.tar.bz2"/>
    <untar src="sample-ctf-trace-20120412.tar" dest="." />
    <echo message="Traces extracted successfully"/>
</target>
</project>
