<?xml version="1.0"?>
<!--
The contents of this file are subject to the terms of the Common Development
and Distribution License (the License). You may not use this file except in
compliance with the License.

You can obtain a copy of the License at http://www.netbeans.org/cddl.html
or http://www.netbeans.org/cddl.txt.

When distributing Covered Code, include this CDDL Header Notice in each file
and include the License file at http://www.netbeans.org/cddl.txt.
If applicable, add the following below the CDDL Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"

The Original Software is NetBeans. The Initial Developer of the Original
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
Microsystems, Inc. All Rights Reserved.
-->

<project name="xtest-qa-functional" basedir="." default="all">

    <!-- Root folder of modules -->
    <dirname property="nb_all" file="${ant.file.xtest-qa-functional}/../.."/>

    <target name="init">
        <property file="../nbproject/private/private.properties"/>
        <property file="../nbproject/project.properties"/>
        <property name="build.compiler.debug" value="true"/>
        <property name="build.compiler.source" value="${ant.java.version}"/>
        <property name="build.compiler.deprecation" value="true"/>
        <property name="build.sysclasspath" value="ignore"/>
    </target>

    <target name="build-jellytools" if="need.to.build.jellytools">
        <!-- <ant dir="${nb_all}/jellytools" target="jar-library" inheritAll="false"/> -->
        <!-- The following is used instead of above because inheritAll="false"
        doesn't work for all properties. Properties xtest.home and xtest.testtype
        has to be null to not scan module binaries because modules jemmy.module and
        nbjunit are not within IDE binaries (see
        nbbuild/antsrc/org/netbeans/nbbuild/ModuleListParser.java).
        -->
        <java classname="org.apache.tools.ant.Main" classpath="${java.class.path}" fork="true">
            <arg value="-f"/>
            <arg value="${nb_all}/jellytools/build.xml"/>
            <arg value="jar-library"/>
        </java>
    </target>
    
    <target name="init-cp">
        <!-- If jellytools repository available and jar not up to date, build jelly2-nb.jar -->
        <condition property="need.to.build.jellytools">
            <and>
                <available file="${nb_all}/jellytools/src" type="dir"/>
                <not>
                    <uptodate targetfile="${nb_all}/jellytools/jelly2-nb.jar" >
                        <srcfiles dir= "${nb_all}/jellytools/src"/>
                    </uptodate>
                </not>
            </and>
        </condition>
        <!-- <available file="${nb_all}/jellytools/src" type="dir" property="jellytools.available"/> -->
        <antcall target="build-jellytools"/>
        <!-- Used built jar preferably. If not available use the latest from CVS. -->
        <available file="${nb_all}/jellytools/jelly2-nb.jar" property="jelly.jar" value="${nb_all}/jellytools/jelly2-nb.jar"/>
        <property name="jelly.jar" location="${nb_all}/jellytools/builds/jelly2-nb.jar"/>
        <!-- path reference used in both compiler and executor -->
        <path id="jemmy.and.jelly.path">
            <pathelement location="${nb_all}/jemmy/builds/jemmy.jar"/>
            <pathelement location="${jelly.jar}"/>
        </path>
        <path id="test.qa-functional.compile.cp">
            <path refid="jemmy.and.jelly.path"/>
            <pathelement path="${test.qa-functional.cp.extra}"/>
        </path>
        <!-- This property cannot be undefined. -->
        <property name="test.qa-functional.run.cp.extra" value=""/>
        <path id="test.qa-functional.run.cp">
            <path refid="jemmy.and.jelly.path"/>
            <pathelement path="${test.qa-functional.run.cp.extra}"/>
        </path>
    </target>
    
    <!-- ========= -->
    <!-- Compilers -->
    <!-- ========= -->
    
    <target name="qa-functional-compiler" depends="init,init-cp">
        <buildTests srcdir="qa-functional/src" compileexcludes="**/data/**">
            <classpath refid="test.qa-functional.compile.cp"/>
        </buildTests>
    </target>
    
    <!-- ========= -->
    <!-- Executors -->
    <!-- ========= -->
    
    <target name="runidetest" depends="init,init-cp">
        <executeTests pluginname="ide">
            <classpath refid="test.qa-functional.run.cp"/>
        </executeTests>
    </target>
    
    <!-- ================ -->
    <!-- Run in IDE's JVM -->
    <!-- ================ -->

    <target name="internal-execution" depends="init,init-cp">
        <taskdef name="internalExecution" classname="org.netbeans.xtest.plugin.ide.IdeInternalExecutionTask" 
                 classpath="${xtest.home}/plugins/ide/lib/xtest-ide-plugin.jar"/>

        <!-- Root directory where tests are built in. It means there will be
             separate folder for each test type: ${compile.destdir.root}/${xtest.testtype}/classes.
             Originally defined in module_harness.xml.             
        -->
        <property name="compile.destdir.root" location="../build/test"/>
        <!-- Destination directory for compiled tests. Used in basic_compiler_targets.xml. -->
        <property name="compile.destdir" location="${compile.destdir.root}/${xtest.testtype}/classes"/>
        <!-- JUnit, NbJUnit, NBJUnit-ide and Insane should be in classpath by default -->
        <property name="junit.classpath" value="${xtest.home}/lib/junit.jar:${xtest.home}/lib/nbjunit.jar:${xtest.home}/lib/nbjunit-ide.jar:${xtest.home}/lib/insanelib.jar"/>

        <!-- This target runs main method of given class in IDE's JVM. 
            You have -->
        <internalExecution classname="${classname}">
            <classpath>
                <path refid="test.qa-functional.run.cp"/>
                <pathelement path="${compile.destdir}"/>
                <pathelement path="${junit.classpath}"/>
            </classpath>
        </internalExecution>
    </target>
</project>

