<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except in
compliance with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project name="pivot_build_by_jenkins" default="check" basedir="./pivot_trunk"
    xmlns:artifact="antlib:org.apache.maven.artifact.ant"
>
    <!-- Dynamic properties -->
    <property file="build.properties"/>
    <property name="running.on.jenkins" value="true"/>

    <!-- Classpath-related properties -->
    <property environment="env"/>
    <path id="classpath.env">
        <pathelement location="${env.CLASSPATH}"/>
    </path>
    <path id="classpath.javalib">
        <fileset dir="${java.home}/lib" includes="**/*.jar" excludes="**/jfxrt.jar"/>
    </path>
    <property name="classpath_env" refid="classpath.env"/>
    <property name="classpath_javalib" refid="classpath.javalib"/>

    <!-- Import Pivot build file -->
    <import file="./pivot_trunk/build.xml"/>

    <path id="classpath.general">
        <fileset dir="../ci-builds-on-jenkins/lib" includes="**/*.jar"/>
        <pathelement path="${classpath_javalib}"/>
    </path>

    <!-- Set version from jenkins or not -->
    <condition property="version" value="${base.version}-${jenkins.build}">
        <isset property="jenkins.job"/>
    </condition>
    <condition property="version" value="${base.version}">
        <not>
            <isset property="jenkins.job"/>
        </not>
    </condition>

    <!-- Help -->
    <target name="help" description="Put some help to console" depends="">
        <echo message="Running on Jenkins? ${running.on.jenkins}"/>
        <property name="classpath" refid="classpath.general"/>
        <echo message="Using Classpath: ${classpath}"/>
    </target>

    <!-- Check -->
    <target name="check" description="Check environment" depends="help">

        <sequential>
            <echo message="Using CLASSPATH=${classpath}"/>

            <!-- Ant version check -->
            <fail>
                <condition>
                    <not>
                        <antversion atleast="1.10.2"/>
                    </not>
                </condition>
                <![CDATA[
                Error:

                Building Pivot requires Apache Ant 1.10.2 or greater. Please see the BUILD
                file for more information.
                ]]>
            </fail>

            <!-- JDK version check -->
            <fail>
                <condition>
                    <not>
                        <or>
                            <equals arg1="${ant.java.version}" arg2="1.8"/>
                            <javaversion atleast="9"/>
                        </or>
                    </not>
                </condition>
                <![CDATA[
                Error:

                Building Pivot requires JDK 1.8 or greater. Please see the
                BUILD file for more information.
                ]]>
            </fail>

            <!-- JUnit check -->
            <fail>
                <condition>
                    <not>
                        <and>
                            <available classname="org.junit.Test" ignoreSystemClasses="true" classpath="${classpath}" />
                            <hasmethod classname="org.junit.Assert" method="assertNotEquals" ignoreSystemClasses="true" classpath="${classpath}" />
                        </and>
                    </not>
                </condition>
                <![CDATA[
                Error:

                JUnit 4.11 (or greater) must be on your classpath. Please see the BUILD
                file for more information.
                ]]>
            </fail>
        </sequential>

    </target>

</project>
