<!--
========================================================================
 Copyright (c) 1999 Mort Bay Consulting (Australia) Pty. Ltd.
 $Id: build.xml,v 3.186 2005/12/06 01:16:44 gregwilkins Exp $
========================================================================
 This build file specifies how to build Jetty using ant, the
 java build tool from the Apache/Jakarta project.
  <http://jakarta.apache.org/ant/index.html>
========================================================================
-->

<project name="Jetty HTTP Server" default="webapps" basedir=".">

  <!-- ==================================================================== -->
  <property file="ant.properties" />

  <!-- ==================================================================== -->
  <property environment="env"/>
  <property name="src"            value="${basedir}/src" />
  <property name="etc"            value="${basedir}/etc" />
  <property name="lib"            value="${basedir}/lib"/>
  <property name="ext"            value="${basedir}/ext"/>
  <property name="dist"           value="${basedir}/dist"/>
  <property name="contrib"        value="${basedir}/contrib"/>
  <property name="extra"          value="${basedir}/extra"/>
  <property name="classes"        value="${basedir}/classes"/>
  <property name="javadoc"        value="${basedir}/javadoc"/>
  <property name="logs"           value="${basedir}/logs"/>
  <property name="webapps"        value="${basedir}/webapps"/>
  <property name="demo.webapps"   value="${basedir}/demo/webapps"/>
  <property name="demo.src"       value="${basedir}/demo/src"/>
  <property name="test"           value="${basedir}/test"/>
  <property name="test.src"       value="${test}/src"/>
  <property name="test.classes"   value="${test}/classes" />

  <property name="jetty.home"             value="${basedir}" />
  <property name="jetty.webapp"           value="${demo.webapps}/jetty"/>
  <property name="jetty.war"              value="${demo.webapps}/jetty.war"/>
  <property name="jetty.webapp.webinf"    value="${jetty.webapp}/WEB-INF"/>
  <property name="jetty.webapp.classes"   value="${jetty.webapp.webinf}/classes"/>

  <property name="start.jar"              value="${basedir}/start.jar"/>
  <property name="stop.jar"               value="${basedir}/stop.jar"/>
  <property name="jetty.jar"              value="${lib}/org.mortbay.jetty.jar"/>
  <property name="mortbay.jmx.jar"        value="${lib}/org.mortbay.jmx.jar"/>
  <property name="mini.http.jar"          value="${lib}/org.mortbay.http.jar"/>
  <property name="servlet.jar"            value="${lib}/javax.servlet.jar"/>
  <property name="jasper-runtime.jar"     value="${ext}/jasper-runtime.jar"/>
  <property name="jasper-compiler.jar"    value="${ext}/jasper-compiler.jar"/>

  <property name="jetty.run"              value="${etc}/admin.xml ${etc}/jetty.xml"/>

  <property name="jvmarg"  value="-Djetty.home=${jetty.home}" />



  <!-- ==================================================================== -->
  <target name="classpath" >
    <available property="jdk1.4.available" classname="java.util.logging.Handler" />
    <fail message="JDK1.4 needed to build main release. See extra/jdk1.2 for 1.2,1.3 builds." unless="jdk1.4.available"/>
    <echo message="JDK1.4 available=${jdk1.4.available}" level="info"/>

    <path id="extpath">
      <fileset dir="${ext}">
        <include name="*.jar"/>
        <include name="*.JAR"/>
        <include name="*.zip"/>
        <include name="*.ZIP"/>
        <exclude name="javax.xml.jaxp.jar"/>
        <exclude name="crimson.jar"/>
       </fileset>
    </path>
   
    <path id="classpath">
      <pathelement location="${jetty.jar}" />
      <pathelement location="${servlet.jar}" />
      <pathelement location="${jasper-runtime.jar}" />
      <pathelement location="${jasper-compiler.jar}" />
      <path refid="extpath" />
    </path>
    <property name="expanded.classpath" refid="classpath"/>
    <echo message="classpath=${expanded.classpath}" level="info"/>

    <available property="jmx.available"
               classname="javax.management.MBeanException"
               classpathref="extpath"
    />
    <echo message="JMX available=${jmx.available}" level="info"/>

  </target>
  
  <!-- ==================================================================== -->
  <target name="prepare" depends="classpath">
    <mkdir dir="${jetty.webapp.classes}"/>
    <mkdir dir="${javadoc}" />
    <mkdir dir="${classes}" />
    <mkdir dir="${lib}" />
    <mkdir dir="${etc}/dtd" />
    <copy todir="${etc}/dtd">
      <fileset dir="${src}/org/mortbay/xml/" includes="*.dtd"/>
      <fileset dir="${src}/javax/servlet/resources/" includes="*.dtd"/>
    </copy>  
    <copy todir="${demo.webapps}/root">
      <fileset dir="${etc}/dtd" includes="*.dtd"/>
    </copy>
    <copy file="${src}/org/mortbay/jetty/servlet/webdefault.xml" tofile="${etc}/webdefault.xml" />
    <available property="demo.available" type="dir" file="${demo.src}" />
    <echo message="Demo available=${demo.available}" level="info"/>
  </target>
  

  <!-- ==================================================================== -->
  <target name="tidy" description="Remove generated files not needed for running">
    <delete dir="${dist}" quiet="false"/>
    <delete dir="${classes}" quiet="true"/>
    <delete dir="${test.classes}" quiet="true"/>
    <delete dir="${javadoc}" quiet="false"/>
    <delete file="${mini.http.jar}" quiet="true"/>
    <delete includeEmptyDirs="true" quiet="true">
      <fileset dir="${basedir}/work">
        <include name="*/**"/>
        <exclude name=".keepme"/>
      </fileset>
    </delete>
    <ant dir="${test}" antfile="${test}/build.xml" inheritAll="false" target="tidy"/>
    <ant dir="${extra}" antfile="${extra}/build.xml" inheritAll="false" target="tidy"/>
  </target>
  

  <!-- ==================================================================== -->
  <target name="clean" depends="tidy"
     description="Remove generated files">
    <delete dir="${jetty.webapp.classes}" quiet="false"/>
    <delete dir="${etc}/dtd" quiet="false"/>
    <delete file="${jetty.jar}" quiet="false"/>
    <delete file="${mortbay.jmx.jar}" quiet="false"/>
    <delete file="${servlet.jar}" quiet="false"/> 
    <delete file="${start.jar}" quiet="false"/>
    <delete file="${stop.jar}" quiet="false"/>
    <delete file="${etc}/webdefault.xml" quiet="false"/>
    <delete file="${demo.webapps}/jetty/LICENSE.TXT" quiet="false"/>
    <delete file="${demo.webapps}/jetty/versions.txt" quiet="false"/>
    <delete file="${demo.webapps}/jetty/readme.txt" quiet="false"/>
    <delete file="${webapps}/javadoc.war"/>

    <delete quiet="false">
      <fileset dir="${demo.webapps}/root">
        <include name="*.dtd"/>
      </fileset>
    </delete>
    <ant antfile="${test}/build.xml" inheritAll="false" target="clean"/>
    <ant dir="${extra}" antfile="${extra}/build.xml" inheritAll="false" target="clean"/>
    <ant dir="${webapps}/template" antfile="${webapps}/template/build.xml" inheritAll="false" target="clean"/>
  </target>



  <!-- ==================================================================== -->
  <target name="classes" depends="prepare"
   description="Compile the java classes" >
    <mkdir dir="${classes}" />
    <copy todir="${classes}">
      <fileset dir="${src}">
        <include name="**/*.properties" />
        <include name="**/*.dtd" />
        <include name="**/*.xml" />
        <include name="**/*.config" />
        <include name="**/*.xsd" />
      </fileset>
    </copy>

    <javac srcdir="${src}"
           destdir="${classes}"
           debug="${javac.debug}"
           optimize="${javac.optimize}"
           deprecation="${javac.deprecation}"
	   encoding="${javac.encoding}"
           >
       <classpath>
         <path refid="extpath"/>
         <pathelement path="${classes}"/>
       </classpath>
       <include name="**/*.java"/>
       <exclude name="**/jmx/**" unless="jmx.available"/>
    </javac>

  </target>


  <!-- ==================================================================== -->
  <target name="extra" depends="jars">
    <ant dir="${extra}" antfile="${extra}/build.xml" inheritAll="false"/>
  </target>


  <!-- ==================================================================== -->
  <target name="start.jar" depends="classes">
    <jar jarfile="${start.jar}" basedir="${classes}"  >
       <manifest>    
         <attribute name="Main-Class" value="org.mortbay.start.Main"/>
       </manifest>    
       <include name="org/mortbay/start/**" />
       <exclude name="**/jmx/**" />
    </jar>
  </target>

  <!-- ==================================================================== -->
  <target name="stop.jar" depends="classes">
    <jar jarfile="${stop.jar}" basedir="${classes}"  >
       <manifest>    
         <attribute name="Main-Class" value="org.mortbay.stop.Main"/>
       </manifest>    
       <include name="org/mortbay/stop/**" />
       <exclude name="**/jmx/**" />
    </jar>
  </target>
  
  <!-- ==================================================================== -->
  <target name="servlet.jar" depends="classes">
    <jar jarfile="${servlet.jar}" basedir="${classes}" >
       <include name="javax/servlet/**" />
       <manifest>    
         <attribute name="Sealed" value="${jar.sealed}"/>
         <attribute name="Built-By" value="${user.name}"/>
         <attribute name="Specification-Title" value="Java API for Servlets"/>
         <attribute name="Specification-Version" value="2.4"/>
         <attribute name="Implementation-Version" value="2.4.jetty"/>
         <attribute name="Package-Title" value="javax.servlet"/>
         <attribute name="Implementation-Vendor" value="Apache Software Foundation"/>
         <attribute name="Implementation-Title" value="javax.servlet"/>
       </manifest>
    </jar>
  </target>


  <!-- ==================================================================== -->
  <target name="jetty.jar" depends="classes,servlet.jar" >
    <jar jarfile="${jetty.jar}">
       <manifest>    
         <attribute name="Sealed" value="${jar.sealed}"/>
         <attribute name="Built-By" value="${user.name}"/>
         <attribute name="Specification-Version" value="${RELEASE.MAJOR}"/>
         <attribute name="Implementation-Version" value="${RELEASE.MAJOR.MINOR}"/>
         <attribute name="Package-Title" value="org.mortbay.http"/>
         <attribute name="Implementation-Vendor" value="Mort Bay Consulting, Pty. Ltd."/>
         <attribute name="Implementation-URL" value="http://jetty.mortbay.org"/>
         <attribute name="Main-Class" value="org.mortbay.http.HttpServer"/>

         <section name="org/mortbay/jetty/">
           <attribute name="Specification-Title" value="Servlet/2.4"/>
           <attribute name="Implementation-Title" value="Jetty/${RELEASE.MAJOR}"/>
         </section>

         <section name="org/mortbay/http/">
           <attribute name="Implementation-Title" value="Mort Bay HTTP Server"/>
         </section>

         <section name="org/mortbay/util/">
           <attribute name="Implementation-Title" value="Mort Bay Misc. Utilities"/>
         </section>

       </manifest>

       <!--
       <metainf dir="${src}/org/mortbay/log">
         <include name="services/*"/>
       </metainf>
       -->

       <fileset dir="${classes}">
         <include name="org/mortbay/**"/>
         <exclude name="org/mortbay/start/**" />
         <exclude name="org/mortbay/stop/**" />
         <exclude name="**/jmx/**" />
       </fileset>
    </jar>
  </target>


  <!-- ==================================================================== -->
  <target name="mortbay.jmx.jar" depends="classes">
    <jar jarfile="${mortbay.jmx.jar}">
       <manifest/>    
       <fileset dir="${classes}">
         <include name="org/mortbay/**/jmx/**"/>
       </fileset>
    </jar>
  </target>

  <!-- ==================================================================== -->
  <target name="mini.http.jar" depends="classes"
     description="Builds minimal dynamic http server">
    <jar jarfile="${mini.http.jar}" basedir="${classes}" compress="true">
       <include name="org/mortbay/util/*" />
       <include name="org/mortbay/http/*" />
       <include name="org/mortbay/http/handler/AbstractHttpHandler.class" />
       <include name="org/mortbay/http/handler/ResourceHandler.class" />
       <include name="org/mortbay/http/handler/ErrorPageHandler.class" />
       <include name="org/mortbay/http/handler/DumpHandler.class" />
       <include name="org/mortbay/http/handler/NullHandler.class" />
       <include name="org/mortbay/http/handler/NotFoundHandler.class" />
       <include name="javax/servlet/http/Cookie.class" />
       <include name="javax/servlet/http/LocalStrings*.properties" />
       <exclude name="org/mortbay/http/*JsseListener*.class" />
       <exclude name="org/mortbay/http/RedirectListener.class" />
       <exclude name="org/mortbay/util/Converter" />
       <exclude name="org/mortbay/util/KeyPairTool.class" />
       <exclude name="org/mortbay/util/TestCase.class" />
       <exclude name="**/jmx" />
       <exclude name="**/ajp" />
       <exclude name="org/mortbay/start/**" />
       <exclude name="org/mortbay/stop/**" />
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Main-Class" value="org.mortbay.http.HttpServer"/>
		<attribute name="Class-Path" value="ext\commons-logging.jar"/>
            </manifest>
    </jar>
  </target>


  <!-- ==================================================================== -->
  <target name="jars" depends="start.jar,stop.jar,servlet.jar,jetty.jar,mortbay.jmx.jar"
   description="Build the jar files" >
  </target>

  <!-- ==================================================================== -->
  <target name="webapps" depends="webapp.jetty"
   description="Build the demonstration webapplications"
   >
    <ant dir="${webapps}/template" antfile="${webapps}/template/build.xml" inheritAll="false"/>
  </target>

  <!-- ==================================================================== -->
  <target name="webapp.jetty" depends="jars" if="demo.available">
    <copy todir="${jetty.webapp.classes}">
      <fileset dir="${demo.src}">
        <include name="**/*.properties" />
      </fileset>
    </copy>
    <copy file="${jetty.webapp.classes}/org/mortbay/webapps/jetty/JettyIndex.properties"
        tofile="${jetty.webapp.classes}/org/mortbay/webapps/jetty/JettyIndex_en.properties" />
    <javac srcdir="${demo.src}"
           destdir="${jetty.webapp.classes}"
           debug="${javac.debug}"
           optimize="${javac.optimize}"
           deprecation="${javac.deprecation}"
           >
      <classpath>
        <path refid="extpath"/>
        <pathelement path="${servlet.jar}" />
        <pathelement path="${jetty.jar}"   />
      </classpath>
      <include name="**/*.java" />
    </javac>

    <copy file="LICENSE.TXT" tofile="${jetty.webapp}/LICENSE.TXT" />
    <copy file="VERSION.TXT" tofile="${jetty.webapp}/versions.txt" />
    <copy file="README.TXT" tofile="${jetty.webapp}/readme.txt" />
  </target>


  <!-- ==================================================================== -->
  <target name="javadoc" depends="jars"
   description="Build the javadoc">
    <mkdir dir="${javadoc}"/>
    <javadoc packagenames="org.mortbay.*,javax.servlet.*"
             destdir="${javadoc}"
             author="true"
             version="true"
             public="false"
             windowtitle="${ant.project.name} ${RELEASE.MAJOR.MINOR} API"
             doctitle="${ant.project.name} ${RELEASE.MAJOR.MINOR}"
             bottom="Copyright &amp;copy; 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.">
       <classpath>
         <path refid="classpath"/> 
         <fileset dir="${extra}">
            <include name="*/classes"/>
            <exclude name="jdk1.2/classes"/>
         </fileset>
       </classpath>
       <sourcepath>
         <pathelement path="${src}"/>  
         <pathelement path="${extra}/plus/src"/> 
         <pathelement path="${extra}/ibmjsse/src"/> 
         <pathelement path="${extra}/loadbalancer/src"/>  
         <pathelement path="${extra}/ftp/src"/>  
       </sourcepath>
    </javadoc>

    <jar jarfile="${webapps}/javadoc.war">
      <fileset dir="${javadoc}">
        <exclude name="**/CVS"/>
      </fileset>
    </jar>

  </target>


  <!-- ==================================================================== -->
  <target name="tests" depends="test"/>
  <target name="test" 
          depends="webapps,javadoc"
          description="Build and run the test harnesses">
    <ant  dir="." antfile="${test}/build.xml" inheritAll="false" target="test"/>
  </target>

  <!-- ==================================================================== -->
  <target name="all" depends="prepare,jars,webapps,javadoc,test"
   description="Build everything"/>

  <!-- ==================================================================== -->
  <target name="demo" depends="webapps" if="demo.available"
   description="Build and run the demo">
    <java jar="${start.jar}"
          dir="${jetty.home}"
          fork="yes"
          failonerror="yes"
          >
       <jvmarg line="${jvmarg}" />
       <arg line="${etc}/admin.xml ${etc}/demo.xml" />
    </java>
  </target>

  <!-- ==================================================================== -->
  <target name="run" depends="classpath"
   description="Run Jetty with configuration set by the jetty.run property">
    <java classname="org.mortbay.jetty.Server"
          dir="${jetty.home}"
          fork="yes"
          failonerror="yes"
          >
       <classpath>
         <pathelement path="${env.CLASSPATH}" />
         <path refid="classpath" />
       </classpath>
       <jvmarg line="${jvmarg}" />
       <arg line="${jetty.run}" />
    </java>
  </target>


  <!-- ==================================================================== -->
  <target name="dist" 
          depends="jars,webapps,extra,javadoc,test,tidy" 
          description="Build the distribution archives">
    <mkdir dir="${dist}"/>
    
    <zip destfile="${dist}/jetty-${RELEASE.MAJOR.MINOR}.zip" >
      <zipfileset 
       dir="${basedir}"
       prefix="jetty-${RELEASE.MAJOR.MINOR}/"> 
        <include name="LICENSE.TXT"/>
        <include name="README.TXT"/>
        <include name="VERSION.TXT"/>
        <include name="*.jar"/>       
        <include name="lib/**"/>       
        <include name="ext/**"/>       
        <include name="logs"/>         
        <include name="webapps/**"/>    
        <include name="etc/LICENSE*"/>   
        <include name="etc/admin.xml"/>  
        <include name="etc/jetty.xml"/>   
        <include name="etc/jetty-jmx.xml"/>  
        <include name="etc/webdefault.xml"/>   
	<include name="extra/lib/*-jdk1.2.jar"/>
        <exclude name="**/CVS/**"/>
      </zipfileset>
    </zip>

    <zip destfile="${dist}/jetty-${RELEASE.MAJOR.MINOR}-extra.zip" >
      <zipfileset 
       dir="${basedir}"
       prefix="jetty-${RELEASE.MAJOR.MINOR}/">   
        <include name="demo/**"/>   
        <include name="extra/**"/>     
        <include name="etc/**"/> 
        <exclude name="etc/jetty.xml"/>  
        <exclude name="etc/webdefault.xml"/>  
        <exclude name="extra/**/src/**"/>  
        <exclude name="**/CVS/**"/>
        <exclude name="**/logs/*.log"/>
      </zipfileset>
    </zip>

    <zip destfile="${dist}/jetty-${RELEASE.MAJOR.MINOR}-src.zip" >
      <zipfileset 
       dir="${basedir}"
       prefix="jetty-${RELEASE.MAJOR.MINOR}/">
        <include name="src/**"/>
        <include name="test/**"/> 
        <include name="extra/**/src/**"/>  
        <include name="build.xml"/>
        <include name="ant.properties"/>
        <exclude name="**/CVS/**"/>
        <exclude name="**/logs/*.log"/>
      </zipfileset>
    </zip>
 
    <zip destfile="${dist}/jetty-${RELEASE.MAJOR.MINOR}-all.zip">
      <zipfileset 
       dir="${basedir}"
       prefix="jetty-${RELEASE.MAJOR.MINOR}/">
        <exclude name="dist/**"/>
        <exclude name="**/CVS/**"/>
        <exclude name="**/logs/*.log"/>
        <exclude name="testdocs/**"/>
	<exclude name=".classpath"/>
	<exclude name=".project"/>
      </zipfileset>
    </zip>

    <copy todir="${dist}">
      <fileset dir="${extra}/j2ee" includes="*.sar"/>
    </copy>  

  </target>

</project>
