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

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

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

The Original Software is NetBeans. The Initial Developer of the Original
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
Microsystems, Inc. All Rights Reserved.
-->
<project name="projectized" basedir=".">

    <import file="../default.xml"/>
    <import file="common.xml"/>

    <target name="common-init" depends="default.init"/>
    <target name="init" depends="basic-init,files-init,build-init"/>

    <target name="build-init" depends="basic-init">
        <!-- Not for release55, too many changes required:
        <property name="public.package.jar.dir" location="${nb_all}/nbbuild/build/public-package-jars"/>
        <mkdir dir="${public.package.jar.dir}"/>
            publicpackagejardir="${public.package.jar.dir}"
        -->
        <property name="avoid.friend.warnings" value="true"/> <!-- XXX release55 hack only -->
        <property name="avoid.pubpkg.warnings" value="true"/> <!-- XXX release55 hack only -->
        <parseprojectxml
            project="."
            publicpackagesproperty="public.packages"
            friendsproperty="friends"
            javadocpackagesproperty="module.javadoc.packages"
            moduledependenciesproperty="module.dependencies"
            moduleclasspathproperty="module.classpath"
            modulerunclasspathproperty="module.run.classpath"
            domainproperty="nbm.domain"
            classpathextensionsproperty="class.path.extensions"/>
        <condition property="is.regular">
            <not>
                <or>
                    <isset property="is.autoload"/>
                    <isset property="is.eager"/>
                    <equals arg1="${module.jar.dir}" arg2="core"/>
                    <equals arg1="${module.jar.dir}" arg2="lib"/>
                </or>
            </not>
        </condition>
        <property name="build.compiler.debug" value="true"/>
        <property name="build.compiler.debuglevel" value="source,lines,vars"/>
        <property name="build.compiler.deprecation" value="true"/>
        <property name="build.sysclasspath" value="ignore"/>
        <property name="build.compiler.optimize" value="off"/>
        <property name="build.package.compress" value="false"/>
        <property name="build.package.index" value="false"/>
        <property name="manifest.mf" location="manifest.mf"/>
        <property name="src.dir" location="src"/>
        <property name="build.classes.dir" location="build/classes"/>
        <property name="nbm" value="${code.name.base.dashes}.nbm"/>
        <property name="nbm.homepage" value="http://${nbm.domain}.${homepage.base}/"/>
        <property name="nbm.distribution" value="http://${dist.base}/${nbm}"/>
        <property name="nbm.module.author" value=""/>
        <property name="nbm.release.date" value=""/>
        <property name="nbm.needs.restart" value="false"/>
        <property name="nbm.is.global" value=""/>
        <path id="cp">
            <pathelement path="${module.classpath}"/>
            <pathelement path="${cp.extra}"/>
        </path>
        <property name="build.javahelp.dir" location="build/javahelp"/>
        <property name="javahelp.base" value="${code.name.base.slashes}/docs"/>
        <property name="javahelp.search" value="JavaHelpSearch"/>
        <property name="javahelp.excludes" value="credits.html"/>
    </target>

    <target name="compile" depends="init">
        <mkdir dir="${build.classes.dir}"/>
        <condition property="javac.target" value="${javac.source}">
            <not>
                <isset property="javac.target"/>
            </not>
        </condition>
        <condition property="tmp.java.home" value="${java14.home}">
            <and>
                <isset property="java14.home"/>
                <equals arg1="${javac.target}" arg2="1.4"/>
                <not>
                    <contains string="${cluster}" substring="enterprise"/>
                </not>
            </and>
        </condition>
        <property name="tmp.java.home" value="${java.home}"/>

        <javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="${javac.source}" target="${javac.target}" includeantruntime="false">
            <bootclasspath>
                <fileset dir="${tmp.java.home}/lib">
                    <include name="*.jar"/>
                </fileset>
                <!-- Handle MAC OSX -->
                <fileset dir="${tmp.java.home}/..">
                    <include name="Classes/*.jar"/>
                </fileset>
                <!-- Handle solaris -->
                <fileset dir="${tmp.java.home}/">
                    <include name="jre/lib/*.jar"/>
                </fileset>
            </bootclasspath>
            <classpath refid="cp"/>
            <compilerarg line="${javac.compilerargs}"/>
        </javac>
        <!-- Sanity check: -->
        <pathconvert pathsep=":" property="class.files.in.src">
            <path>
                <fileset dir="${src.dir}">
                    <include name="**/*.class"/>
                </fileset>
            </path>
        </pathconvert>
        <fail>
            <condition>
                <not>
                    <equals arg1="${class.files.in.src}" arg2=""/>
                </not>
            </condition>
            You have stray *.class files in ${src.dir} which you must remove.
            Probably you failed to clean your sources before updating them from CVS.
        </fail>
        <!-- OK, continue: -->
        <copy todir="${build.classes.dir}">
            <!-- #58298: strip comments to save some space -->
            <fileset dir="${src.dir}" includes="**/*.properties"/>
            <filterchain>
                <tokenfilter>
                    <!-- #61965: preserve #NOI18N and similar comments -->
                    <filetokenizer/>
                    <replaceregex pattern="^#(?!(PART)?(NO)?I18N).*[\r\n]+" replace="" flags="gm"/>
                </tokenfilter>
            </filterchain>
        </copy>
        <copy todir="${build.classes.dir}">
            <fileset dir="${src.dir}" excludes="${jar-excludes}"/>
        </copy>
    </target>
    
    <target name="test-lib-init" depends="init">
        <!-- xtest.home is set externally when run using XTest. -->
        <property name="xtest.home" location="${nb_all}/xtest"/>
        <path id="test.unit.lib.cp">
            <!-- XXX check if these files exist, and if not, run xtest/build.xml -->
            <pathelement location="${xtest.home}/lib/junit.jar"/>
            <pathelement location="${xtest.home}/lib/nbjunit.jar"/>
            <pathelement location="${xtest.home}/lib/nbjunit-ide.jar"/>
            <pathelement location="${xtest.home}/lib/insanelib.jar"/>
        </path>
    </target>

    <target name="javadoc" depends="build-init,-javadoc-init">
        <property name="javadoc.check.failonerror" value="false" />
        <!-- This should become an import at some point, perhaps: -->
        <ant dir="${nb_all}/nbbuild/javadoctools" antfile="template.xml" target="javadoc">
            <property name="javadoc.base" location="."/>
            <property name="javadoc.name" value="${code.name.base.dashes}" />
            <property name="javadoc.packages" value="${module.javadoc.packages}"/>
            <property name="javadoc.classpath" refid="cp"/>
            <property name="javadoc.manifest" location="${manifest.mf}"/>
            <property name="javadoc.project" location="nbproject/project.xml"/>
        </ant>
    </target>
    
    <target name="javadoc-nb" depends="init,javadoc" if="netbeans.home">
        <nbbrowse file="${netbeans.javadoc.dir}/${code.name.base.dashes}/index.html"/>
    </target>
    
    <!-- apisupport/project could calls this for the debug action. -->
    <!-- You can also call it directly from the nbbuild/misc pseudoproject. -->
    <target name="debug" depends="netbeans">
        <ant dir="${nb_all}/nbbuild" target="tryme-debug"/>
    </target>
    
    <target name="profile" depends="netbeans" >
        <fileset id="profiler.roots.module" dir="${cluster}">
            <include name="${module.jar}"/>
        </fileset>
        <ant dir="${nb_all}/nbbuild" target="tryme-profile" >
            <property name="profiler.roots.path" value="profiler.roots.module" />
            <reference refid="profiler.roots.module" />
        </ant>
    </target>
    
    <target name="reload" depends="netbeans">
        <ant dir="${nb_all}/nbbuild" target="tryme">
            <property name="tryme.debug.args" value="--reload ${cluster}/${module.jar}"/>
        </ant>
    </target>
    
    <target name="reload-in-ide" depends="netbeans">
        <nbinstaller module="${cluster}/${module.jar}" action="reinstall"/>
    </target>
    
    <target name="javahelp" depends="init" if="has.javahelp">
        <mkdir dir="${build.javahelp.dir}/${javahelp.base}/${javahelp.search}"/>
        <copy todir="${build.javahelp.dir}">
            <fileset dir="javahelp"/>
        </copy>
        <jhindexer basedir="${build.javahelp.dir}/${javahelp.base}"
                   db="${build.javahelp.dir}/${javahelp.base}/${javahelp.search}">
            <classpath>
                <fileset dir="${nb_all}/apisupport/external">
                    <include name="jsearch*.jar"/>
                </fileset>
            </classpath>
            <include name="**/*.html"/>
            <exclude name="${javahelp.search}/"/>
            <exclude name="${javahelp.excludes}"/>
        </jhindexer>
        <!-- Add ide.css for easy previewing only; usersguide provides it in distro: -->
        <!-- (XXX maybe the viewer task can automagically do this...) -->
        <mkdir dir="${build.javahelp.dir}/org/netbeans/modules/usersguide"/>
        <copy tofile="${build.javahelp.dir}/org/netbeans/modules/usersguide/ide.css"
              file="${nb_all}/usersguide/javahelp/org/netbeans/modules/usersguide/ide.css"
              failonerror="false"/>
        <mkdir dir="${cluster}/${javahelp.jar.dir}"/>
        <jar jarfile="${cluster}/${javahelp.jar}" compress="true">
            <fileset dir="${build.javahelp.dir}">
                <!-- XXX this does not exclude the folder, unfortunately... -->
                <exclude name="org/netbeans/modules/usersguide/ide.css"/>
            </fileset>
        </jar>
    </target>

    <target name="check-javahelp" depends="javahelp" description="Validate helpset for various errors." if="has.javahelp">
        <fail unless="javahelp.hs">Must set javahelp.hs property</fail>
        <taskdef name="checkhelpsets" classname="org.netbeans.nbbuild.CheckHelpSets">
            <classpath>
                <pathelement location="${nb_all}/nbbuild/nbantext.jar"/>
                <fileset dir="${nb_all}/core/external">
                    <include name="jh*.jar"/>
                </fileset>
            </classpath>
        </taskdef>
        <checkhelpsets>
            <!-- XXX need to check against real files (since there may be some processing) but should use a link mapper: -->
            <fileset dir="${build.javahelp.dir}">
                <include name="${javahelp.base}/${javahelp.hs}"/>
            </fileset>
        </checkhelpsets>
    </target>

    <!-- XXX need target to preview javahelp in a viewer like this: -->
    <!--
    HelpSet hs = new HelpSet(someClassLoader, f.toURI().toURL());
    String title = hs.getTitle();
    if (title == null) {
        title = f.getAbsolutePath();
    }
    JDialog dlg = new JDialog(WindowManager.getDefault().getMainWindow(), title, false);
    dlg.getContentPane().add(new JHelp(hs), BorderLayout.CENTER);
    dlg.setSize(920, 660); // match min size of IDE's viewer
    dlg.pack();
    dlg.addWindowListener(this);
    dlg.show();
    synchronized (this) {
        wait();
    }
    // ...
    public synchronized void windowClosing(WindowEvent ev) {
        notify();
    }
    -->

    <target name="fix-cddl" depends="build-init">
        <property name="license.root.dir" location="${basedir}"/>
        <checklicense >
            <cvsfileset dir="${license.root.dir}"/>
            <cvsfileset dir="${src.dir}"/>
            
    <convert 
        token='^([ \t]*[^ \n]+[ \t]?)?[ \t]*Sun Public License N?otice' 
        prefix='true'
    >
        <line text='The contents of this file are subject to the terms of the Common Development'/>
        <line text='and Distribution License (the License). You may not use this file except in'/>
        <line text='compliance with the License.'/>
    </convert>
    <convert 
     token='The *contents *of *this *file *are
 *subject *to *the *Sun *Public.*available.*at.*([hH][tT][tT][pP][^:]*://www.sun.com/|http://jalopy.sf.net/license-spl.html)'
    >
        <line text='You can obtain a copy of the License at http://www.netbeans.org/cddl.html'/>
        <line text='or http://www.netbeans.org/cddl.txt.'/>
        <line text=''/>
        <line text='When distributing Covered Code, include this CDDL Header Notice in each file'/>
        <line text='and include the License file at http://www.netbeans.org/cddl.txt.'/>
        <line text='If applicable, add the following below the CDDL Header, with the fields'/>
        <line text='enclosed by brackets [] replaced by your own identifying information:'/>
        <line text='"Portions Copyrighted [year] [name of copyright owner]"'/>
   </convert>
   <convert token='1997-[0-2][09][09][0-9]' replace='1997-2006'/>
   <convert token='Original\n[^A-Za-z]*Code' replace='Original\nSoftware' replaceall='true'/>
   <convert token='Original Code' replace='Original Software' replaceall='true'/>
        </checklicense>

        <checklicense fragment="Sun Public License" fail="whenpresent">
            <cvsfileset dir="${license.root.dir}"/>
            <cvsfileset dir="${src.dir}"/>
        </checklicense>
    </target>
</project>
