<?xml version="1.0" encoding="UTF-8"?> <!-- -*- sgml-indent-step: 2 -*- -->
<!--
  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 basedir="." default="all" name="epbuild">
    <import file="default.xml"/>

    <target name="all" depends="-init-devenv,num_init,clean-log,ide-log,commit-validation"/>

    <target name="-user-init" if="user.build.properties.file">
      <property file="${user.build.properties.file}"/>
    </target>

    <target name="-init" depends="-user-init">
        <property name="allsuites"      value="print/suite,xml/epsuite,enterprise/soa,enterprise/xslt,enterprise/compapp,enterprise/bpel,enterprise/iep,enterprise/wsdlextensions,enterprise/sql,identity"/>
        <property name="allsuites.nbms" value="print/suite,xml/epsuite,enterprise/soa,enterprise/xslt,enterprise/compapp,enterprise/bpel,enterprise/iep,enterprise/wsdlextensions,enterprise/sql,identity"/>
    </target>
    
    <target name="-init-devenv" depends="-init">
        <property name="no-ide-zip" value="true"/>
        <propertyfile file="run.properties" comment="Generated per run properties">
            <entry key="compile.warning" value="-Xlint"/>
        </propertyfile>
    </target>

    <target name="clean-log" depends="num_init">
        <record name="${LOGDIR}/clean.log" action="start"/>
        <antcall target="clean"/>
        <record name="${LOGDIR}/clean.log" action="stop"/>
    </target>

    <target name="update-log" depends="num_init">
        <record name="${LOGDIR}/update.log" action="start"/>
        <antcall target="may-update"/>
        <record name="${LOGDIR}/update.log" action="stop"/>
    </target>

    <target name="ide-log" depends="num_init">
        <record name="${LOGDIR}/build.log" action="start"/>
        <antcall target="firststart"/>
        <record name="${LOGDIR}/build.log" action="stop"/>
    </target>

    <target name="num_init" depends="num,no_num,ext,no_ext" unless="no_increment"/>

    <target name="no_num" if="logdir">
        <property name="LOGDIR" value="${logdir}"/>
    </target>

    <target name="num" unless="logdir">
        <tstamp>
            <format property="DATE" pattern="yyMMdd" locale="en"/>
        </tstamp>
        <available file="${DATE}.number" property="build.number.file.found"/>
        <buildnumber file="${DATE}.number"/>

        <property name="buildnumber" value="${DATE}_${build.number}"/>
        <property name="no_increment" value="true"/>
    </target>

    <target name="ext" if="build.number.file.found" unless="logdir">
        <property name="ext" value="_${build.number}"/>
        <property name="LOGDIR" location="logs/${DATE}${ext}"/>
        <mkdir dir="${LOGDIR}"/>
        <echo message="LOGDIR=${LOGDIR}"/>
    </target>

    <target name="no_ext" unless="build.number.file.found,logdir">
        <property name="LOGDIR" location="logs/${DATE}"/>
        <mkdir dir="${LOGDIR}"/>
        <echo message="LOGDIR=${LOGDIR}"/>
    </target>

    <macrodef name="resolve">
        <attribute name="name"/>
        <attribute name="value"/>
        <sequential>
            <property name="@{name}" value="${@{value}}"/>
        </sequential>
    </macrodef>

    <target name="bootstrap" depends="-entpack-tools,init,-init">

        <!-- set user properties -->
        <antcall target="build-messaging"/>
        <antcall target="validate"/>
    </target>

    <target name="build-messaging">
        <echo message="Starting a build for Enterprise Pack ${branchname} build ${buildnumber}..."/>
        <echo message="OS: ${os.name} ${os.version}  Locale: ${user.language}"/>
        <echo message="Java: ${java.vendor} ${java.version} in ${java.home}"/>
        <echo message="Ant: ${ant.version} in ${ant.home}"/>
        <echo message="Classpath: ${java.class.path}"/>
        <echo message="NetBeans: ${netbeans.dest.dir}"/>
        <echo message="NB ROOT: ${nb_all}"/>
        <echo message="Enterprise Pack Modules: ${allsuites}"/>
        <echo message="Enterprise Pack NBMs: ${allsuites.nbms}"/>
    </target>
    
    <target name="build" depends="bootstrap,netbeans-all"/>
    <target name="ml-build" depends="build,ml-jars"/>

    <target name="ml-jars" depends="bootstrap">
        <ant dir="../../translatedfiles" antfile="../translatedfiles/build_entpack.xml" target="pj-jars"/>
        <copy todir="${netbeans.dest.dir}" >
            <fileset dir="../../translatedfiles/nb"/>
        </copy>
    </target>

    <target name="real-clean" depends="clean" description="Clean everything possible.">
        <echo message="Cleaning build system..."/>
        <echo message="Cleaning NetBeans-specific Ant extensions..."/>
        <delete file="moduledefs-tmp.properties"/>
        <delete file="moduledefs-dirs-tmp.properties"/>
        <delete file="run.properties"/>
        <delete dir="nbms" failonerror="false"/>
        <delete dir="${cache.dir}"/>
        <delete dir="${dist.dir}"/>
        <delete dir="${netbeans.dest.dir}"/>
        <delete dir="xtest"/>
        <delete dir="logs"/>
        <delete dir="results"/>
    </target>

    <target name="clean" depends="bootstrap, clean-all" description="Run 'clean' on all module suites.">
        <echo message="Run `ant real-clean' if desired."/>
    </target>

    <target name="netbeans-all" depends="bootstrap">
        <mkdir dir="${nb_all}/nbbuild/netbeans"/>
        <ep-for-each startdir="../.." target="build" locations="${allsuites}" inheritAll="false"/>
        <ep-for-each startdir="../.." target="process-cluster" locations="${allsuites}" inheritAll="false"/>
    </target>

    <target name="ide-zip" depends="build,zip-clusters" unless="no-ide-zip">
        <mkdir dir="${dist.dir}"/>
        <zip destfile="${dist.dir}/ide-${branchname}-${buildnumber}.zip" update="true" duplicate="preserve">
            <zipfileset dir="${netbeans.dest.dir}" filemode="755" includes="bin/netbeans" prefix="netbeans"/>
            <zipfileset dir="${netbeans.dest.dir}" filemode="755" includes="platform6/lib/nbexec" prefix="netbeans"/>
            <zipfileset dir="${netbeans.dest.dir}" includes="**/*" prefix="netbeans"/>
        </zip>
    </target>

    <target name="zip-clusters" depends="init,-init,num_init">
        <mkdir dir="${dist.dir}"/>
        <ep-for-each startdir="../.." target="zip-cluster" locations="${allsuites}" propertyName="dist.dir" propertyValue="${dist.dir}">
            <property name="branchname" value="${branchname}"/>
            <property name="buildnumber" value="${buildnumber}"/>
            <property name="file.ext" value=""/>
        </ep-for-each>
    </target>

    <target name="firststart" depends="ide-zip">
        <ant dir="." antfile="start.xml">
            <property name="locale" value="en"/>
            <property name="firststart_args" value="${args_en}"/>
        </ant>
    </target>

    <target name="ml-ide-zip" depends="ml-build,ml-zip-clusters" unless="no-ide-zip">
        <mkdir dir="${dist.dir}"/>
        <zip destfile="${dist.dir}/ide-${branchname}-${buildnumber}-ml.zip" update="true" duplicate="preserve">
            <zipfileset dir="${netbeans.dest.dir}" filemode="755" includes="bin/netbeans" prefix="netbeans"/>
            <zipfileset dir="${netbeans.dest.dir}" filemode="755" includes="platform6/lib/nbexec" prefix="netbeans"/>
            <zipfileset dir="${netbeans.dest.dir}" includes="**/*" prefix="netbeans"/>
        </zip>
    </target>

    <target name="ml-zip-clusters" depends="init,-init,num_init">
        <mkdir dir="${dist.dir}"/>
        <ep-for-each startdir="../.." target="zip-cluster" locations="${allsuites}" propertyName="dist.dir" propertyValue="${dist.dir}">
            <property name="branchname" value="${branchname}"/>
            <property name="buildnumber" value="${buildnumber}"/>
            <property name="file.ext" value="-ml"/>
        </ep-for-each>
    </target>

    <target name="ml-firststart" depends="ml-ide-zip">
        <ant dir="." antfile="start.xml">
            <property name="locale" value="ja"/>
            <property name="firststart_args" value="${args_ja}"/>
        </ant>
    </target>

    <target name="clean-all" depends="bootstrap,-init">
        <echo message="allsuites.nbms=${allsuites.nbms}"/>
        <ep-for-each startdir="../.." target="clean" locations="${allsuites.nbms}" skipNonExistentDir="true" inheritAll="false"/>
    </target>

    <target name="nbm-all" depends="bootstrap,-init">
        <mkdir dir="nbms"/>
        <ep-for-each startdir="../.." target="nbms" locations="${allsuites.nbms}" propertyName="nbm.target.dir" propertyValue="${nb_all}/nbbuild/entpack/nbms">
            <property name="nbplatform.EntPack.netbeans.dest.dir" value="${nb_all}/nbbuild/netbeans"/>
            <property name="nbplatform.EntPack.label" value="EntPack"/>
            <property name="nbplatform.EntPack.harness.dir" value="${nb_all}/nbbuild/netbeans/harness"/>
            <property name="keystore" value="${keystore}"/>
            <property name="storepass" value="${storepass}"/>
            <property name="nbm_alias" value="${nbm_alias}"/>
        </ep-for-each>
        <ep-for-each startdir="../.." target="move-nbm" locations="${allsuites.nbms}">
            <property name="nbm.target.dir" value="${nb_all}/nbbuild/entpack/nbms"/>
        </ep-for-each>
    </target>

    <target name="ml-nbm-all" depends="bootstrap,-init,ml-jars">
        <mkdir dir="nbms"/>
        <ep-for-each startdir="../.." target="nbms" locations="${allsuites.nbms}" propertyName="nbm.target.dir" propertyValue="${nb_all}/nbbuild/entpack/nbms">
            <property name="nbplatform.EntPack.netbeans.dest.dir" value="${nb_all}/nbbuild/netbeans"/>
            <property name="nbplatform.EntPack.label" value="EntPack"/>
            <property name="nbplatform.EntPack.harness.dir" value="${nb_all}/nbbuild/netbeans/harness"/>
            <property name="locmakenbm.locales" value="${locmakenbm.locales}"/>
            <property name="keystore" value="${keystore}"/>
            <property name="storepass" value="${storepass}"/>
            <property name="nbm_alias" value="${nbm_alias}"/>
        </ep-for-each>
        <ep-for-each startdir="../.." target="move-nbm" locations="${allsuites.nbms}">
            <property name="nbm.target.dir" value="${nb_all}/nbbuild/entpack/nbms"/>
        </ep-for-each>
    </target>

    <target name="zip-nbms" depends="num,nbm-all">
        <mkdir dir="${dist.dir}"/>
        <zip destfile="${dist.dir}/all-nbms-${branchname}-${buildnumber}.zip" update="true" duplicate="preserve" basedir="nbms"/>
    </target>

    <target name="ml-zip-nbms" depends="num,ml-nbm-all">
        <mkdir dir="${dist.dir}"/>
        <zip destfile="${dist.dir}/all-nbms-${branchname}-${buildnumber}-ml.zip" update="true" duplicate="preserve" basedir="nbms"/>
    </target>

    <target name="get-netbeans" description="update netbeans binaries" depends="-may-get-nbantext,-may-get-netbeans,-may-get-xtest"/>
    
    <target name="-may-get-nbantext">
        <available property="nbantext.available" file="../nbantext.jar"/>
        <antcall target="-may-rebuild-nbantext" inheritAll="false"/>
    </target>
    
    <target name="-may-rebuild-nbantext" unless="nbantext.available">
        <ant dir="${nb_all}/nbbuild" antfile="build.xml" target="bootstrap" inheritAll="false"/>
    </target>
    
    <target name="-may-get-netbeans">
        <echo message="netbeans.dest.dir=${netbeans.dest.dir}"/>
        <condition  property="nb.build.available">
            <available file="${netbeans.dest.dir}/build_info"/>
        </condition>
        <echo message="nb.build.available=${nb.build.available}"/>
        <antcall target="-may-rebuild-netbeans"/>
    </target>
    
    <target name="-check-have-nb-modules">
        <!-- check for the minimal presence of NB modules necessary for NB IDE rebuild
             the list is not complete, it's just basic test -->
        <condition property="have.nb.modules" value="true">
            <and>
                <available file="${nb_all}/apisupport" type="dir"/>
                <available file="${nb_all}/core" type="dir"/>
                <available file="${nb_all}/openide" type="dir"/>
                <available file="${nb_all}/ide" type="dir"/>
            </and>
        </condition>
    </target>
    
    <target name="-may-rebuild-netbeans" depends="-check-have-nb-modules" unless="nb.build.available" if="have.nb.modules">
        <echo message="Rebuilding NetBeans IDE; nb.build.available=${nb.build.available}; have.nb.module=${have.nb.modules}"/>
        <ant dir="${nb_all}/nbbuild" antfile="${nb_all}/nbbuild/build.xml" target="build" inheritAll="false"/>
        <antcall target="-fail-no-nb-ide"/>
    </target>
    
    <target name="-check-did-nb-rebuild">
        <condition property="nb.got.rebuild" value="true">
            <and>
                <available file="${netbeans.dest.dir}/build_info" type="file"/>
                <isset property="netbeans.dest.dir"/>
            </and>
        </condition>
    </target>
    
    <target name="-fail-no-nb-ide" depends="-check-did-nb-rebuild" unless="nb.got.rebuild">
        <fail message="NetBeans Enterprise Pack requires binary build of NetBeans IDE to be available 
        prior the very build of Enterprise Pack modules. Get either NetBeans IDE build 
        on http://www.netbeans.org/download/index.html or get NetBeans IDE sources. Check 
        http://nbbuild.netbeans.org/entpack/index.html for further details."/>
    </target>
    
    <target name="-check-have-xtest">
        <condition property="xtest.distro.available">
            <available file="${nb_all}/xtest/xtest-distribution.zip" type="file"/>
        </condition>
        <condition property="xtest.dir.available">
            <available file="${nb_all}/xtest" type="dir"/>
        </condition>
        <echo message="xtest.distro.available=${xtest.distro.available}"/>
        <echo message="xtest.dir.available=${xtest.dir.available}"/>
    </target>

    <target name="-may-get-xtest" depends="-check-have-xtest,-rebuild-xtest"/>
    
    <target name="-rebuild-xtest" unless="xtest.distro.available" if="xtest.dir.available">
        <ant dir="${nb_all}/xtest" antfile="${nb_all}/xtest/build.xml" target="makedist-simple"/>
    </target>
    
    <target name="-entpack-tools">
    <!--
        <javac srcdir="antsrc" destdir="antsrc" deprecation="true" debug="true" source="1.4" classpath="${ant.home}/lib/ant.jar"/>
        <jar jarfile="entpack-antext.jar" basedir="antsrc" update="true">
            <exclude name="**/*.java"/>
            <exclude name="package-list"/>
        </jar>
    -->
    </target>

    <target name="validate" depends="check-jdk-version,check-ant-version"
        description="Make sure that the build is using the correct jdk and ant versions.">
    </target>
  
    <target name="check-jdk-version">
        <condition property="supported.jdk">
            <contains string="${java.version}" substring="${required.java.version}"/>
        </condition>
        <fail unless="supported.jdk"
              message="You must use JDK version ${required.java.version}. You are using ${java.version}. You may get the correct version from http://java.sun.com/products/archive/j2se/${required.java.version}/index.html"/>
    </target>

    <target name="check-ant-version">
        <condition property="supported.ant">
            <contains string="${ant.version}" substring="${required.ant.version}"/>
        </condition>
        <fail unless="supported.ant"
              message="You must use Ant version ${required.ant.version}. You are using ${ant.version}. You may get the correct version from http://archive.apache.org/dist/ant/binaries"/>
    </target>

    <target name="junit" depends="junit-init">
        <exec executable="ant">
            <arg value="-lib"/>
            <arg value="${nb_all}/junit/external/${junit.jar}"/>
            <arg value="junit-test"/>
        </exec>
    </target>

    <target name="junit-log" depends="num_init">
        <record name="${LOGDIR}/sanitytest.log" action="start"/>
            <antcall target="junit"/>
        <record name="${LOGDIR}/sanitytest.log" action="stop"/>
    </target>

    <target name="junit-init">
        <!-- get junit binary zip -->
    </target>

    <target name="l10n-kit" depends="bootstrap">
        <echo message="Creating l10n kits..."/>
        <taskdef name="l10nTask" classname="org.netbeans.nbbuild.L10nTask" classpath="${nb_all}/nbbuild/nbantext.jar"/>

        <property name="changedFile" value="l10n.list.entpack.changed"/>
        <property name="localizableFile" value="l10n.list.entpack"/>
        <property name="generatedFile" value="l10n.list.entpack.translated_ja"/>
        <property name="l10n-dist" value="${dist.dir}"/>
        <property name="l10n-build" value="l10n-build"/>
        <property name="topdirs" value="${nb_all}"/>
        <property name="l10n-exclude" value="**/ja/**, **/*_ja.hs, **/*_ja.xml"/>
        <property name="l10n-modules" value="${allsuites}"/>

        <delete file="${l10n-dist}/l10n-${buildnumber}.tar.gz"/>
        <delete file="${l10n-build}/l10n-${buildnumber}.tar"/>

        <!-- regular modules L10Nkit -->
        <l10nTask topdirs="${topdirs}" modules="${l10n-modules}" localizableFile="${localizableFile}" generatedFile="${generatedFile}" distDir="${l10n-dist}" changedFile="${changedFile}" buildDir="${l10n-build}" buildNumber="${buildnumber}" excludePattern="${l10n-exclude}"/>

        <delete dir="${l10n-build}"/>
    </target>

    <target name="-check-run-validation">
        <condition property="ep.run.validation" value="true">
          <and>
            <available file="${nb_all}/xtest" type="dir"/>
            <available file="${nb_all}/xtest/lib/harness.xml" type="file"/>
          </and>
        </condition>
        <echo message="ep.run.validation=${ep.run.validation}"/>
    </target>

    <target name="get-xtest" depends="-may-get-xtest"/>

    <target name="commit-validation" depends="-may-get-xtest,-check-run-validation" if="ep.run.validation">
        <property name="xtest.config" value="commit-validation"/>
        <echo message="xtest.config=${xtest.config}"/>
        <ant antfile="test.xml" inheritAll="true">
           <property name="xtest.fail.on.failure" value="true"/>
           <property name="xtest.config" value="${xtest.config}"/>
        </ant>
    </target>
</project>
