<?xml version="1.0" encoding="UTF-8"?>
<!--
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="harness" basedir="." default="netbeans">

    <import file="common.xml"/>
    <import file="jdk.xml"/>
    
    <target name="taskdefs" unless="harness.taskdefs.done">
        <dirname property="harness.dir" file="${harness.file}"/>
        <taskdef classpath="${harness.dir}/tasks.jar" resource="org/netbeans/nbbuild/taskdefs.properties"/>
        <property name="harness.taskdefs.done" value="true"/>
    </target>
    
    <target name="common-init" depends="taskdefs">
        <property name="netbeans.javadoc.dir" location="build/javadoc"/>
    </target>

    <target name="basic-init" depends="projectized-common.basic-init">
        <!-- Must be done even without build-init, or clean will not work. -->
        <condition property="cluster" value="${suite.dir}/build/cluster"> <!-- #59872 -->
            <isset property="suite.dir"/>
        </condition>
        <property name="cluster" location="build/cluster"/>
    </target>
    
    <target name="init" depends="basic-init,files-init,build-init"/>

    <target name="nbm-license-init" unless="license.file">
        <property name="license.file" location="${java.io.tmpdir}/no-license.txt"/>
        <echo file="${license.file}">[NO LICENSE SPECIFIED]</echo>
    </target>

    <target name="build-init" depends="basic-init,nbm-license-init">
        <condition property="public.package.jar.dir" value="${suite.dir}/build/public-package-jars">
            <isset property="suite.dir"/>
        </condition>
        <property name="public.package.jar.dir" location="build/public-package-jars"/>
        <mkdir dir="${public.package.jar.dir}"/>
        <!-- Similar to projectized.xml but does not try to set NBM homepage/distribution, nor is javahelp.excludes predefined. -->
        <parseprojectxml
            project="."
            publicpackagesproperty="public.packages"
            friendsproperty="friends"
            javadocpackagesproperty="module.javadoc.packages"
            moduledependenciesproperty="module.dependencies"
            moduleclasspathproperty="module.classpath"
            publicpackagejardir="${public.package.jar.dir}"
            modulerunclasspathproperty="module.run.classpath"
            classpathextensionsproperty="class.path.extensions"/>
        <condition property="is.regular">
            <not>
                <or>
                    <isset property="is.autoload"/>
                    <isset property="is.eager"/>
                    <equals arg1="${module.jar.dir}" arg2="core"/>
                    <equals arg1="${module.jar.dir}" arg2="lib"/>
                </or>
            </not>
        </condition>
        <property name="build.compiler.debug" value="true"/>
        <property name="build.compiler.debuglevel" value="source,lines,vars"/>
        <property name="build.compiler.deprecation" value="true"/>
        <property name="build.sysclasspath" value="ignore"/>
        <property name="build.compiler.optimize" value="off"/>
        <property name="build.package.compress" value="false"/>
        <property name="build.package.index" value="false"/>
        <property name="manifest.mf" location="manifest.mf"/>
        <property name="src.dir" location="src"/>
        <property name="build.classes.dir" location="build/classes"/>
        <property name="nbm" value="${code.name.base.dashes}.nbm"/>
        <property name="nbm.module.author" value=""/>
        <property name="nbm.release.date" value=""/>
        <property name="nbm.needs.restart" value="false"/>
        <property name="nbm.is.global" value=""/>
        <!-- Override if you want to use these: -->
        <property name="nbm.distribution" value=""/>
        <property name="nbm.homepage" value=""/>
        <path id="cp">
            <pathelement path="${module.classpath}"/>
            <pathelement path="${cp.extra}"/>
        </path>
        <property name="build.javahelp.dir" location="build/javahelp"/>
        <property name="javahelp.base" value="${code.name.base.slashes}/docs"/>
        <property name="javahelp.search" value="JavaHelpSearch"/>
    </target>

    <target name="test-lib-init" depends="init">
        <!-- Tricky, since who distributes these things? junit & testtools modules only. -->
        <!-- But those might not be installed anywhere. Not clear what to do. -->
        <!-- So we try four things in order (!): -->
        <!-- 1. You can define test.unit.lib.cp yourself if need be. -->
        <!-- 2. If the platform has some or all of junit & testtools modules, use them. -->
        <!-- 3. If running from the IDE and the caller IDE has these modules, use them. -->
        <!-- 4. If the dest dir happens to be nbbuild/netbeans/ in a NB source tree, use xtest sources. -->
        <!-- Would be nice to have: -->
        <!-- 5. [not done yet] If ${netbeans.sources} includes a NB source tree, use xtest sources. -->
        <!-- ...but that would be more difficult to do, since you would need to parse netbeans.sources. -->
        <path id="test.unit.lib.cp">
            <pathelement path="${test.unit.lib.cp}"/> <!-- for manual override -->
            <fileset dir="${netbeans.dest.dir}">
                <include name="ide*/modules/ext/junit-*.jar"/>
            </fileset>
            <pathelement location="${netbeans.dest.dir}/testtools/modules/ext/nbjunit.jar"/>
            <pathelement location="${netbeans.dest.dir}/testtools/modules/ext/insanelib.jar"/>
            <fileset dir="${netbeans.home}/..">
                <include name="ide*/modules/ext/junit-*.jar"/>
            </fileset>
            <pathelement location="${netbeans.home}/../testtools/modules/ext/nbjunit.jar"/>
            <pathelement location="${netbeans.home}/../testtools/modules/ext/insanelib.jar"/>
            <pathelement location="${netbeans.user}/modules/ext/nbjunit.jar"/>
            <pathelement location="${netbeans.user}/modules/ext/insanelib.jar"/>
            <pathelement location="${netbeans.dest.dir}/../../xtest/lib/junit.jar"/>
            <pathelement location="${netbeans.dest.dir}/../../xtest/lib/nbjunit.jar"/>
            <pathelement location="${netbeans.dest.dir}/../../xtest/lib/insanelib.jar"/>
        </path>
    </target>
    
    <target name="javahelp" depends="init" if="has.javahelp">
        <!-- Similar to projectized.xml but does not fiddle with usersguide/.../ide.css, and finds jhall.jar differently: -->
        <property name="jhall.jar" location="${harness.dir}/jsearch-2.0_03.jar"/>
        <available property="jhall.jar.exists" file="${jhall.jar}"/>
        <fail unless="jhall.jar.exists">You must set 'jhall.jar' (e.g. in private.properties) to the location of jsearch.jar from a JavaHelp distribution</fail>
        <mkdir dir="${build.javahelp.dir}/${javahelp.base}/${javahelp.search}"/>
        <copy todir="${build.javahelp.dir}">
            <fileset dir="javahelp"/>
        </copy>
        <jhindexer basedir="${build.javahelp.dir}/${javahelp.base}"
                   db="${build.javahelp.dir}/${javahelp.base}/${javahelp.search}">
            <classpath>
                <pathelement location="${jhall.jar}"/>
            </classpath>
            <include name="**/*.html"/>
            <exclude name="${javahelp.search}/"/>
            <exclude name="${javahelp.excludes}"/>
        </jhindexer>
        <mkdir dir="${cluster}/${javahelp.jar.dir}"/>
        <jar jarfile="${cluster}/${javahelp.jar}" compress="true">
            <fileset dir="${build.javahelp.dir}"/>
        </jar>
    </target>

    <target name="javadoc" depends="build-init,-javadoc-init">
        <mkdir dir="${netbeans.javadoc.dir}/${code.name.base.dashes}"/>
        <javadoc destdir="${netbeans.javadoc.dir}/${code.name.base.dashes}" packagenames="${module.javadoc.packages}" source="${javac.source}" windowtitle="${javadoc.title}">
            <classpath refid="cp"/>
            <sourcepath location="${src.dir}"/>
            <doctitle>${javadoc.title}</doctitle>
            <header>${javadoc.header}</header>
        </javadoc>
    </target>

    <target name="javadoc-nb" depends="init,javadoc" if="netbeans.home">
        <nbbrowse file="${netbeans.javadoc.dir}/${code.name.base.dashes}/index.html"/>
    </target>
    
    <target name="run" depends="netbeans">
        <ant antfile="${harness.dir}/run.xml" target="run"/>
    </target>

    <target name="profile" depends="netbeans,-jdk-presetdef-nbprofiledirect">
        <ant antfile="${harness.dir}/run.xml" target="profile"/>
    </target>
    
    <target name="debug" depends="netbeans,-jdk-presetdef-nbjpdastart">
        <ant antfile="${harness.dir}/run.xml" target="debug"/>
    </target>
    
    <target name="reload" depends="netbeans">
        <ant antfile="${harness.dir}/run.xml" target="run">
            <property name="run.args" value='--reload "${cluster}/${module.jar}"'/>
        </ant>
    </target>
    
    <target name="reload-in-ide" depends="netbeans">
        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
        <nbinstaller module="${cluster}/${module.jar}" action="reinstall"/>
    </target>
    
</project>
