<?xml version="1.0" encoding="UTF-8"?>

<!--
  Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

  This code is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License version 2 only, as
  published by the Free Software Foundation.  Oracle designates this
  particular file as subject to the "Classpath" exception as provided
  by Oracle in the LICENSE file that accompanied this code.

  This code is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  version 2 for more details (a copy is included in the LICENSE file that
  accompanied this code).

  You should have received a copy of the GNU General Public License version
  2 along with this work; if not, write to the Free Software Foundation,
  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  or visit www.oracle.com if you need additional information or have any
  questions.
-->

<project name="jtharness-dependencies" default="verify-dependencies" basedir=".">

    <property file="local.properties"/>
    <property file="build.properties"/>

    <!-- servlet-api -->
    <target name="verify-servlet-api">
        <available file="${servletjar}" type="file" property="servlet.present"/>
        <antcall target="compile-servlet-warning"/>
        <antcall target="checksum-servlet-warning"/>
    </target>

    <target name="compile-servlet-warning" unless="servlet.present">
        <echo message="${servlet.missing}"/>
    </target>

    <target name="compare-servlet-checksum" if="servlet.present">
        <checksum file="${servletjar}" algorithm="sha1" property="${servlet.checksum}" verifyproperty="servlet.checksum.matches"/>
        <condition property="servlet.checksum.differs">
            <equals arg1="${servlet.checksum.matches}" arg2="false"/>
        </condition>
    </target>

    <target name="checksum-servlet-warning" depends="compare-servlet-checksum" if="${servlet.checksum.differs}" unless="verify.off">
        <fail if="verify.strict" message="wrong checksum for servlet dependency"/>
        <echo message="warning: ${servlet.wrong.checksum}" level="warning"/>
    </target>
    <!-- -->

    <!-- junit support-->
    <target name="verify-junit">
        <available file="${asmjar}" type="file" property="asm.present"/>
        <available file="${asmcommonsjar}" type="file" property="asm.commons.present"/>
        <available file="${junitlib}" type="file" property="junitlib.present"/>

        <condition property="jar.junit.dependencies.present">
            <and>
                <available file="${asmjar}" type="file"/>
                <available file="${asmcommonsjar}" type="file"/>
                <available file="${junitlib}" type="file"/>
            </and>
        </condition>
        <antcall target="compile-junit-warning"/>
        <antcall target="checksum-asm-warning"/>
        <antcall target="checksum-asm-commons-warning"/>
        <antcall target="checksum-junitlib-warning"/>
    </target>

    <target name="compile-junit-warning" unless="jar.junit.dependencies.present">
        <echo message="${junit.libs.missing}"/>
    </target>

    <target name="compare-asm-checksum" if="asm.present">
        <checksum file="${asmjar}" algorithm="sha1" property="${asm.checksum}" verifyproperty="asm.checksum.matches"/>
        <condition property="asm.checksum.differs">
            <equals arg1="${asm.checksum.matches}" arg2="false"/>
        </condition>
    </target>

    <target name="checksum-asm-warning" depends="compare-asm-checksum" if="${asm.checksum.differs}" unless="verify.off">
        <fail if="verify.strict" message="wrong checksum for asm dependency"/>
        <echo message="warning: ${asm.wrong.checksum}" level="warning"/>
    </target>

    <target name="compare-asm-commons-checksum" if="asm.commons.present">
        <checksum file="${asmcommonsjar}" algorithm="sha1" property="${asm.commons.checksum}" verifyproperty="asm.commons.checksum.matches"/>
        <condition property="asm.commons.checksum.differs">
            <equals arg1="${asm.commons.checksum.matches}" arg2="false"/>
        </condition>
    </target>

    <target name="checksum-asm-commons-warning" depends="compare-asm-commons-checksum" if="${asm.commons.checksum.differs}" unless="verify.off">
        <fail if="verify.strict" message="wrong checksum for asm-commons dependency"/>
        <echo message="warning: ${asm.commons.wrong.checksum}" level="warning"/>
    </target>

    <target name="compare-junitlib-checksum" if="junitlib.present">
        <checksum file="${junitlib}" algorithm="sha1" property="${junitlib.checksum}" verifyproperty="junitlib.checksum.matches"/>
        <condition property="junitlib.checksum.differs">
            <equals arg1="${junitlib.checksum.matches}" arg2="false"/>
        </condition>
    </target>

    <target name="checksum-junitlib-warning" depends="compare-junitlib-checksum" if="${junitlib.checksum.differs}" unless="verify.off">
        <fail if="verify.strict" message="wrong checksum for junit dependency"/>
        <echo message="warning: ${junit.wrong.checksum}" level="warning"/>
    </target>
    <!-- -->

    <!-- serial -->
    <target name="verify-serial">
        <available file="${jcommjar}" type="file" property="jcomm.present"/>
        <antcall target="compile-serial-warning"/>
        <antcall target="checksum-serial-warning"/>
    </target>

    <target name="compile-serial-warning" unless="jcomm.present">
        <echo message="${jcomm.missing}"/>
    </target>

    <target name="compare-serial-checksum" if="jcomm.present">
        <checksum file="${jcommjar}" algorithm="sha1" property="${jcomm.checksum}" verifyproperty="jcomm.checksum.matches"/>
        <condition property="jcomm.checksum.differs">
            <equals arg1="${jcomm.checksum.matches}" arg2="false"/>
        </condition>
    </target>

    <target name="checksum-serial-warning" depends="compare-serial-checksum" if="${jcomm.checksum.differs}" unless="verify.off">
        <fail if="verify.strict" message="wrong checksum for Serial Agent dependency"/>
        <echo message="warning: ${jcomm.wrong.checksum}" level="warning"/>
    </target>
    <!-- -->

    <target name="verify-dependencies" depends="verify-servlet-api, verify-serial, verify-junit">
    </target>
</project>