<?xml version="1.0"?>
<!DOCTYPE project [
  <!ENTITY jarmanifest '
          <manifest>
            <section name="org/apache/oro">
             <attribute name="Specification-Title"
                     value="${name}" />
             <attribute name="Specification-Version"
                     value="${version}" />
             <attribute name="Specification-Vendor"
                     value="${company.name}" />
             <attribute name="Implementation-Title"
                     value="org.apache.oro" />
             <attribute name="Implementation-Version"
                     value="${version} ${DATE}" />
             <attribute name="Implementation-Vendor"
                     value="${company.name}" />
             <attribute name="Implementation-Vendor-Id"
                     value="${company.id}" />
            </section>
           </manifest>'
  >
]>
<!--
  $Id$
 
  Copyright 2000-2005 The Apache Software Foundation
 
  Licensed 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.

Notes:
   This is a build file for use with the Jakarta Ant build tool.

Prerequisites:

   jakarta-ant from http://jakarta.apache.org/ant/index.html

Build Instructions:
   To build, run

   ant <target>

   in the directory where this file is located with the target you want.

Available targets (default == jar):
  clean          removes generated files
  docs           builds xml documentation
  examples       builds the example programs
  jar            builds lib + jar
  javadocs       builds the javadoc
  compile        builds the library
  lib            builds the library
  package        builds lib + jar + javadoc + distribution
  package-all    builds package-zip and package-tgz
  package-tgz    builds a tarred and gzipped distribution
  package-zip    builds a zipped distribution
  tools          builds the tools

Run ant -projecthelp for complete list of targets with descriptions.
-->

<project default="jar">

  <!-- Allow properties following these statements to be overridden -->
  <!-- Note that all of these don't have to exist.  They've just been defined
       incase they are used. -->
  <property file="build.properties"/>
<!--
  <property file=".ant.properties"/>
  <property file="${user.home}/.ant.properties"/>
  <property file="default.properties"/>  
 -->

    <!-- prepare target.  Creates build directories. -->

    <target name="prepare"
            description="Creates build directories.">
       <tstamp>
         <format property="DATE" pattern="yyyy-MM-dd hh:mm:ss" />
       </tstamp>
        <mkdir dir="${build.dest}"/>
        <mkdir dir="${build.dest}/META-INF"/>
        <copy todir="${build.dest}/META-INF">
            <fileset dir="${top.dir}">
                <include name="LICENSE"/>
                <include name="NOTICE"/>
            </fileset>
        </copy>
        <mkdir dir="${build.tests}"/>
        <available file="${jakarta-site2.dir}/lib" type="dir"
                   property="AnakiaTask.present"/>
    </target>

    <target name="prepare-error" depends="prepare"
            description="Prints error message for prepare target."
	    unless="AnakiaTask.present">
       <echo>
        AnakiaTask is not present! Please check to make sure that 
        velocity.jar is in your classpath.
       </echo>
    </target>

    <!-- compile target.  Compiles the library classes only -->
    <condition property="java.util.regex.available">
      <available classname="java.util.regex.Pattern"/>
    </condition>

    <target name="compile" depends="prepare"
            description="Compiles the library classes only.">
        <javac srcdir="${build.src}"
            destdir="${build.dest}"
            excludes="examples/**,tools/**"
            source="${javac.source}"
            target="${javac.target}"
            debug="${javac.debug}"
            deprecation="${javac.deprecation}"
            optimize="${javac.optimize}">
            <and>
                <filename name="**/*.java"/>
                <not>
                  <selector unless="java.util.regex.available">
                    <filename name="org/apache/oro/text/java/**"/>
                  </selector>
                </not>
            </and>
        </javac>
    </target>

    <!-- lib target.  Preserved for backward compatibility. -->

    <target name="lib" depends="compile"/>

    <!-- examples target.  Compiles the example classes. -->

    <target name="examples" depends="prepare,compile"
            description="Compiles the example classes.">
        <javac srcdir="${build.src}"
            destdir="${build.dest}"
            includes="examples/**"
            source="${javac.source}"
            target="${javac.target}"
            debug="${javac.debug}"
            deprecation="${javac.deprecation}"
            optimize="${javac.optimize}"/>
    </target>

    <!-- tools target.  Compiles the tool classes. -->

    <target name="tools" depends="prepare,compile"
            description="Compiles the tool classes.">
        <javac srcdir="${build.src}"
            destdir="${build.dest}"
            includes="tools/**"
            source="${javac.source}"
            target="${javac.target}"
            debug="${javac.debug}"
            deprecation="${javac.deprecation}"
            optimize="${javac.optimize}"/>
    </target>
    
    <!-- tests target.  Compiles and runs the unit tests. -->

    <target name="tests" depends="prepare,compile"
            description="Compiles and runs the unit tests.">
        <javac srcdir="${build.src}/tests"
            destdir="${build.tests}"
            source="${javac.source}"
            target="${javac.target}"
            debug="${javac.debug}"
            deprecation="${javac.deprecation}"
            optimize="${javac.optimize}"/>
    </target>

    <!-- jar target.  Compiles the source directory and creates a .jar file -->

    <target name="jar" depends="compile"
          description="Compiles the source directory and creates .jar files.">
        <!-- Create master jar file. -->
        <jar jarfile="${top.dir}/${jar.all.name}"
            basedir="${build.dest}"
            includes="org/**,META-INF/**"
            excludes="**/package.html,**/overview.html">
          &jarmanifest;
        </jar>

        <!-- Create core jar file. -->
        <jar jarfile="${top.dir}/${jar.core.name}"
            basedir="${build.dest}"
            includes="org/apache/oro/text/regex/**,**/PatternMatchingEngineFactory.class,META-INF/**"
            excludes="**/Perl5**,**/OpCode.class,**/CharStringPointer.class">
          &jarmanifest;
        </jar>

        <!-- Create awk jar file. -->
        <jar jarfile="${top.dir}/${jar.awk.name}"
            basedir="${build.dest}"
            includes="org/apache/oro/text/awk/**">
          &jarmanifest;
        </jar>

        <!-- Create glob jar file. -->
        <jar jarfile="${top.dir}/${jar.glob.name}"
            basedir="${build.dest}"
            includes="org/apache/oro/text/Glob*">
          &jarmanifest;
        </jar>

        <!-- Create java jar file. -->
        <jar jarfile="${top.dir}/${jar.java.name}"
            basedir="${build.dest}"
            includes="org/apache/oro/text/java/**">
          &jarmanifest;
        </jar>

        <!-- Create perl5 jar file. -->
        <jar jarfile="${top.dir}/${jar.perl5.name}"
            basedir="${build.dest}"
            includes="org/apache/oro/text/perl/**,org/apache/oro/text/regex/Perl5**,**/OpCode.class,**/CharStringPointer.class">
          &jarmanifest;
        </jar>

        <!-- Create util jar file. -->
        <jar jarfile="${top.dir}/${jar.util.name}"
            basedir="${build.dest}"
            includes="org/apache/oro/io/**,org/apache/oro/util/**,org/apache/oro/text/*.class"
            excludes="**/PatternMatchingEngineFactory.class,org/apache/oro/text/Glob*">
          &jarmanifest;
        </jar>
    </target>

    <!-- javadocs target.  Creates the API documentation -->

    <target name="javadocs" depends="prepare"
            description="Creates the API documentation.">
        <javadoc packagenames="org.apache.oro.io,org.apache.oro.text,org.apache.oro.text.regex,org.apache.oro.text.awk,org.apache.oro.text.java,org.apache.oro.text.perl,org.apache.oro.util"
            sourcepath="${build.src}"
            destdir="${javadoc.destdir}"
            overview="${build.src}/org/apache/oro/overview.html"
            author="true"
            version="true"
            windowtitle="${name} ${version} API"
            doctitle="${name} ${version} API"
            header="&lt;a href=&apos;http://jakarta.apache.org/oro/&apos; target=_top&gt;&lt;img src=&apos;{@docroot}/../images/logoSmall.gif&apos; alt=&apos;Jakarta ORO&apos; width=48 height=47 align=center border=0 hspace=1 vspace=1&gt;&lt;/a&gt;"
            bottom="${copyright.message}">
         </javadoc>
         <replace file="${javadoc.destdir}/overview-frame.html"
                  token="{@docroot}" value="."/>
         <replace dir="${javadoc.destdir}" includes="**/*.html"
                  token="@version@" value="${version}"/>
         <!-- Kluge to fix bad image src. -->
         <replace dir="${javadoc.destdir}" token="src='/.." value="src='..">
            <include name="**/*.html"/>
         </replace>
    </target>

    <!-- docs target.  Creates project web pages and documentation. -->
    <target name="docs" depends="prepare-error,compile,examples"
          description="Creates the project web pages and documentation."
	  if="AnakiaTask.present">
      <taskdef name="anakia" classname="org.apache.velocity.anakia.AnakiaTask">
          <classpath>
            <fileset dir="${jakarta-site2.dir}/lib">
              <include name="*.jar"/>
            </fileset>
          </classpath>
	</taskdef>

        <anakia basedir="${docs.src}" destdir="${docs.dest}/"
        extension=".html" style="./site.vsl"
        projectFile="stylesheets/project.xml"
        excludes="**/stylesheets/** manual/** empty.xml"
        includes="**/*.xml"
        lastModifiedCheck="true"
        templatePath="${jakarta-site2.dir}/xdocs/stylesheets">
        </anakia>

        <copy todir="${docs.dest}/images" filtering="no">
            <fileset dir="${docs.src}/images">
                <include name="**/*.gif"/>
                <include name="**/*.jpeg"/>
                <include name="**/*.jpg"/>
            </fileset>
        </copy>

        <mkdir dir="${docs.dest}/classes"/>
        <mkdir dir="${docs.dest}/classes/examples"/>
        <copy todir="${docs.dest}/classes/examples" filtering="no">
            <fileset dir="${build.dest}/examples">
                <include name="MatcherDemoApplet.class"/>
            </fileset>
        </copy>
        <mkdir dir="${docs.dest}/classes/org"/>
        <copy todir="${docs.dest}/classes/org" filtering="no">
            <fileset dir="${build.dest}/org">
                <include name="**/*.class"/>
            </fileset>
        </copy>
    </target>

    <!-- package target -->

    <target name="package" depends="jar,javadocs,docs"
            description="Creates a distribution directory tree.">
        <mkdir dir="${final.dir}"/>
        <copy todir="${final.dir}/src">
            <fileset dir="${code.src}"/>
        </copy>
	<!-- BEGIN_REMOVE_THIS -->
	<!-- Remove this when there's a first draft of the manual. -->
        <copy todir="${final.dir}/docs">
            <fileset dir="${docs.dest}" excludes="manual/**"/>
        </copy>
	<!-- END_REMOVE_THIS -->

        <copy file="${top.dir}/build.xml" tofile="${final.dir}/build.xml"/>
        <copy file="${top.dir}/build.properties"
	 tofile="${final.dir}/build.properties"/>

        <copy file="${top.dir}/CHANGES" tofile="${final.dir}/CHANGES"/>
        <copy file="${top.dir}/COMPILE" tofile="${final.dir}/COMPILE"/>
        <copy file="${top.dir}/CONTRIBUTORS"
              tofile="${final.dir}/CONTRIBUTORS"/>
        <copy file="${top.dir}/ISSUES"  tofile="${final.dir}/ISSUES"/>
        <copy file="${top.dir}/LICENSE" tofile="${final.dir}/LICENSE"/>
        <copy file="${top.dir}/NOTICE"  tofile="${final.dir}/NOTICE"/>
        <copy file="${top.dir}/README" tofile="${final.dir}/README"/>
        <copy file="${top.dir}/STYLE" tofile="${final.dir}/STYLE"/>
        <copy file="${top.dir}/TODO" tofile="${final.dir}/TODO"/>
        <copy todir="${final.dir}/">
          <fileset dir="${top.dir}/" includes="*.jar"/>
        </copy>
    </target>

    <!-- package-zip target.  Packages the distribution with ZIP -->

    <target name="package-zip" depends="package"
            description="Packages the distribution as a zip file.">
        <zip zipfile="${top.dir}/${final.name}.zip" basedir="${top.dir}/"
             includes="**/${final.name}/**" excludes="**/.cvsignore"/>
    </target>
    
    <!-- Packages the distribution with TAR-GZIP -->

    <target name="package-tgz" depends="package"
            description="Packages the distribution as a gzipped tar file.">
        <tar tarfile="${top.dir}/${final.name}.tar"
             basedir="${top.dir}" excludes="**/**">
          <tarfileset dir="${final.dir}/..">
            <include name="${final.name}/**"/>
            <exclude name="**/.cvsignore"/>
          </tarfileset>
        </tar>
        <gzip zipfile="${top.dir}/${project}-${version}.tar.gz" src="${top.dir}/${project}-${version}.tar"/>
    </target>
    
    <!-- Packages the distribution with ZIP and TAG-GZIP -->

    <target name="package-all" depends="package-zip, package-tgz">
    </target>

    <!-- Makes an attempt to clean up a little. -->

    <target name="clean"
	    description="Removes generated artifacts from source tree.">
        <delete dir="${build.dest}"/>
        <delete dir="${final.dir}"/>
        <delete file="${top.dir}/${final.name}.tar"/>
        <delete file="${top.dir}/${final.name}.tar.gz"/>
        <delete file="${top.dir}/${final.name}.zip"/>
        <delete>
          <fileset dir="${top.dir}" includes="velocity.log*,*.jar"/>
        </delete>

    </target>
</project>
