<?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="projectized-common" basedir=".">

    <!-- XXX supply descriptions for the appropriate targets -->
    <!-- XXX should use namespaces for NB in-VM tasks from ant/browsetask and debuggerjpda/ant and apisupport/ant -->
    <!-- XXX move more things here from projectized.xml when possible and desirable -->

    <condition property="testcoverage.import" value="testcoverage.xml">
        <and>
            <isset property="harness.dir"/>
            <available file="testcoverage.xml" filepath="${harness.dir}"/>
        </and>
    </condition>
    <condition property="testcoverage.import" value="${netbeans.dest.dir}/harness/testcoverage.xml">
        <and>
            <isset property="netbeans.dest.dir"/>
            <available file="testcoverage.xml" filepath="${netbeans.dest.dir}/harness"/>
        </and>
    </condition>
    <property name="testcoverage.import" value="no-testcoverage.xml"/>
    <import file="${testcoverage.import}"/>
    
    <target name="-build-dir-init">
        <property name="build.dir" location="build"/>
    </target>

    <target name="basic-init" depends="common-init,-jdk-init">
        <!-- Synch the following property loads with NbModuleProject.makeEvalDefs: -->
        <property file="nbproject/private/private.properties"/>
        <property file="nbproject/project.properties"/>
        <!-- Do not try to set module.classpath here, in particular: -->
        <!-- during a clean, the ${foo/bar.dir} properties may not be set. -->
        <parseprojectxml project="." 
                         codenamebaseproperty="code.name.base"
                         codenamebasedashesproperty="code.name.base.dashes"
                         codenamebaseslashesproperty="code.name.base.slashes"
        />
        <property name="module.jar.dir" value="modules"/>
        <property name="module.jar.basename" value="${code.name.base.dashes}.jar"/>
        <property name="module.jar" value="${module.jar.dir}/${module.jar.basename}"/>
        <available property="has.javahelp" file="javahelp" type="dir"/>
        <property name="javahelp.jar.dir" value="modules/docs"/>
        <property name="javahelp.jar.basename" value="${code.name.base.dashes}.jar"/>
        <property name="javahelp.jar" value="${javahelp.jar.dir}/${javahelp.jar.basename}"/>
        <condition property="javahelp.class.path.extension" value="docs/${javahelp.jar.basename}">
            <isset property="has.javahelp"/>
        </condition>
        <property name="javac.source" value="1.7"/>
        <property name="javac.default.target" value="${javac.source}"/>
        <property name="javac.target" value="${javac.default.target}"/>
        <property name="javac.compilerargs" value=""/>
        <property name="module.auto.deps.xml" location="module-auto-deps.xml"/>
        <condition property="has.module.auto.deps">
            <available file="${module.auto.deps.xml}"/>
        </condition>
        <property name="jar-excludes" value="**/*.java,**/*.form,**/package.html,**/doc-files/"/>
        <property name="module.jar.verifylinkageignores" value=""/>
        <property name="cp.extra" value=""/>
        <tstamp>
            <format property="module.build.started.time" pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ"/>
        </tstamp>
        <condition property="asm.jar" value="${nbplatform.active.dir}/platform/core/asm-8.0.1.jar">
            <available file="${nbplatform.active.dir}/platform/core/asm-8.0.1.jar"/>
        </condition>
        <property name="asm.jar" location="${platform/libs.asm.dir}/core/asm-8.0.1.jar"/>
        <property name="tsaurl" value=""/>
        <property name="tsacert" value=""/>
    </target>

    <target name="-release.dir">
        <property name="release.dir" location="release"/>
        <condition property="has.release.dir">
            <available file="${release.dir}"/>
        </condition>
    </target>
    <target name="-release.files" depends="-release.dir" if="has.release.dir">
        <pathconvert pathsep="," property="release.files">
            <path>
                <fileset dir="${release.dir}"/>
            </path>
            <filtermapper>
                <replacestring from="${release.dir}${file.separator}" to=""/>
                <replacestring from=" " to="?"/>
            </filtermapper>
        </pathconvert>
    </target>
    <target name="files-init" depends="basic-init,-release.files">
        <property name="release.files" value=""/>
        <property name="release.files.extra" value=""/>
        <property name="extra.module.files" value=""/>
        <patternset id="module.files" includes="${release.files},${release.files.extra},${extra.module.files}">
            <include name="${module.jar}"/>
            <include name="${javahelp.jar}" if="has.javahelp"/>
            <include name="config/Modules/${code.name.base.dashes}.xml"/>
            <include name="config/ModuleAutoDeps/${code.name.base.dashes}.xml" if="has.module.auto.deps"/>
            <include name="ant/nblib/${code.name.base.dashes}.jar"/>
        </patternset>
    </target>

    <target name="-javac-init-nbjdk" depends="-jdk-preinit" if="nbjdk.valid">
        <macrodef name="custom-javac-presetdef">
            <attribute name="javacval"/>
            <sequential>
               <presetdef name="custom-javac">
                    <custom-javac executable="@{javacval}"/>
                </presetdef>
            </sequential>
        </macrodef>
        <custom-javac-presetdef javacval="${nbjdk.javac}"/>
    </target>

    <target name="-javac-init-bootclasspath-prepend" depends="build-init" if="bootclasspath.prepend">
        <presetdef name="nb-javac">
            <custom-javac>
                <bootclasspath>
                    <path path="${nbjdk.bootclasspath}"/>
                </bootclasspath>
                <compilerarg value="-Xbootclasspath/p:${bootclasspath.prepend}" />
            </custom-javac>
        </presetdef>
    </target>

    <target name="-javac-init-no-bootclasspath-prepend" depends="build-init" unless="bootclasspath.prepend">
        <presetdef name="nb-javac">
            <custom-javac>
                <bootclasspath>
                    <path path="${nbjdk.bootclasspath}"/>
                </bootclasspath>
            </custom-javac>
        </presetdef>
    </target>

    <target name="-javac-init" depends="build-init,-javac-init-nbjdk,-javac-init-bootclasspath-prepend,-javac-init-no-bootclasspath-prepend">
        <path id="cp">
            <pathelement path="${module.classpath}"/>
            <pathelement path="${cp.extra}"/>
        </path>
        <path id="processor.cp">
            <pathelement path="${module.processor.classpath}"/>
            <pathelement path="${cp.extra}"/>
        </path>
        <!-- Unlike ${module.classpath}, this does not use publicPackageJarDir, since processors need not be in public packages. -->
        <!-- Also needs to include transitive dependencies. -->
    </target>

    <target name="up-to-date" depends="init">
        <uptodate targetfile="${cluster}/${module.jar}" property="is.jar.uptodate">
            <srcfiles dir="${src.dir}"/>
            <srcfiles dir="nbproject">
                <include name="project.xml"/>
                <include name="project.properties"/>
            </srcfiles>
            <srcfiles dir=".">
                <include name="manifest.mf"/>
            </srcfiles>
            <srcresources>
                <path refid="cp"/>
            </srcresources>
        </uptodate>
    </target>

    <target name="update" depends="basic-init">
        <fail
            message="Please specify URL of catalog to perform the update from via -Dautoupdate.catalog.url=..."
            unless="autoupdate.catalog.url"
        />
        <autoupdate
            updatecenter="${autoupdate.catalog.url}"
            todir="${cluster}"
        >
            <modules includes="${code.name.base}"/>
        </autoupdate>
    </target>

    <extension-point name="-pre-compile" depends="init,up-to-date"/>
    <extension-point name="-post-compile" depends="-pre-compile,-do-compile"/>
    <target name="compile" depends="-pre-compile,-do-compile,-post-compile"/>
    <target name="-do-compile" depends="init,up-to-date,-pre-compile" unless="is.jar.uptodate">
        <mkdir dir="${build.classes.dir}"/>
        <depend srcdir="${src.dir}" destdir="${build.classes.dir}" cache="${build.dir}/depcache">
            <classpath refid="cp"/>
        </depend>
        <property name="javac.fork" value="false"/>
        <nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8"
                  deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="${javac.source}" target="${javac.target}" includeantruntime="false"
                  fork="${javac.fork}"
        >
            <classpath refid="cp"/>
            <compilerarg line="${javac.compilerargs}"/>
            <processorpath refid="processor.cp"/>
        </nb-javac>
        <copy todir="${build.classes.dir}">
            <fileset dir="${src.dir}" excludes="${jar-excludes}"/>
        </copy>
        <processjsannotation classes="${build.classes.dir}" asm="${asm.jar}">
            <classpath refid="cp"/>
        </processjsannotation>
    </target>

    <target name="compile-single" depends="init">
        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
        <mkdir dir="${build.classes.dir}"/>
        <pathconvert pathsep="${line.separator}" property="javac.includes.binary">
            <path>
                <filelist dir="${build.classes.dir}" files="${javac.includes}"/>
            </path>
            <globmapper from="*.java" to="*.class"/>
        </pathconvert>
        <tempfile deleteonexit="true" property="javac.includesfile.binary"/>
        <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
        <delete>
            <files includesfile="${javac.includesfile.binary}"/>
        </delete>
        <delete>
            <fileset file="${javac.includesfile.binary}"/>
        </delete>
        <nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}"
                  debug="${build.compiler.debug}" deprecation="${build.compiler.deprecation}" encoding="UTF-8"
                  source="${javac.source}" target="${javac.target}" includes="${javac.includes}" optimize="${build.compiler.optimize}" includeantruntime="false">
            <classpath refid="cp"/>
            <compilerarg line="${javac.compilerargs}"/>
            <processorpath refid="processor.cp"/>
        </nb-javac>
        <processjsannotation classes="${build.classes.dir}" asm="${asm.jar}">
            <classpath refid="cp"/>
        </processjsannotation>
    </target>

    <target name="jar-prep" depends="init">
        <mkdir dir="${cluster}/${module.jar.dir}"/>
        <tstamp>
            <format property="buildnumber" pattern="yyMMdd" timezone="UTC"/>
        </tstamp>
    </target>

    <extension-point name="-pre-jar" depends="init,compile,jar-prep"/>
    <extension-point name="-post-jar" depends="-pre-jar,-do-jar"/>
    <target name="jar" depends="-pre-jar,-do-jar,-post-jar"/>
    <target name="-do-jar" depends="init,compile,jar-prep,-pre-jar" unless="is.jar.uptodate">
        <!-- This task adds some or all of: -Public-Packages, -Friends, Class-Path, -IDE-Dependencies, -Module-Dependencies, -Specification-Version, -Implementation-Version, -Build-Version, AutoUpdate-Show-In-Client -->
        <jarwithmoduleattributes jarfile="${cluster}/${module.jar}" compress="${build.package.compress}" index="${build.package.index}" manifest="${manifest.mf}" stamp="${cluster}/.lastModified">
            <fileset dir="${build.classes.dir}"/>
        </jarwithmoduleattributes>
    </target>

    <!-- Can insert extra stuff in here: -->
    <target name="netbeans-extra"/>

    <target name="-init-startlevel">
        <property name="module.startlevel" value=""/>
        <property name="check.module.startlevel" value="true"/>
    </target>

    <target name="module-xml-regular" if="is.regular" depends="-init-startlevel">
        <mkdir dir="${cluster}/config/Modules"/>
        <createmodulexml xmldir="${cluster}/config/Modules" startlevel="${module.startlevel}" strictcheck="${check.module.startlevel}">
            <enabled dir="${cluster}">
                <include name="${module.jar}"/>
            </enabled>
        </createmodulexml>
    </target>

    <target name="module-xml-autoload" if="is.autoload" depends="-init-startlevel">
        <mkdir dir="${cluster}/config/Modules"/>
        <createmodulexml xmldir="${cluster}/config/Modules" startlevel="${module.startlevel}" strictcheck="${check.module.startlevel}">
            <autoload dir="${cluster}">
                <include name="${module.jar}"/>
            </autoload>
        </createmodulexml>
    </target>

    <target name="module-xml-eager" if="is.eager" depends="-init-startlevel">
        <mkdir dir="${cluster}/config/Modules"/>
        <createmodulexml xmldir="${cluster}/config/Modules" startlevel="${module.startlevel}" strictcheck="${check.module.startlevel}">
            <eager dir="${cluster}">
                <include name="${module.jar}"/>
            </eager>
        </createmodulexml>
    </target>

    <target name="module-auto-deps" depends="basic-init" if="has.module.auto.deps">
        <mkdir dir="${cluster}/config/ModuleAutoDeps"/>
        <copy file="${module.auto.deps.xml}" tofile="${cluster}/config/ModuleAutoDeps/${code.name.base.dashes}.xml"/>
    </target>

    <extension-point name="-pre-release"/>
    <extension-point name="-post-release" depends="-pre-release,-do-release"/>
    <target name="release" depends="-pre-release,-do-release,-post-release"/>
    <target name="-do-release" depends="files-init,-pre-release" if="has.release.dir">
        <mkdir dir="${cluster}"/>
        <copy todir="${cluster}" overwrite="true">
            <fileset dir="${release.dir}">
                <patternset includes="${release.files}"/>
            </fileset>
        </copy>        
    </target>

    
    <target name="chmod-executables" depends="-init-executables">
        <chmod perm="a+x">
            <fileset refid="module.executable.files"/>
        </chmod>
    </target>

    <target name="verify-class-linkage" depends="jar,release">
<!--        <verifyclasslinkage jar="${cluster}/${module.jar}" failonerror="false" ignores="${module.jar.verifylinkageignores}" maxwarnings="10">
            <classpath refid="cp"/>
            <classpath path="${nbjdk.bootclasspath}"/>
        </verifyclasslinkage>-->
    </target>

    <target name="-verify-apichanges"/><!-- just for overriding -->

    <target name="-validate-layers" depends="init">
        <parsemanifest manifest="${manifest.mf}" attribute="OpenIDE-Module-Layer" property="layer.file"/>
        <!-- DTD from sources -->
        <available file="${nb_all}/platform/openide.filesystems/src/org/openide/filesystems/filesystem.dtd" type="file"
                   property="dtd.cp" value="${nb_all}/platform/openide.filesystems/src"/>
        <!-- DTD from platform -->
        <pathconvert property="dtd.cp">
            <pathfileset>
                <path refid="cluster.path.id"/>
                <filename name="core/org-openide-filesystems.jar"/>
            </pathfileset>
        </pathconvert>

        <xmlvalidate warn="no"> <!--  failonerror="false" -->
            <fileset file="${src.dir}/${layer.file}" erroronmissingdir="false"/>
            <xmlcatalog classpath="${dtd.cp}">
                <dtd publicId="-//NetBeans//DTD Filesystem 1.0//EN"
                     location="org/openide/filesystems/filesystem.dtd"/>
                <dtd publicId="-//NetBeans//DTD Filesystem 1.1//EN"
                     location="org/openide/filesystems/filesystem1_1.dtd"/>
                <dtd publicId="-//NetBeans//DTD Filesystem 1.2//EN"
                     location="org/openide/filesystems/filesystem1_2.dtd"/>
            </xmlcatalog>
        </xmlvalidate>
    </target>

    <target name="-netbeans" depends="init,jar,netbeans-extra,javahelp,module-auto-deps,release,module-xml-regular,
            module-xml-autoload,module-xml-eager,chmod-executables,verify-class-linkage,
            -validate-layers,-verify-apichanges"/> 
    
    <target name="netbeans" depends="-netbeans">
        <property name="module.files.toString" refid="module.files"/>
        <echo level="verbose">Basic matching module files: ${module.files.toString}</echo>
        <genlist outputfiledir="${cluster}" module="${module.jar}">
            <fileset dir="${cluster}">
                <patternset refid="module.files"/>
            </fileset>
        </genlist>
    </target>

    <target name="build" depends="netbeans,test-build"/>

    <target name="-jnlp-init">
        <fail unless="jnlp.dest.dir" >
            You have to provide value to jnlp.dest.dir property!
        </fail>
        <mkdir dir="${jnlp.dest.dir}" />
        <makeurl property="jnlp.codebase" file="${jnlp.dest.dir}"/>
        <property name="jnlp.signjar.alias" value="jnlp" />
        <property name="jnlp.signjar.keystore" location="${jnlp.dest.dir}/default.keystore" />
        <property name="jnlp.signjar.password" value="netbeans" />
        <property name="jnlp.permissions" value="&lt;security&gt;&lt;all-permissions/&gt;&lt;/security&gt;"/>
        <property name="jnlp.verify.excludes" value="" />
        <!-- Oddly, <available> as a task overrides existing properties, which is not what we want here. -->
        <condition property="jnlp.sign.jars" value="true">
            <available file="${jnlp.signjar.keystore}"/>
        </condition>
        <property name="jnlp.sign.jars" value="false"/>
        <property name="jnlp.indirect.jars" value="[NOTHING]"/>
        <property name="jnlp.indirect.files" value="[NOTHING]"/>
        <property name="jnlp.generate.versions" value="false"/>
    </target>

    <target name="jnlp" depends="init,netbeans,jnlp-master,-jnlp-init" description="Builds JNLP descriptor and signs JAR files" >
        <makejnlp
            dir="${jnlp.dest.dir}"
            alias="${jnlp.signjar.alias}"
            storepass="${jnlp.signjar.password}"
            keystore="${jnlp.signjar.keystore}"
            codebase="${jnlp.codebase}"
            verify="true"
            verifyexcludes="${jnlp.verify.excludes}"
            permissions="${jnlp.permissions}"
            signjars="${jnlp.sign.jars}"
            processjarversions="${jnlp.generate.versions}"
        >
            <modules dir="${cluster}" >
                <include name="${module.jar}" />
            </modules>
            <indirectjars dir="${cluster}" includes="${jnlp.indirect.jars}"/>
            <indirectfiles dir="${cluster}" includes="${jnlp.indirect.files}"/>
        </makejnlp>
    </target>

    <target name="jnlp-master" depends="init,netbeans" if="jnlp.master.dir" >
        <property name="jnlp.master.codebase" value="" />
        <makemasterjnlp
            dir="${jnlp.master.dir}"
            codebase="${jnlp.master.codebase}"
        >
            <modules dir="${cluster}" >
                <include name="${module.jar}" />
            </modules>
        </makemasterjnlp>
    </target>


    <target name="-nbm-prompt-for-storepass" if="keystore" unless="storepass">
        <input addproperty="storepass" message="Enter password for ${keystore}:">
            <handler type="secure"/>
        </input>
    </target>

    <target name="-init-executables">
        <property name="nbm.executable.files" value="[NOTHING]"/><!-- fallback -->
        <fileset dir="${cluster}" id="module.executable.files" includes="${nbm.executable.files}"/>
    </target>

    <target name="-init-extra.nbm.files" unless="extra.nbm.files.provided"> <!-- fallback -->
        <zipfileset dir="${cluster}" id="extra.nbm.files" includes="[NOTHING]"/>
    </target>

    <extension-point name="-pre-nbm" depends="init,netbeans,-nbm-prompt-for-storepass,-init-executables,-init-extra.nbm.files"/>
    <extension-point name="-post-nbm" depends="-pre-nbm,-do-nbm"/>
    <target name="nbm" depends="-pre-nbm,-do-nbm,-post-nbm"/>
    <target name="-do-nbm" depends="init,netbeans,-nbm-prompt-for-storepass,-init-executables,-init-extra.nbm.files,-pre-nbm" description="Build NBM archive.">
        <mkdir dir="${build.dir}"/>
        <property name="nbm.target.cluster" value=""/> <!-- fallback -->
        <property name="license.file.override" value="${license.file}"/>
        <property name="use.pack200" value="false"/>
        <property name="pack200.excludes" value=""/>
        <property name="nbm.locales" value="${locales}"/>
        <makenbm file="${build.dir}/${nbm}"
                 productdir="${cluster}"
                 module="${module.jar}"
                 homepage="${nbm.homepage}"
                 distribution="${nbm.distribution}"
                 needsrestart="${nbm.needs.restart}"
                 global="${nbm.is.global}"
                 preferredupdate="${nbm.is.preferredupdate}"
                 usepack200="${use.pack200}"
                 pack200excludes="${pack200.excludes}"
                 alwayscreatenbm="${nbm.always.create}"
                 targetcluster="${nbm.target.cluster}"
                 releasedate="${nbm.release.date}"
                 moduleauthor="${nbm.module.author}"
                 locales="${nbm.locales}"
                 >
            <license file="${license.file.override}"/>
            <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}" tsaurl="${tsaurl}" tsacert="${tsacert}"/>
            <updaterjar>
                <pathfileset>
                    <path refid="cluster.path.id"/>
                    <filename name="modules/ext/updater.jar"/>
                </pathfileset>
            </updaterjar>
            <executables refid="module.executable.files"/>
            <extranbmfiles refid="extra.nbm.files"/>
        </makenbm>
    </target>

    <target name="nbm-nosignature" depends="init,netbeans,-nbm-prompt-for-storepass,-init-executables" description="Build NBM archive.">
        <mkdir dir="${build.dir}"/>
        <property name="nbm.target.cluster" value=""/> <!-- fallback -->
        <property name="license.file.override" value="${license.file}"/>
        <property name="use.pack200" value="true"/>
        <property name="pack200.excludes" value=""/>
        <property name="nbm.locales" value="${locales}"/>
        <makenbm file="${build.dir}/${nbm}"
                 productdir="${cluster}"
                 module="${module.jar}"
                 homepage="${nbm.homepage}"
                 distribution="${nbm.distribution}"
                 needsrestart="${nbm.needs.restart}"
                 global="${nbm.is.global}"
                 preferredupdate="${nbm.is.preferredupdate}"
                 usepack200="${use.pack200}"
                 pack200excludes="${pack200.excludes}"
                 targetcluster="${nbm.target.cluster}"
                 releasedate="${nbm.release.date}"
                 moduleauthor="${nbm.module.author}"
                 locales="${nbm.locales}"
                 >
            <license file="${license.file.override}"/>
            <updaterjar>
                <pathfileset>
                    <path refid="cluster.path.id"/>
                    <filename name="modules/ext/updater.jar"/>
                </pathfileset>
            </updaterjar>
            <executables refid="module.executable.files"/>
        </makenbm>
    </target>

    <target name="test-preinit" depends="init"/>
    <target name="test-init" depends="init,test-preinit,test-lib-init">
        <property name="test.timeout" value="600000"/> <!-- 10min per test -->
        <property name="test.run.args" value="-ea"/>
        <property name="test.filter.trace" value="true"/>
        <condition property="test.bootclasspath.prepend.args" value="-Xbootclasspath/p:${run.bootclasspath.prepend}">
            <isset property="run.bootclasspath.prepend"/>
        </condition>
        <property name="test.bootclasspath.prepend.args" value="-Dno.netbeans.bootclasspath.prepend.needed=true"/>
        <macrodef name="test-init">
            <attribute name="test.type"/>
            <sequential>
                <property name="test.@{test.type}.dir" location="test/@{test.type}"/>
                <property name="test.@{test.type}.src.dir" location="${test.@{test.type}.dir}/src"/>
                <property name="test.@{test.type}.data.dir" location="${test.@{test.type}.dir}/data"/>
                <property name="build.test.@{test.type}.dir" location="${build.dir}/test/@{test.type}"/>
                <property name="build.test.@{test.type}.classes.dir" location="${build.test.@{test.type}.dir}/classes"/>
                <property name="build.test.@{test.type}.results.dir" location="${build.test.@{test.type}.dir}/results"/>
                <property name="build.test.@{test.type}.work.dir" location="${build.test.@{test.type}.dir}/work"/>
                <property name="test-@{test.type}-sys-prop.cluster.path.final" value="${cluster.path.final}:${cluster}"/> <!-- #153178, 176019 -->
                <property name="test.@{test.type}.cp.extra" value=""/>
                <path id="test.@{test.type}.cp">
                    <!-- Cannot use <path refid="cp"/> since that uses ${module.classpath} and we want ${module.run.classpath}: -->
                    <pathelement path="${test.@{test.type}.compile.cp}"/>
                    <pathelement path="${cp.extra}"/>
                    <pathelement location="${cluster}/${module.jar}"/>
                    <path refid="test.unit.lib.cp"/>
                    <!-- for compatibility with property based classpath-->
                    <pathelement path="${module.run.classpath}"/>
                    <pathelement path="${test.@{test.type}.cp.extra}"/>
                </path>
                <path id="test.@{test.type}.run.cp">
                    <pathelement path="${build.test.@{test.type}.classes.dir}"/>
                    <!-- Cannot use <path refid="cp"/> since that uses ${module.classpath} and we want ${module.run.classpath}: -->
                    <pathelement path="${test.@{test.type}.runtime.cp}"/>
                    <pathelement path="${cp.extra}"/>
                    <pathelement location="${cluster}/${module.jar}"/>
                    <path refid="test.unit.lib.cp"/>
                    <!-- for compatibility with property based classpath-->
                    <pathelement path="${module.run.classpath}"/>
                    <pathelement path="${test.@{test.type}.run.cp.extra}"/>
                    <pathelement path="${test.@{test.type}.cp.extra}"/>
                    <pathelement path="${test.extra.nb.javac.deps}"/>
                </path>
                <!-- path reference used in both compiler and executor -->
                <propertyset id="test.@{test.type}.properties">
                    <propertyset>
                        <propertyref prefix="test-@{test.type}-sys-prop."/>
                        <mapper type="glob" from="test-@{test.type}-sys-prop.*" to="*"/>
                    </propertyset>
                    <propertyset>
                        <propertyref name="build.test.@{test.type}.work.dir"/>
                        <mapper type="glob" from="build.test.@{test.type}.work.dir" to="nbjunit.workdir"/>
                    </propertyset>
                    <propertyset>
                        <propertyref name="test.timeout"/>
                        <mapper type="glob" from="test.timeout" to="nbjunit.hard.timeout"/>
                    </propertyset>
                    </propertyset>
                    <condition property="exists.test.@{test.type}.src.dir">
                        <and>
                            <available file="${test.@{test.type}.src.dir}" type="dir"/>
                            <not>
                                <istrue value="${disable.@{test.type}.tests}"/>
                            </not>
                        </and>
                    </condition>

            </sequential>
        </macrodef>
        <test-init test.type="unit"/>
        <test-init test.type="qa-functional"/>
    </target>

    <target name="test-build" depends="netbeans,test-dep-build,do-test-build" description="Compile and package all tests."/>

    <macrodef name="test-dep-build">
        <attribute name="test.type"/>
        <sequential>
            <sortsuitemodules unsortedmodules="${test.@{test.type}.testdep}" sortedmodulesproperty="mods.sorted" sorttests="true"/>
            <subant buildpath="${mods.sorted}" target="do-test-build" />
        </sequential>
    </macrodef>
    <target name="test-unit-dep-build" if="test.unit.testdep">
        <test-dep-build test.type="unit"/>
    </target>
    <target name="test-qa-functional-dep-build" if="test.qa-functional.testdep">
        <test-dep-build test.type="qa-functional"/>
    </target>
    <target name="test-dep-build" depends="test-unit-dep-build,test-qa-functional-dep-build"/>

    <macrodef name="do-test-build">
        <attribute name="test.type"/>
        <sequential>
            <fail >
                Missing test dependency
                Runtime classpath: ${test.@{test.type}.runtime.cp}
                Compile classpath: ${test.@{test.type}.compile.cp}
                <condition>
                    <or>
                        <contains string="${test.@{test.type}.runtime.cp}" substring="-missing-Module-Entries-:" />
                        <contains string="${test.@{test.type}.compile.cp}" substring="-missing-Module-Entries-:" />
                    </or>
                </condition>
            </fail>
            <mkdir dir="${build.test.@{test.type}.classes.dir}"/>
            <depend srcdir="${test.@{test.type}.src.dir}" destdir="${build.test.@{test.type}.classes.dir}" cache="${build.test.@{test.type}.dir}/depcache">
                <classpath refid="test.@{test.type}.cp"/>
            </depend>
            <property name="test.javac.excludes" value=""/> <!-- # 113770 -->
            <nb-javac srcdir="${test.@{test.type}.src.dir}" destdir="${build.test.@{test.type}.classes.dir}" excludes="${test.javac.excludes}"
                      debug="true" deprecation="${build.compiler.deprecation}" encoding="UTF-8"
                      source="${javac.source}" target="${javac.target}" optimize="${build.compiler.optimize}" includeantruntime="false">
                <classpath refid="test.@{test.type}.cp"/>
                <compilerarg line="${javac.compilerargs}"/>
                <processorpath refid="test.@{test.type}.cp"/>
            </nb-javac>
            <processjsannotation classes="${build.test.@{test.type}.classes.dir}" asm="${asm.jar}">
                <classpath refid="test.@{test.type}.cp"/>
            </processjsannotation>
            <copy todir="${build.test.@{test.type}.classes.dir}">
                <fileset dir="${test.@{test.type}.src.dir}">
                    <exclude name="**/*.java"/>
                </fileset>
            </copy>
            <delete dir="${build.test.@{test.type}.dir}/data"/>
            <copy todir="${build.test.@{test.type}.dir}">
                <fileset dir="${test.@{test.type}.dir}">
                    <include name="data/**"/>
                </fileset>
            </copy>
        </sequential>
    </macrodef>
    <target name="do-unit-test-build" depends="init,test-init" if="exists.test.unit.src.dir">
        <do-test-build test.type="unit"/>
    </target>
    <target name="do-qa-functional-test-build" depends="init,test-init" if="exists.test.qa-functional.src.dir">
        <do-test-build test.type="qa-functional"/>
    </target>
    <target name="do-test-build" depends="do-unit-test-build,do-qa-functional-test-build"/>

    <target name="compile-test-single" depends="init,test-init,jar">
        <macrodef name="compile-test-single">
            <attribute name="test.type"/>
            <sequential>
                <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
                <mkdir dir="${build.test.@{test.type}.classes.dir}"/>
                <!-- XXX consider forcing deprecation=true -->
                <!-- XXX consider deleting the .class file first to force a rebuild -->
                <depend srcdir="${test.@{test.type}.src.dir}" destdir="${build.test.@{test.type}.classes.dir}" cache="${build.test.@{test.type}.dir}/depcache">
                    <classpath refid="test.@{test.type}.cp"/>
                </depend>
                <nb-javac srcdir="${test.@{test.type}.src.dir}" destdir="${build.test.@{test.type}.classes.dir}"
                          debug="true" deprecation="${build.compiler.deprecation}" encoding="UTF-8"
                          source="${javac.source}" target="${javac.target}" includeantruntime="false" optimize="${build.compiler.optimize}" includes="${javac.includes}">
                    <classpath refid="test.@{test.type}.cp"/>
                    <compilerarg line="${javac.compilerargs}"/>
                    <processorpath refid="test.@{test.type}.cp"/>
                </nb-javac>
                <processjsannotation classes="${build.test.@{test.type}.classes.dir}" asm="${asm.jar}">
                    <classpath refid="test.@{test.type}.cp"/>
                </processjsannotation>
                <copy todir="${build.test.@{test.type}.classes.dir}">
                    <fileset dir="${test.@{test.type}.src.dir}">
                        <exclude name="**/*.java"/>
                    </fileset>
                </copy>
                <copy todir="${build.test.@{test.type}.dir}">
                    <fileset dir="${test.@{test.type}.dir}">
                        <include name="data/**"/>
                    </fileset>
                </copy>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <compile-test-single test.type="${test.type}"/>
    </target>

    <macrodef name="metaproperty">
        <attribute name="name"/>
        <attribute name="value"/>
        <sequential>
            <property name="@{name}" value="${@{value}}"/>
        </sequential>
    </macrodef>
    <macrodef name="test">
        <attribute name="test.type"/>
        <attribute name="disable.apple.ui" default="false"/>
        <sequential>
            <property name="test.config" value="default"/>
            <property name="test.config.default.includes" value="**/*Test.class"/>
            <property name="test.config.${test.config}.includes" value="NOTHING"/>
            <metaproperty name="test.includes" value="test.config.${test.config}.includes"/>
            <property name="test.config.${test.config}.excludes" value=""/>
            <metaproperty name="test.excludes" value="test.config.${test.config}.excludes"/>
            <mkdir dir="${build.test.@{test.type}.results.dir}"/>
            <condition property="test.runner" value ="testng" else="junit">
                <available classname="org.testng.annotations.Test" classpath="${test.@{test.type}.runtime.cp}"/>
            </condition>
            <antcall target="-do-${test.runner}">
                <param name="run.test.type" value="@{test.type}"/>
                <param name="disable.apple.ui" value="@{disable.apple.ui}"/>
            </antcall>
        </sequential>
    </macrodef>
    <target name="test-unit" depends="init,test-init,test-build" if="exists.test.unit.src.dir">
        <test test.type="unit" disable.apple.ui="true"/>
    </target>
    <target name="test-qa-functional" depends="init,test-init,test-build" if="exists.test.qa-functional.src.dir">
        <test test.type="qa-functional"/>
    </target>

    <target name="-do-junit" depends="test-init">
        <macrodef name="junit-impl">
            <attribute name="test.type"/>
            <attribute name="disable.apple.ui" default="false"/>
            <sequential>
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}" jvm="${test.nbjdk.java}">
                    <batchtest todir="${build.test.@{test.type}.results.dir}">
                        <fileset dir="${build.test.@{test.type}.classes.dir}" includes="${test.includes}" excludes="${test.excludes}"/>
                    </batchtest>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${test.run.args}"/>
                    <!--needed to have tests NOT to steal focus when running, works in latest apple jdk update only.-->
                    <sysproperty key="apple.awt.UIElement" value="@{disable.apple.ui}"/>
                    <formatter type="brief" usefile="false"/>
                    <formatter type="xml"/>
                </junit>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <junit-impl test.type="${run.test.type}" disable.apple.ui="${disable.apple.ui}"/>
    </target>

    <target name="-do-testng" depends="test-init">
        <macrodef name="testng-impl">
            <attribute name="test.type"/>
            <attribute name="disable.apple.ui" default="false"/>
            <sequential>
                <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="test.@{test.type}.run.cp"/>
                <testng mode="mixed"
                        failureProperty="tests.failed"
                        outputdir="${build.test.@{test.type}.results.dir}"
                        workingDir="${build.test.@{test.type}.results.dir}"
                        suitename="${code.name.base}"
                        listener="org.testng.reporters.VerboseReporter"
                        jvm="${test.nbjdk.java}"
                >
                    <classfileset dir="${build.test.@{test.type}.classes.dir}" excludes="${test.excludes}" includes="${test.includes}"/>
                    <propertyset refid="test.@{test.type}.properties"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${test.run.args}"/>
                    <!-- needed to have tests NOT to steal focus when running, works in latest apple jdk update only.-->
                    <sysproperty key="apple.awt.UIElement" value="@{disable.apple.ui}"/>
                </testng>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <testng-impl test.type="${run.test.type}" disable.apple.ui="${disable.apple.ui}"/>
    </target>

    <target name="test-generate-html" depends="-build-dir-init">
        <subant target="-test-browse-html" genericantfile="${ant.file}" inheritall="true">
            <dirset dir="${build.dir}/test" includes="*/results"/>
        </subant>
    </target>

    <target name="-do-test-generate-html">
        <junitreport todir=".">
            <fileset dir=".">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="html"/>
        </junitreport>
        <makeurl file="${basedir}/html/index.html" property="test.report.url"/>
        <echo>

            Report URL: ${test.report.url}
        </echo>
    </target>

    <target name="-test-browse-html" if="netbeans.home" depends="-do-test-generate-html">
        <nbbrowse file="html/index.html"/>
    </target>
    <target name="test" depends="test-unit,test-qa-functional"/>

    <target name="test-single" depends="init,test-init,test-build">
        <macrodef name="test-single">
            <attribute name="test.type"/>
            <sequential>
                <fail unless="test.includes">Must set test.includes</fail>
                <property name="run.jvmargs.ide" value=""/> 
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
                <condition property="test.runner" value ="testng" else="junit">
                    <available classname="org.testng.annotations.Test" classpath="${test.@{test.type}.runtime.cp}"/>
                </condition>
                <condition property="is.test.suite" value ="-suite" else="">
                    <contains string="${test.includes}" substring=".xml"/>
                </condition>
                <antcall target="-do-${test.runner}-single${is.test.suite}">
                    <param name="test.type" value="@{test.type}"/>
                </antcall>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <property name="run.args.ide" value=""/>
        
        <test-single test.type="${test.type}"/>
    </target>

    <target name="-do-junit-single" depends="test-init">
        <macrodef name="junit-impl">
            <attribute name="test.type"/>
            <sequential>
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}" jvm="${test.nbjdk.java}">
                    <batchtest todir="${build.test.@{test.type}.results.dir}">
                        <fileset dir="${test.@{test.type}.src.dir}" includes="${test.includes}"/>
                    </batchtest>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <jvmarg line="${test.run.args}"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${run.args.ide}"/>
                    <jvmarg line="${run.jvmargs.ide}"/>
                    <formatter type="brief" usefile="false"/>
                    <formatter type="xml"/>
                </junit>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <junit-impl test.type="${test.type}" />
    </target>

    <target name="-do-testng-single" depends="test-init">
        <macrodef name="testng-impl">
            <attribute name="test.type"/>
            <sequential>
                <fileset id="testng.test" dir="${test.@{test.type}.src.dir}" includes="${test.includes}"/>
                <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="test.@{test.type}.run.cp"/>
                <testng  mode="mixed"
                         classfilesetref="testng.test"
                         failureProperty="tests.failed"
                         outputdir="${build.test.@{test.type}.results.dir}"
                         workingDir="${build.test.@{test.type}.results.dir}"
                         suitename="${code.name.base}"
                         listener="org.testng.reporters.VerboseReporter"
                         jvm="${test.nbjdk.java}"
                >
                    <propertyset refid="test.@{test.type}.properties"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${test.run.args}"/>
                    <!-- needed to have tests NOT to steal focus when running, works in latest apple jdk update only.-->
                    <sysproperty key="apple.awt.UIElement" value="@{disable.apple.ui}"/>
                </testng>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <testng-impl test.type="${test.type}"/>
    </target>

    <target name="-do-testng-single-suite" depends="test-init">
        <macrodef name="testng-impl">
            <attribute name="test.type"/>
            <sequential>
                <fileset id="testng.test" dir="${test.@{test.type}.src.dir}" includes="${test.includes}"/>
                <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="test.@{test.type}.run.cp"/>
                <testng  mode="mixed"
                         xmlfilesetref="testng.test"
                         failureProperty="tests.failed"
                         outputdir="${build.test.@{test.type}.results.dir}"
                         workingDir="${build.test.@{test.type}.results.dir}"
                         suitename="${code.name.base}"
                         listener="org.testng.reporters.VerboseReporter"
                         jvm="${test.nbjdk.java}"
                >
                    <propertyset refid="test.@{test.type}.properties"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${test.run.args}"/>
                    <!-- needed to have tests NOT to steal focus when running, works in latest apple jdk update only.-->
                    <sysproperty key="apple.awt.UIElement" value="@{disable.apple.ui}"/>
                </testng>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <testng-impl test.type="${test.type}"/>
    </target>

    <target name="do-debug-test-single" depends="test-init">
        <macrodef name="do-debug-test-single">
            <attribute name="test.type"/>
            <sequential>
                <fail unless="test.class">Must set test.class</fail>
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
                <condition property="test.runner" value ="testng" else="junit">
                    <available classname="org.testng.annotations.Test" classpath="${test.@{test.type}.runtime.cp}"/>
                </condition>
                <condition property="is.test.suite" value ="-suite" else="">
                    <matches pattern="([a-zA-Z_$][a-zA-Z\d_$]*\.)*xml$" string="${test.class}"/>
                </condition>
                <antcall target="-do-${test.runner}-debug-single${is.test.suite}">
                    <param name="test.type" value="@{test.type}"/>
                </antcall>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <do-debug-test-single test.type="${test.type}"/>
    </target>

    <target name="-do-junit-debug-single" depends="test-init">
        <macrodef name="junit-impl">
            <attribute name="test.type"/>
            <sequential>
                <property name="test.report.file" location="${build.test.@{test.type}.results.dir}/TEST-${test.class}.xml"/>
                <delete file="${test.report.file}"/>
                <touch file="${test.report.file}" verbose="false"/>   <!-- must exist, otherwise the XML formatter would fail -->
                <condition property="test.methods.line" value="methods=${test.methods}" else="">
                    <isset property="test.methods"/>
                </condition>
                <java fork="true" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" jvm="${test.nbjdk.java}">
                    <jvmarg value="-agentlib:jdwp=transport=dt_socket,address=${jpda.address}"/>
                    <jvmarg line="${test.run.args}"/>
                    <classpath>
                        <path refid="test.@{test.type}.run.cp"/>
                        <fileset dir="${ant.home}" includes="patches/*.jar"/>
                        <pathelement location="${ant.home}/lib/ant.jar"/>
                        <pathelement location="${ant.home}/lib/ant-junit.jar"/>
                        <pathelement location="${ant.home}/lib/ant-junit4.jar"/>
                    </classpath>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <arg value="${test.class}"/>
                    <arg value="showoutput=true"/>
                    <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
                    <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
                    <arg line="${test.methods.line}"/>
                </java>
            </sequential>
        </macrodef>
        <junit-impl test.type="${test.type}" />
    </target>

    <target name="-do-testng-debug-single" depends="test-init">
        <macrodef name="testng-impl">
            <attribute name="test.type"/>
            <sequential>
                <condition property="testng.args.line" value="-methods ${test.class}.${test.methods}" else="-testclass ${test.class}">
                    <isset property="test.methods"/>
                </condition>
                <!-- XXX: Consider debugging using testng task itself      -->
                <!-- TestNG is running in forkMode="once"                  -->
                <!-- therefore results while debugging single class/method -->
                <!-- can be different from running all tests at once       -->
                <java classname="org.testng.TestNG" fork="true" jvm="${test.nbjdk.java}">
                    <jvmarg value="-agentlib:jdwp=transport=dt_socket,address=${jpda.address}"/>
                    <jvmarg line="${test.run.args}"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <jvmarg value="-ea"/>
                    <arg line="-mixed"/>
                    <arg line="-d ${build.test.@{test.type}.results.dir}"/>
                    <arg line="-listener org.testng.reporters.VerboseReporter"/>
                    <arg line="-suitename ${code.name.base}"/>
                    <arg line="-testname ${test.class}"/>
                    <arg line="${testng.args.line}"/>
                </java>
                <!--
                <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="test.@{test.type}.run.cp"/>
                <testng mode="mixed" methods="${testng.methods}" failureProperty="tests.failed" outputdir="${build.test.@{test.type}.results.dir}" workingDir="${build.test.@{test.type}.results.dir}">
                    <classfileset dir="${build.test.@{test.type}.classes.dir}" excludes="${test.excludes}" includes="**/*Test.class"/>
                    <propertyset refid="test.@{test.type}.properties"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${test.run.args}"/>
                    <jvmarg value="-agentlib:jdwp=transport=dt_socket,address=${jpda.address}"/>
                </testng>
                -->
            </sequential>
        </macrodef>
        <testng-impl test.type="${test.type}"/>
    </target>

    <target name="-do-testng-debug-single-suite" depends="test-init">
        <macrodef name="testng-impl">
            <attribute name="test.type"/>
            <sequential>
                <fileset id="testng.test" dir="${test.@{test.type}.src.dir}" includes="${test.class}"/>
                <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="test.@{test.type}.run.cp"/>
                <testng  mode="mixed"
                         xmlfilesetref="testng.test"
                         failureProperty="tests.failed"
                         outputdir="${build.test.@{test.type}.results.dir}"
                         workingDir="${build.test.@{test.type}.results.dir}"
                         suitename="${code.name.base}"
                         listener="org.testng.reporters.VerboseReporter"
                         jvm="${test.nbjdk.java}"
                >
                    <propertyset refid="test.@{test.type}.properties"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${test.run.args}"/>
                    <jvmarg value="-agentlib:jdwp=transport=dt_socket,address=${jpda.address}"/>
                    <!-- needed to have tests NOT to steal focus when running, works in latest apple jdk update only.-->
                    <sysproperty key="apple.awt.UIElement" value="@{disable.apple.ui}"/>
                </testng>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <testng-impl test.type="${test.type}"/>
    </target>

    <target name="debug-test-single" depends="init,test-init,test-build,do-debug-test-single"/>

    <target name="debug-test-single-nb" depends="init,test-init,test-build,-jdk-presetdef-nbjpdastart" if="netbeans.home">
        <macrodef name="debug-test-single-nb">
            <attribute name="test.type"/>
            <sequential>
                <fail unless="test.class">Must set test.class</fail>
                <nbjpdastart transport="dt_socket" addressproperty="jpda.address" name="${test.class}">
                    <classpath>
                        <path refid="test.@{test.type}.run.cp"/>
                        <!-- Permit extra sources to be searched even if they are not in the actual CP. -->
                        <!-- Used e.g. from ant/test/unit since some tests use dynamic loading: -->
                        <pathelement path="${test.@{test.type}.debug.cp.extra}"/>
                    </classpath>
                </nbjpdastart>
                <antcall target="do-debug-test-single"/>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <debug-test-single-nb test.type="${test.type}"/>
    </target>
    
    <target name="test-method" depends="init,test-init,test-build">
        <macrodef name="test-method">
            <attribute name="test.type"/>
            <sequential>
                <fail unless="test.class">Must set test.class</fail>
                <fail unless="test.methods">Must set test.methods</fail>
                <property name="run.jvmargs.ide" value=""/>
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
                <condition property="test.runner" value ="testng" else="junit">
                    <available classname="org.testng.annotations.Test" classpath="${test.@{test.type}.runtime.cp}"/>
                </condition>
                <antcall target="-do-${test.runner}-testmethod">
                    <param name="test.type" value="@{test.type}"/>
                </antcall>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <test-method test.type="${test.type}"/>
    </target>
    
    <target name="-do-junit-testmethod" depends="test-init">
        <macrodef name="junit-impl">
            <attribute name="test.type"/>
            <sequential>
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}" jvm="${test.nbjdk.java}">
                    <test name="${test.class}" methods="${test.methods}" todir="${build.test.@{test.type}.results.dir}"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <jvmarg line="${test.run.args}"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${run.jvmargs.ide}"/>
                    <formatter type="brief" usefile="false"/>
                    <formatter type="xml"/>
                </junit>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <junit-impl test.type="${test.type}" />
    </target>

    <target name="-do-testng-testmethod" depends="test-init">
        <macrodef name="testng-impl">
            <attribute name="test.type"/>
            <sequential>
                <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="test.@{test.type}.run.cp"/>
                <testng mode="mixed"
                        methods="${test.class}.${test.methods}"
                        failureProperty="tests.failed"
                        outputdir="${build.test.@{test.type}.results.dir}"
                        workingDir="${build.test.@{test.type}.results.dir}"
                        suitename="${code.name.base}"
                        listener="org.testng.reporters.VerboseReporter"
                        jvm="${test.nbjdk.java}"
                >
                    <propertyset refid="test.@{test.type}.properties"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <jvmarg line="${test.run.args}"/>
                    <!-- needed to have tests NOT to steal focus when running, works in latest apple jdk update only.-->
                    <sysproperty key="apple.awt.UIElement" value="@{disable.apple.ui}"/>
                </testng>
                <fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <testng-impl test.type="${test.type}"/>
    </target>

    <target name="run-test-main"  depends="init,test-init,test-build">
        <macrodef name="tjava">
            <attribute name="test.type"/>
            <element name="customize" optional="true"/>
            <sequential>
                <fail unless="main.class">Must set main.class.</fail>
                <property name="run.jvmargs.ide" value=""/>
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
                <java classname="${main.class}" dir="${build.test.@{test.type}.results.dir}" fork="true">
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <jvmarg line="${test.run.args}"/>
                    <jvmarg line="${run.args.ide}"/>
                    <jvmarg line="${run.jvmargs.ide}"/>
                    <customize/>
                </java>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/> <!-- compatibility -->
        <property name="run.args.ide" value=""/> <!-- default -->
        <tjava test.type="${test.type}"/>
    </target>

    <target name="do-debug-test-main" depends="test-init">
        <macrodef name="do-debug-test-main">
            <attribute name="test.type"/>
            <element name="customize" optional="true"/>
            <sequential>
                <fail unless="main.class">Must set main.class.</fail>
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
                <java fork="true" classname="${main.class}">
                    <jvmarg value="-agentlib:jdwp=transport=dt_socket,address=${jpda.address}"/>
                    <jvmarg line="${test.run.args}"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <customize/>
                </java>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <do-debug-test-main test.type="${test.type}"/>
    </target>

    <target name="debug-test-main-nb" depends="init,test-init,test-build,-jdk-presetdef-nbjpdastart" if="netbeans.home">
        <macrodef name="debug-test-main-nb">
            <attribute name="test.type"/>
            <sequential>
                <fail unless="main.class">Must set main.class</fail>
                <nbjpdastart transport="dt_socket" addressproperty="jpda.address" name="${main.class}">
                    <classpath>
                        <path refid="test.@{test.type}.run.cp"/>
                        <!-- Permit extra sources to be searched even if they are not in the actual CP. -->
                        <!-- Used e.g. from ant/test/unit since some tests use dynamic loading: -->
                        <pathelement path="${test.@{test.type}.debug.cp.extra}"/>
                    </classpath>
                </nbjpdastart>
                <antcall target="do-debug-test-main"/>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <debug-test-main-nb test.type="${test.type}"/>
    </target>
    
    <target name="-pre-debug-fix" depends="init">
        <fail unless="fix.class">Must set fix.class to e.g. org/netbeans/modules/foo/Bar</fail>
        <property name="javac.includes" value="${fix.class}.java"/>
    </target>
    <target name="debug-fix-nb" if="netbeans.home" depends="init,-pre-debug-fix,compile-single">
        <nbjpdareload>
            <fileset includes="${fix.class}*.class" dir="${build.classes.dir}"/>
        </nbjpdareload>
    </target>
    <target name="debug-fix-test-nb" if="netbeans.home" depends="init,-pre-debug-fix,compile-test-single">
        <macrodef name="debug-fix-test-nb">
            <attribute name="test.type"/>
            <sequential>
                <nbjpdareload>
                    <fileset includes="${fix.class}*.class" dir="${build.test.@{test.type}.classes.dir}"/>
                </nbjpdareload>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <debug-fix-test-nb test.type="${test.type}"/>
    </target>

    <target name="-profile-check" if="netbeans.home">
        <condition property="profiler.configured">
            <or>
                <contains string="${run.args.ide}" substring="-agentpath:" casesensitive="true"/>
                <contains string="${run.args.ide}" substring="-javaagent:" casesensitive="true"/>
            </or>
        </condition>
    </target>

    <target name="-profile-test-single-nb-pre72" depends="init,test-init,test-build,-jdk-presetdef-nbprofiledirect" if="profiler.info.jvmargs.agent">
        <macrodef name="profile-test-single-nb">
            <attribute name="test.type"/>
            <sequential>
                <fail unless="profile.class">Must set profile.class</fail>
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
                <nbprofiledirect
                    jvmargsproperty="profiler.jvmargs"
                >
                    <classpath refid="test.@{test.type}.run.cp"/>
                </nbprofiledirect>
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" jvm="${test.nbjdk.java}">
                    <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
                    <jvmarg value="${profiler.info.jvmargs.agent}"/>
                    <jvmarg line="${profiler.info.jvmargs}"/>
                    <test name="${profile.class}" todir="${build.test.@{test.type}.results.dir}"/>
                    <classpath refid="test.@{test.type}.run.cp"/>
                    <jvmarg value="${test.bootclasspath.prepend.args}"/>
                    <syspropertyset refid="test.@{test.type}.properties"/>
                    <jvmarg line="${test.run.args}"/>
                    <formatter type="brief" usefile="false"/>
                    <formatter type="xml"/>
                </junit>
                <fail if="tests.failed">Some tests failed; see details above.</fail>
            </sequential>
        </macrodef>
        <property name="test.type" value="unit"/>
        <profile-test-single-nb test.type="${test.type}"/>
    </target>

    <target name="profile-test-single-nb" depends="-profile-check,init,test-init,test-build,-profile-test-single-nb-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent">        
        <startprofiler/>
        <antcall target="test-single"/>
    </target>
    
    <target name="profile-test-main-nb" depends="-profile-check,init,test-init,test-build" if="profiler.configured" unless="profiler.info.jvmargs.agent">
        <startprofiler/>
        <antcall target="run-test-main"/>
    </target>

    <target name="-javadoc-init" depends="init">
        <!-- #71884: default Javadoc title and header -->
        <loadproperties srcFile="${manifest.mf}" prefix="mf.">
            <filterchain>
                <replaceregex pattern="[\n\r]+ ([^ ][^\n\r]*)"
                            replace="\1"
                            flags="g"
                            byline="false"/>
            </filterchain>
        </loadproperties>
        <property file="${src.dir}/${mf.OpenIDE-Module-Localizing-Bundle}" prefix="bundle."/>
        <condition property="javadoc.title" value="${bundle.OpenIDE-Module-Name}">
            <isset property="bundle.OpenIDE-Module-Name"/>
        </condition>
        <property name="javadoc.title" value="${code.name.base.dashes}"/> <!-- fallback -->
        <condition property="mf.OpenIDE-Module-Specification-Version" value="${spec.version.base}"> <!-- fallback -->
            <isset property="spec.version.base"/>
        </condition>
        <property name="mf.OpenIDE-Module" value="${code.name.base.dashes}"/> <!-- fallback -->
        <property name="mf.OpenIDE-Module-Implementation-Version" value=""/> <!-- fallback -->
        <property name="javadoc.header" value="${mf.OpenIDE-Module} ${mf.OpenIDE-Module-Specification-Version} ${mf.OpenIDE-Module-Implementation-Version}"/>
    </target>

    <target name="arch" depends="init" description="Process an arch.xml, creating it if it does not yet exist.">
        <fail unless="javadoc.arch">You must define e.g. javadoc.arch=$${basedir}/arch.xml in project.properties</fail>
        <mkdir dir="${build.dir}"/>
        <property name="arch.output.html" location="${build.dir}/arch.html"/>
        <property name="arch.generate" value="true"/>
        <arch answers="${javadoc.arch}" output="${arch.output.html}"
              project="nbproject/project.xml"
        />
    </target>

    <target name="-arch-nb-check"> <!-- #67438: might not yet exist, if arch file newly generated as skeleton -->
        <condition property="-arch-nb-run">
            <and>
                <isset property="netbeans.home"/>
                <available file="${arch.output.html}"/>
            </and>
        </condition>
    </target>
    <target name="arch-nb" depends="init,arch,-arch-nb-check" if="-arch-nb-run" description="Process an arch.xml, creating it if it does not yet exist, and display the result.">
        <nbbrowse file="${arch.output.html}"/>
    </target>

    <target name="-testuserdir-delete-init" depends="files-init">
        <property name="test.user.dir" location="${build.dir}/testuserdir"/>
        <property name="test.user.dir.lock" location="${test.user.dir}/lock"/>
        <condition property="app.running">
            <islocked file="${test.user.dir.lock}"/>
        </condition> 
    </target>
    <target name="-testuserdir-delete-ok" depends="-testuserdir-delete-init" unless="app.running">
        <delete dir="${test.user.dir}"/>
    </target>
    <target name="-testuserdir-delete-fail" depends="-testuserdir-delete-init" if="app.running">
        <!-- #66799: best to warn about this condition... -->
        <fail>Will not delete ${test.user.dir} because ${test.user.dir.lock} still exists; kill any running process and delete lock file if necessary</fail>
    </target>
    <target name="testuserdir-delete" depends="-testuserdir-delete-ok,-testuserdir-delete-fail" description="Delete testing user directory (if the application is not running); clears any saved settings etc."/>

    <target name="clean" depends="files-init,testuserdir-delete">
        <delete failonerror="false" includeemptydirs="true">
            <fileset dir="${build.classes.dir}" />
            <fileset dir="${build.dir}">
                <exclude name="testuserdir/"/>
            </fileset>
        </delete>
        <delete dir="${netbeans.javadoc.dir}/${code.name.base.dashes}"/>
        <delete file="${netbeans.javadoc.dir}/${code.name.base.dashes}.zip"/>
        <delete includeemptydirs="true" failonerror="false"> <!-- #59457: OK if cluster does not exist currently -->
            <fileset dir="${cluster}">
                <patternset refid="module.files"/>
                <exclude name="config/Modules/${code.name.base.dashes}.xml" if="${do.not.clean.module.config.xml}"/>
            </fileset>
        </delete>
        <delete file="${cluster}/update_tracking/${code.name.base.dashes}.xml"/>
        <delete file="${netbeans.dest.dir}/${module.cluster.name}.built" failonerror="false"/>
    </target>

    <target name="fix-dependencies" depends="basic-init" description="Removes unused compilation dependencies on other modules.">
        <property name="build.compiler.deprecation" value="false" />
        <property name="fix.dependencies.modules" value=""/>
        <fixdependencies antfile="../../build.xml" buildtarget="netbeans" cleantarget="clean" failonerror="true" sanitycheck="false" moduleFilter="${fix.dependencies.modules}" strip="false">
            <replace codenamebase="org.openide" addcompiletime="true" >
                <module codenamebase="org.openide.filesystems" spec="6.2"/>
                <module codenamebase="org.openide.util" spec="6.2"/>
                <module codenamebase="org.openide.util.enumerations" spec="6.2"/>
                <module codenamebase="org.openide.modules" spec="6.2"/>
                <module codenamebase="org.openide.nodes" spec="6.2"/>
                <module codenamebase="org.openide.explorer" spec="6.2"/>
                <module codenamebase="org.openide.awt" spec="6.2"/>
                <module codenamebase="org.openide.dialogs" spec="6.2"/>
                <module codenamebase="org.openide.compat" spec="6.2"/>
                <module codenamebase="org.openide.options" spec="6.2"/>
                <module codenamebase="org.openide.windows" spec="6.2"/>
                <module codenamebase="org.openide.text" spec="6.2"/>
                <module codenamebase="org.openide.actions" spec="6.2"/>
                <module codenamebase="org.openide.loaders" spec="5.3"/>
            </replace>
            <replace codenamebase="org.openide.util" addcompiletime="true" >
                <module codenamebase="org.openide.util" spec="8.0"/>
                <module codenamebase="org.openide.util.lookup" spec="8.0"/>
            </replace>
            <replace codenamebase="org.openide.nodes" addcompiletime="true" >
                <module codenamebase="org.openide.nodes" spec="7.23"/>
                <module codenamebase="org.openide.awt" spec="7.33"/>
            </replace>
            <replace codenamebase="org.openide.filesystems" addcompiletime="true" >
                <module codenamebase="org.openide.filesystems" spec="8.0"/>
                <module codenamebase="org.openide.util.lookup" spec="8.16"/>
            </replace>
            <replace codenamebase="org.openide.util" addcompiletime="true">
                <module codenamebase="org.openide.util" spec="9.0"/>
                <module codenamebase="org.openide.util.ui" spec="9.3"/>
            </replace>
            <replace codenamebase="org.openide.util" addcompiletime="true">
                <module codenamebase="org.openide.util" spec="9.3"/>
            </replace>

            <replace codenamebase="org.openide.filesystems" addcompiletime="true">
                <module codenamebase="org.openide.filesystems" spec="9.0"/>
                <module codenamebase="org.openide.filesystems.nb" spec="9.0"/>
                <module codenamebase="org.openide.filesystems.compat8" spec="9.0"/>
            </replace>
            <replace codenamebase="org.openide.execution" addcompiletime="true">
                <module codenamebase="org.openide.execution" spec="9.0"/>
                <module codenamebase="org.openide.execution.compat8" spec="9.0"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.parsing.api" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.parsing.api" release="1" spec="9.0"/>
                <module codenamebase="org.netbeans.modules.parsing.indexing" spec="9.0"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.projectuiapi" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.projectuiapi" release="1" spec="1.78"/>
                <module codenamebase="org.netbeans.modules.projectuiapi.base" release="1" spec="1.78"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.project.ant" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.project.ant" release="1" spec="1.62"/>
                <module codenamebase="org.netbeans.modules.project.ant.ui" spec="1.62"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.java.project" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.java.project" release="1" spec="1.62"/>
                <module codenamebase="org.netbeans.modules.java.project.ui" release="1" spec="1.62"/>
            </replace>
            <replace codenamebase="org.netbeans.api.xml" addcompiletime="true">
                <module codenamebase="org.netbeans.api.xml" release="1" spec="1.41"/>
                <module codenamebase="org.netbeans.api.xml.ui" release="1" spec="1.41"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.editor.lib" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.editor.lib" release="3" spec="4.0"/>
                <module codenamebase="org.netbeans.modules.editor.document" spec="1.0"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.editor.lib2" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.editor.lib2" release="1" spec="2.0"/>
                <module codenamebase="org.netbeans.modules.editor.document" spec="1.0"/>
            </replace>
            <replace codenamebase="org.netbeans.api.progress" addcompiletime="true">
                <module codenamebase="org.netbeans.api.progress" release="1" spec="1.40"/>
                <module codenamebase="org.netbeans.api.progress.nb" spec="1.40"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.java.source" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.java.source.base" spec="1.1"/>
                <module codenamebase="org.netbeans.modules.java.source" spec="0.141"/>
                <module codenamebase="org.netbeans.modules.java.source.compat8" spec="9.0"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.project.libraries" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.project.libraries" release="1" spec="1.49"/>
                <module codenamebase="org.netbeans.modules.project.libraries.ui" release="1" spec="1.49"/>
            </replace>
            <replace codenamebase="org.netbeans.modules.xml.catalog" addcompiletime="true">
                <module codenamebase="org.netbeans.modules.xml.catalog" release="2" spec="2.0"/>
                <module codenamebase="org.netbeans.modules.xml.catalog.ui" spec="1.0"/>
            </replace>
            <replace codenamebase="org.openide.loaders" addcompiletime="true">
                <module codenamebase="org.openide.loaders" spec="7.61"/>
                <module codenamebase="org.netbeans.api.templates" spec="1.0"/>
            </replace>
            <replace codenamebase="org.netbeans.core.startup" addcompiletime="true">
                <module codenamebase="org.netbeans.core.startup" release="1" spec="1.60"/>
                <module codenamebase="org.netbeans.core.startup.base" spec="1.60"/>
            </replace>
            <fileset dir="nbproject" >
                <include name="project.xml" />
            </fileset>
        </fixdependencies>
    </target>

    <target name="fix-test-dependencies" depends="basic-init" description="Moves classpath for tests from project.properties to project.xml.">
        <fixtestdeps projectXml="nbproject/project.xml"
                     propertiesFile="nbproject/project.properties"/>
    </target>

    <target name="display-coverage-report" depends="coverage-report"
            description="Creates and displays unit test coverage report for this module">
        <fail unless="testcoverage.unit.report.dir">
            Property testcoverage.unit.report.dir not set. Test coverage script may be missing in ${harness.dir}.
        </fail>
        <nbbrowse file="${testcoverage.unit.report.dir}/index.html"/>
    </target>
    
</project>
