<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="jetty">

    <!-- This copies jars, with some modifications and renaming,
         from the jetty-distribution directory to the jettylib directory.
         This is disabled if the property with-libjetty9-java=true.

         This copies jars, with some modifications and renaming,
         from the apache-tomcat-deployer and apache-tomcat directories to the jettylib directory.
         This is disabled if the property with-libservlet2.5-java=true.

         This also builds the small helper jar jetty-i2p.jar from
         the source in the java/ directory.
     -->

    <!-- Note: Change version numbers in top-level build.xml if you update to a new Tomcat or Jetty! -->

    <property name="jetty.branch" value="stable-9" />
    <property name="jetty.base" value="jetty-distribution-${jetty.ver}" />
    <property name="jetty.sha1" value="e9f176730aea36a69c24eeba77dd0880a30492dc" />
    <property name="jetty.filename" value="${jetty.base}.zip" />
    <property name="jetty.url" value="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/${jetty.ver}/${jetty.filename}" />
    <property name="verified.filename" value="verified.txt" />
    <property name="javac.compilerargs" value="" />
    <property name="javac.version" value="1.8" />
    <property name="javac.release" value="8" />
    <property name="manifest.classpath.name" value="Class-Path" />

    <!-- everything we need is in the deployer package, except for tomcat-api.jar in the full package,
         so we just use the full package instead.
      <property name="tomcat.lib" value="apache-tomcat-${tomcat.ver}-deployer/lib" />
     -->
    <property name="tomcat.lib" value="apache-tomcat-${tomcat.ver}/lib" />
    <property name="tomcat.bin" value="apache-tomcat-${tomcat.ver}/bin" />

    <target name="all" depends="build" />

    <!--
      - We now check in the jars we need to ${jetty.base}, so
      - fetchJettylib, verifyJettylib, and extractJettylib are not used unless
      - updating to a new Jetty version by changing ${jetty.ver} and ${jetty.sha1} above.
     -->

    <!-- verify everything we need is in jettylib/ -->
    <target name="ensureJettylib" depends="ensureJettylib1, copyJettylib" />

    <target name="ensureJettylib1" >
        <condition property="jetty.zip.extracted" >
            <or>
                <istrue value="${with-libjetty9-java}" />
                <available file="${jetty.base}" type="dir" />
            </or>
        </condition>
        <condition property="jetty.zip.available" >
            <or>
                <istrue value="${jetty.zip.extracted}" />
                <available file="${jetty.filename}" type="file" />
            </or>
        </condition>
        <condition property="verified.already" >
            <or>
                <istrue value="${with-libjetty9-java}" />
                <istrue value="${jetty.zip.extracted}" />
                <and>
                    <available file="${jetty.filename}" />
                    <uptodate property="foo.bar.baz" srcfile="${jetty.filename}" targetfile="${verified.filename}" />
                </and>
            </or>
        </condition>
    </target>

  <!--
    <target name="ensureJettylib" depends="extractJettylib" />
   -->

    <target name="fetchJettylib" unless="jetty.zip.available" >
        <fail message="Error - jetty.ver property not set - you must run from top level build.xml" >
            <condition>
                <not>
                    <isset property="jetty.ver" />
                </not>
            </condition>
        </fail>
        <echo message="It seems that you don't have '${jetty.filename}' deployed." />
        <echo message="The build script can download this file for you automatically," />
        <echo message="or alternatively you can obtain it manually from:" />
        <echo message="${jetty.url}" />
        <echo message="" />
        <echo message="The libraries contained in the fetched file provide the Jetty web server" />
        <echo message="(http://jetty.mortbay.org/). They are not absolutely necessary" />
        <echo message="but strongly recommended, since they are used by some applications" />
        <echo message="on top of I2P, like the router console." />
        <echo message="" />
        <echo message="Even if you deploy the Jetty archive manually into directory apps/jetty/," />
        <echo message="the build script will still attempt to verify its checksums, which must be:" />
        <echo message="SHA1 ${jetty.sha1}" />
        <echo message="" />
        <input message="Download Jetty archive automatically?" validargs="y,n" addproperty="jetty.download" />
        <fail message="Aborting as requested. Please deploy the Jetty archive manually." >
            <condition>
                <equals arg1="${jetty.download}" arg2="n"/>
            </condition>
        </fail>
        <get src="${jetty.url}" verbose="true" dest="${jetty.filename}" />
    </target>

    <target name="verifyJettylib" depends="fetchJettylib" unless="verified.already" >
        <condition property="jetty.zip.verified" >
                <checksum file="${jetty.filename}" algorithm="SHA" property="${jetty.sha1}" />
        </condition>
        <fail message="Jetty archive does not match its checksum!" >
            <condition>
                <not>
                    <istrue value="${jetty.zip.verified}" />
                </not>
            </condition>
        </fail>
        <touch file="${verified.filename}" />
    </target>

    <target name="extractJettylib" depends="verifyJettylib" unless="jetty.zip.extracted" >
      <!-- for .tgz -->
      <!--
        <gunzip src="${jetty.filename}" dest="jetty.tar" />
        <untar src="jetty.tar" dest="." />
      -->
      <!-- for .zip -->
        <unzip src="${jetty.filename}" dest="." />
    </target>

    <target name="mkJettylibdir" >
        <mkdir dir="jettylib" />
    </target>

    <!-- Jetty and tomcat files -->
    <!--
         We support the following configurations:
           no system jars: Precise, Trusty
           with-libtomcat8-java: Jessie (without backports), Wheezy
           with-libtomcat8-java AND with-libjetty9-java: Xenial, Jessie (with backports), Stretch
           with-libtomcat9-java: Buster
           with-libtomcat9-java AND with-libjetty9-java: Buster
           with-libjetty9-java (only): not supported
     -->
    <target name="copyJettylib" depends="mkJettylibdir, copyJettylib1, copyTomcatLib1, copyJettylib2, copyJettylib3, copyTomcatLib" />

    <!-- Jetty files only -->
    <target name="copyJettylib1" depends="extractJettylib, buildPatches" unless="${with-libjetty9-java}" >
      <!-- We copy everything to names without the version numbers so we
           can update them later. Where there was something similar in Jetty 5/6,
           we use the same names so they will overwrite the Jetty 5/6 jar on upgrade.
           Otherwise we use the same name as the symlink in Ubuntu /usr/share/java.
           Reasons for inclusion:
              start.jar: Needed for clients.config startup of eepsites
              jetty-util-xxx.jar: LifeCycle (base class for stuff), URIUtil (used in i2psnark)
              jetty-deploy, -http, -io, -security, -servlet, -webapp: All split out from main server jar in Jetty 7
              jetty-continuation-xxx.jar: Needed? Useful?
              jetty-servlets-xxx.jar: Needed for CGI for eepsite
              jetty-sslengine-xxx.jar: Old Jetty 6, now a dummy
              jetty-java5-threadpool-xxx.jar: Old Jetty 6, now a dummy
              jetty-rewrite-handler: Not used by I2P, but only 20KB and could be useful for eepsites
              jetty-management: Not used by I2P, but only 34KB and could be useful for eepsites, and we bundled it with Jetty 5
              javax.servlet.jsp-2.2.0.v201112011158.jar: Required API
              servlet-api-3.0.jar: Required API
              All of these are available in the Ubuntu packages libjetty-java and libjetty-extra-java
        -->
        <copy preservelastmodified="true" file="${jetty.base}/start.jar" tofile="jettylib/jetty-start.jar" />
        <copy file="${jetty.base}/lib/jetty-server-${jetty.ver}.jar" tofile="jettylib/org.mortbay.jetty.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-continuation-${jetty.ver}.jar" tofile="jettylib/jetty-continuation.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-deploy-${jetty.ver}.jar" tofile="jettylib/jetty-deploy.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-http-${jetty.ver}.jar" tofile="jettylib/jetty-http.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-io-${jetty.ver}.jar" tofile="jettylib/jetty-io.jar" />
      <!-- comment out above line and uncomment below and the patches section further down if we need patches -->
<!--
        <jar destfile="jettylib/jetty-io.jar"  manifest="${jetty.base}/lib/jetty-io-${jetty.ver}.jar" filesetmanifest="mergewithoutmain" >
            <zipfileset excludes="**/SslConnection*.class" src="${jetty.base}/lib/jetty-io-${jetty.ver}.jar" />
            <zipfileset src="build/jetty-io-patch.jar" />
        </jar>
-->
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-jmx-${jetty.ver}.jar" tofile="jettylib/org.mortbay.jmx.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-rewrite-${jetty.ver}.jar" tofile="jettylib/jetty-rewrite-handler.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-security-${jetty.ver}.jar" tofile="jettylib/jetty-security.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-servlet-${jetty.ver}.jar" tofile="jettylib/jetty-servlet.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-servlets-${jetty.ver}.jar" tofile="jettylib/jetty-servlets.jar" />
<!--
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-util-${jetty.ver}.jar" tofile="jettylib/jetty-util.jar" />
-->
      <!-- comment out above line and uncomment below and the patches section further down if we need patches -->
        <jar destfile="jettylib/jetty-util.jar"  manifest="${jetty.base}/lib/jetty-util-${jetty.ver}.jar" filesetmanifest="mergewithoutmain" >
            <zipfileset excludes="**/JavaVersion.class" src="${jetty.base}/lib/jetty-util-${jetty.ver}.jar" />
            <zipfileset src="build/jetty-util-patch.jar" />
        </jar>

        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-webapp-${jetty.ver}.jar" tofile="jettylib/jetty-webapp.jar" />
        <copy preservelastmodified="true" file="${jetty.base}/lib/jetty-xml-${jetty.ver}.jar" tofile="jettylib/jetty-xml.jar" />
        <jar destfile="jettylib/jetty-java5-threadpool.jar" >
            <manifest>
                <attribute name="Note" value="Intentionally empty" />
            </manifest>
        </jar>
        <jar destfile="jettylib/jetty-sslengine.jar" >
            <manifest>
                <attribute name="Note" value="Intentionally empty" />
            </manifest>
        </jar>
    </target>

    <!--
         Make javax.servlet.jar.
         If with-libtomcat8-java or with-libtomcat9-java but not with-libjetty9-java, we don't do this.
         copyTomcatLib1 dependency to set the with-libtomcat-java variable.
     -->
    <target name="copyJettylib2" depends="extractJettylib, copyTomcatLib1" unless="${with-libtomcat-java}" >
        <jar destfile="jettylib/javax.servlet.jar" duplicate="preserve" filesetmanifest="mergewithoutmain" >
            <!-- all versions - Servlet API -->
          <!--
            <zipfileset excludes="about.html about_files about_files/* META-INF/ECLIPSEF.* META-INF/eclipse.inf plugin.properties" src="${jetty.base}/lib/servlet-api-3.1.jar" />
           -->
            <zipfileset src="${tomcat.lib}/servlet-api.jar" />

          <!--
            Jetty version - see below for why we don't use this one
            <zipfileset excludes="about.html about_files about_files/* META-INF/ECLIPSEF.* META-INF/eclipse.inf plugin.properties" src="${jetty.base}/lib/jsp/javax.servlet.jsp-api-2.3.1.jar" />
           -->

            <!-- Apache in Jetty package version -->
            <!-- Also includes org.apache.*, this is copied into jasper-runtime.jar below -->
            <!-- In Debian packages they are found in /usr/share/java/tomcat8-servlet-api.jar in the libtomcat8-java package -->
            <!-- javax/servlet/jsp/resources are dups of those in apache-jsp jar -->
          <!--
            <zipfileset includes="javax/**/*" src="${jetty.base}/lib/apache-jsp/org.mortbay.jasper.apache-jsp-8.0.33.jar"/>
            <zipfileset excludes="about.html about_files about_files/* META-INF/ECLIPSEF.* META-INF/eclipse.inf plugin.properties javax/servlet/jsp/resources/*" src="${jetty.base}/lib/jetty-schemas-3.1.jar" />
           -->

            <!-- Apache package version -->
            <zipfileset excludes="META-INF/LICENSE META-INF/NOTICE" src="${tomcat.lib}/jsp-api.jar"/>
          <!--
            <zipfileset excludes="about.html about_files about_files/* META-INF/ECLIPSEF.* META-INF/eclipse.inf plugin.properties" src="${jetty.base}/lib/jetty-schemas-3.1.jar" />
           -->
        </jar>
      <!--
        <delete file="jetty.tar" />
        <delete dir="${jetty.base}" />
      -->
    </target>

    <!-- Copy jetty-apache-jsp.jar -->
    <!-- ONLY if with-libtomcat8-java but NOT with-libjetty9-java (wheezy/jessie configuration) -->
    <!-- If neither with-libtomcat8-java nor with-libjetty9-java, it's merged into jasper-runtime.jar in the copyTomcatLib2 target below -->
    <target name="copyJettylib3" depends="extractJettylib, copyTomcatLib1" if="${with-libtomcat-without-libjetty}" >
            <copy preservelastmodified="true" file="${jetty.base}/lib/apache-jsp/org.eclipse.jetty.apache-jsp-${jetty.ver}.jar" tofile="jettylib/jetty-apache-jsp.jar" />
    </target>

    <!-- Tomcat.
         The glassfish jars bundled in Jetty 6 are way too old.
         For compatibility with very old I2P installations where the classpath
         was set individually in wrapper.config, we rename and combine the jars as follows:
         jasper.jar : jasper-runtime.jar
         jasper-el.jar + el-api.jar : commons-el.jar
         tomcat-juli.jar : Add to jasper-runtime.jar
         empty jar : jasper-compiler.jar
         Also, take NOTICE and LICENSE out of each one, we bundle those separately.

         Not as of Jetty 8 (using from Jetty):
         servlet-api.jar + jsp-api.jar : javax.servlet.jar
         If we go to Tomcat 7:
         tomcat-api.jar + tomcat-util.jar: Add to javax.servlet.jar (as of Tomcat 7 / Jetty 8)
     -->
    <target name="copyTomcatLib" depends="mkJettylibdir, copyTomcatLib1, copyTomcatLib2, copyTomcatLib3" />

    <target name="copyTomcatLib1" >
        <condition property="with-libtomcat-java" >
            <or>
                <istrue value="${with-libtomcat6-java}" />
                <istrue value="${with-libtomcat7-java}" />
                <istrue value="${with-libtomcat8-java}" />
                <istrue value="${with-libtomcat9-java}" />
            </or>
        </condition>
        <condition property="with-libtomcat-without-libjetty" >
            <and>
                <istrue value="${with-libtomcat-java}" />
                <not>
                    <istrue value="${with-libjetty9-java}" />
                </not>
            </and>
        </condition>
    </target>


    <!-- Make commons-el.jar and jasper-runtime.jar -->
    <target name="copyTomcatLib2" unless="${with-libtomcat-java}" >
        <!-- EL API and compiler libs.
             Tomcat 6 has EL 2.1.
             Tomcat 7 / libservlet3.0 has EL 2.2.
             Jetty 9 / Tomcat 8 / libservlet3.1 has EL 3.0.
             According to http://stackoverflow.com/questions/7202686/differences-between-el-2-1-and-2-2
             2.2 is backwards-compatible with 2.1.
         -->
        <!-- the javax.el API, AND the com.sun.el parser -->
        <!-- actually from jetty9, not tomcat8... this will fail unless we have the jetty files also -->
        <jar destfile="jettylib/commons-el.jar" duplicate="preserve" filesetmanifest="mergewithoutmain">
          <!--
            Jetty version
            <zipfileset src="${jetty.base}/lib/jsp/javax.el-3.0.0.jar"/>
           -->

            <!-- Apache in Jetty package version -->
          <!--
            <zipfileset src="${jetty.base}/lib/apache-jsp/org.mortbay.jasper.apache-el-${tomcat.ver}.jar"/>
           -->

            <!-- Apache package version -->
            <zipfileset excludes="META-INF/LICENSE META-INF/NOTICE" src="${tomcat.lib}/el-api.jar"/>
            <zipfileset excludes="META-INF/LICENSE META-INF/NOTICE" src="${tomcat.lib}/jasper-el.jar"/>
        </jar>

        <!-- actually from jetty9, not tomcat8... this will fail unless we have the jetty files also -->
        <jar destfile="jettylib/jasper-runtime.jar" duplicate="preserve" filesetmanifest="mergewithoutmain" >
          <!--
            Jetty version
            <zipfileset src="${jetty.base}/lib/jsp/javax.servlet.jsp-2.3.2.jar"/>
            To be included in jasper-runtime.jar?
            Server complains "NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet" even with this included (but it still works).
            The following file has the class, but /usr/share/java/jetty8-jsp.jar is empty
            We don't use this one, because we want to be consistent with Debian builds that
            must use Apache (aka libtomcat8).
            <zipfileset excludes="about.html about_files about_files/* META-INF/ECLIPSEF.* META-INF/eclipse.inf plugin.properties" src="${jetty.base}/lib/jsp/jetty-jsp-${jetty.ver}.jar" />
           -->

            <!-- For both Apache in Jetty package and Apache package versions -->
            <!-- required Jetty initializer (see RouterConsoleRunner) -->
            <zipfileset src="${jetty.base}/lib/apache-jsp/org.eclipse.jetty.apache-jsp-${jetty.ver}.jar"/>

            <!-- Apache in Jetty package version -->
            <!-- Also includes javax.servlet.jsp.*, this is copied into javax.servlet.jar above -->
          <!--
            <zipfileset src="${jetty.base}/lib/apache-jsp/org.mortbay.jasper.apache-jsp-${jetty.ver}.jar"/>
           -->

            <!-- Apache package version -->
            <!-- we match what was bundled in the Jetty package version -->
            <!-- except we need compat/ as of 8.5.29 or JspC fails in the jar scan -->
            <zipfileset excludes="META-INF/LICENSE META-INF/NOTICE" src="${tomcat.lib}/jasper.jar"/>
            <zipfileset excludes="META-INF/LICENSE META-INF/NOTICE" src="${tomcat.lib}/tomcat-api.jar"/>
            <zipfileset includes="org/apache/juli/logging/**/*" src="${tomcat.bin}/tomcat-juli.jar"/>
            <zipfileset excludes="META-INF/LICENSE META-INF/NOTICE org/apache/tomcat/util/codec/ org/apache/tomcat/util/threads/" src="${tomcat.lib}/tomcat-util.jar"/>
            <zipfileset excludes="META-INF/LICENSE META-INF/NOTICE" src="${tomcat.lib}/tomcat-util-scan.jar"/>
        </jar>

        <jar destfile="jettylib/commons-logging.jar" update="true" >
            <manifest>
                <attribute name="Note" value="Intentionally empty" />
            </manifest>
        </jar>
    </target>

    <target name="copyTomcatLib3" unless="${with-libtomcat-java}" >
        <jar destfile="jettylib/jasper-compiler.jar" >
            <manifest>
                <attribute name="Note" value="Intentionally empty" />
            </manifest>
        </jar>
    </target>

    <target name="build" depends="jar" />

    <target name="builddep" />

    <condition property="depend.available">
        <typefound name="depend" />
    </condition>

    <target name="depend" if="depend.available">
        <depend
            cache="../../build"
            srcdir="./java/src" 
            destdir="./build/obj" >
            <classpath>
                <pathelement location="../../core/java/build/i2p.jar" />
                <pathelement location="./jettylib/org.mortbay.jetty.jar" />
                <pathelement location="./jettylib/jasper-runtime.jar" />
                <pathelement location="./jettylib/javax.servlet.jar" />
                <pathelement location="./jettylib/jetty-deploy.jar" />
                <pathelement location="./jettylib/jetty-http.jar" />
                <pathelement location="./jettylib/jetty-io.jar" />
                <pathelement location="./jettylib/jetty-security.jar" />
                <pathelement location="./jettylib/jetty-servlet.jar" />
                <pathelement location="./jettylib/jetty-util.jar" />
                <pathelement location="./jettylib/jetty-webapp.jar" />
                <pathelement location="./jettylib/jetty-xml.jar" />
            </classpath>
        </depend>
    </target>

    <target name="compile" depends="builddep, ensureJettylib, depend" >
        <mkdir dir="./build" />
        <mkdir dir="./build/obj" />
        <javac 
            srcdir="./java/src" 
            debug="true" deprecation="on" source="${javac.version}" target="${javac.version}" 
            release="${javac.release}"
            destdir="./build/obj" 
            encoding="UTF-8"
            includeAntRuntime="false" >
            <classpath>
                <pathelement location="../../core/java/build/i2p.jar" />
                <pathelement location="./jettylib/jasper-runtime.jar" />
                <pathelement location="./jettylib/javax.servlet.jar" />
                <pathelement location="./jettylib/jetty-deploy.jar" />
                <pathelement location="./jettylib/jetty-http.jar" />
                <pathelement location="./jettylib/jetty-io.jar" />
                <pathelement location="./jettylib/jetty-security.jar" />
                <pathelement location="./jettylib/jetty-servlet.jar" />
                <pathelement location="./jettylib/jetty-util.jar" />
                <pathelement location="./jettylib/jetty-webapp.jar" />
                <pathelement location="./jettylib/jetty-xml.jar" />
                <pathelement location="./jettylib/org.mortbay.jetty.jar" />
                <!-- following jar only present for debian builds -->
                <pathelement location="./jettylib/tomcat-api.jar" />
            </classpath>
            <compilerarg line="${javac.compilerargs}" />
        </javac>
    </target>

    <target name="listChangedFiles" depends="jarUpToDate" if="shouldListChanges" >
        <exec executable="git" outputproperty="workspace.changes" errorproperty="mtn.error2" failifexecutionfails="false" >
            <arg value="status" />
            <arg value="-s" />
            <arg value="--porcelain" />
            <arg value="-uno" />
            <arg value="." />
        </exec>
        <!-- trim flags -->
        <exec executable="sed" inputstring="${workspace.changes}" outputproperty="workspace.changes.sed" errorproperty="mtn.error2" failifexecutionfails="false" >
            <arg value="-e" />
            <arg value="s/^[MTADRCU ]*//" />
        </exec>
        <!-- \n in an attribute value generates an invalid manifest -->
        <exec executable="tr" inputstring="${workspace.changes.sed}" outputproperty="workspace.changes.tr" errorproperty="mtn.error2" failifexecutionfails="false" >
            <arg value="-s" />
            <arg value="[:space:]" />
            <arg value="," />
        </exec>
    </target>

    <!-- With Jetty 5 we replaced classes in the jar, but with Jetty 6 we
         put our stuff in its own jar so we can work with standard Jetty 6 packages
      -->
    <target name="jar" depends="compile, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
        <!-- set if unset -->
        <property name="workspace.changes.tr" value="" />
        <copy todir="build/obj" file="resources/log4j.properties" />
        <jar destfile="./jettylib/jetty-i2p.jar" basedir="./build/obj" includes="**/*.class log4j.properties" >
            <manifest>
                <attribute name="Implementation-Version" value="${full.version}" />
                <attribute name="Built-By" value="${build.built-by}" />
                <attribute name="Build-Date" value="${build.timestamp}" />
                <attribute name="Base-Revision" value="${workspace.version}" />
                <!-- needed by JettyStart for pre-0.7.5 wrapper.config -->
                <attribute name="${manifest.classpath.name}" value="jetty-deploy.jar jetty-xml.jar" />
                <attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
                <attribute name="X-Compile-Source-JDK" value="${javac.version}" />
                <attribute name="X-Compile-Target-JDK" value="${javac.version}" />
            </manifest>
        </jar>
    </target>    

    <target name="jarUpToDate">
        <uptodate property="jar.uptodate" targetfile="jettylib/jetty-i2p.jar" >
            <srcfiles dir= "build/obj" includes="**/*.class" />
            <srcfiles dir= "resources" />
        </uptodate>
        <condition property="shouldListChanges" >
            <and>
                <not>
                    <isset property="jar.uptodate" />
                </not>
                <isset property="git.available" />
            </and>
        </condition>
    </target>    

    <!-- empty, uncomment below if needed -->
<!--
    <target name="buildPatches" unless="${with-libjetty9-java}" />
-->

    <target name="buildPatches" depends="jarPatches" unless="${with-libjetty9-java}" />

    <target name="compilePatches" unless="${with-libjetty9-java}" >
        <mkdir dir="./build" />
        <mkdir dir="./build/objPatches" />
        <javac 
            srcdir="./patches/jetty-util/src/main/java" 
            debug="true" deprecation="on" source="${javac.version}" target="${javac.version}" 
            release="${javac.release}"
            destdir="./build/objPatches" 
            includeAntRuntime="false"
            encoding="UTF-8"
            classpath="" >
            <compilerarg line="${javac.compilerargs}" />
        </javac>
<!--
        <mkdir dir="./build/objPatches2" />
        <javac 
            srcdir="./patches/jetty-io/src/main/java" 
            debug="true" deprecation="on" source="${javac.version}" target="${javac.version}" 
            release="${javac.release}"
            destdir="./build/objPatches2" 
            includeAntRuntime="false"
            encoding="UTF-8" >
            <compilerarg line="${javac.compilerargs}" />
            <classpath>
                <pathelement location="${jetty.base}/lib/jetty-io-${jetty.ver}.jar" />
                <pathelement location="${jetty.base}/lib/jetty-util-${jetty.ver}.jar" />
            </classpath>
        </javac>
-->
    </target>

    <target name="jarPatches" depends="compilePatches, jarPatchesUpToDate" unless="jarPatches.uptodate" >
        <jar destfile="./build/jetty-util-patch.jar" basedir="./build/objPatches" includes="**/*.class" />
<!--
        <jar destfile="./build/jetty-io-patch.jar" basedir="./build/objPatches2" includes="**/*.class" />
-->
    </target>    

    <target name="jarPatchesUpToDate" >
        <condition property="jarPatches.uptodate" >
            <or>
                <equals arg1="${with-libjetty9-java}" arg2="true" />
                <uptodate property="jarPatches.uptodate" targetfile="jettylib/jetty-i2p.jar" >
                    <srcfiles dir= "build/objPatches" includes="**/*.class" />
<!--
                    <srcfiles dir= "build/objPatches2" includes="**/*.class" />
-->
                </uptodate>
            </or>
        </condition>
    </target>    

    <target name="clean" >
        <delete dir="./build" />
        <delete file="${verified.filename}" />
    </target>    
    <target name="cleandep" depends="clean" />
    <target name="distclean" depends="clean">
        <delete dir="./jettylib" />
      <!--
        <echo message="Not actually deleting the jetty libs (since they're so large)" />
       -->
    </target>
    <target name="reallyclean" depends="distclean">
    </target>
    <target name="totallyclean" depends="clean">
        <delete dir="./jettylib" />
        <delete file="${jetty.filename}" />
    </target>
    <target name="javadoc" >
        <available property="jetty.zip.available" file="${jetty.filename}" type="file" />
        <available property="jetty.zip.javadocExtracted" file="build/javadoc" type="dir" />
        <ant target="fetchJettylib" />
        <ant target="verifyJettylib" />
        <ant target="extractJavadoc" />
    </target>
    <target name="extractJavadoc" unless="jetty.zip.javadocExtracted" >
        <mkdir dir="./build" />
        <mkdir dir="./build/javadoc" />
        <unzip src="${jetty.filename}" dest="./build/javadoc" >
            <patternset>
                <include name="${jetty.base}/javadoc/" />
            </patternset>
            <mapper type="glob" from="${jetty.base}/javadoc/*" to="javadoc/*" />
        </unzip>
    </target>

    <!-- for Maven Central -->
    <target name="servletJar" depends="compile" >
        <!-- set if unset -->
        <jar destfile="./build/servlet-i2p-${release.number}.jar" basedir="./build/obj" includes="net/i2p/servlet/filters/*.class" >
            <manifest>
                <attribute name="Specification-Title" value="I2P Servlet classes" />
                <attribute name="Specification-Version" value="${api.version}" />
                <attribute name="Specification-Vendor" value="The I2P Project https://geti2p.net/" />
                <attribute name="Implementation-Title" value="I2P Java Servlet classes" />
                <attribute name="Implementation-Version" value="${full.version}" />
                <attribute name="Implementation-Vendor" value="The I2P Project https://geti2p.net/" />
                <attribute name="Built-By" value="${build.built-by}" />
                <attribute name="Build-Date" value="${build.timestamp}" />
                <attribute name="Base-Revision" value="${workspace.version}" />
                <attribute name="X-Compile-Source-JDK" value="${javac.version}" />
                <attribute name="X-Compile-Target-JDK" value="${javac.version}" />
            </manifest>
        </jar>
    </target>    

    <target name="servletJavadoc">
        <mkdir dir="./build" />
        <mkdir dir="./build/servlet-i2p-javadoc" />
        <javadoc access="package"
            source="${javac.version}"
            destdir="./build/servlet-i2p-javadoc"
            packagenames="*"
            use="true"
            splitindex="true"
            failonerror="true"
            additionalparam="-notimestamp"
            doctitle="I2P Javadocs for Release ${release.number} Build ${i2p.build.number}${build.extra}"
            windowtitle="I2P Anonymous Network - Java Documentation - Version ${release.number}">
            <group title="Jetty Utilities" packages="*" />
            <sourcepath>
                <pathelement location="./java/src" />
            </sourcepath>
            <classpath>
                <pathelement location="../../core/java/build/i2p.jar" />
                <pathelement location="./jettylib/org.mortbay.jetty.jar" />
                <pathelement location="./jettylib/javax.servlet.jar" />
                <pathelement location="./jettylib/jasper-runtime.jar" />
                <pathelement location="./jettylib/jetty-deploy.jar" />
                <pathelement location="./jettylib/jetty-http.jar" />
                <pathelement location="./jettylib/jetty-io.jar" />
                <pathelement location="./jettylib/jetty-security.jar" />
                <pathelement location="./jettylib/jetty-servlet.jar" />
                <pathelement location="./jettylib/jetty-util.jar" />
                <pathelement location="./jettylib/jetty-webapp.jar" />
                <pathelement location="./jettylib/jetty-xml.jar" />
                <!-- following are only for debian builds -->
                <pathelement location="../../core/java/build/libintl.jar" />
                <pathelement location="../../core/java/build/gnu-getopt.jar" />
                <pathelement location="../../core/java/build/json-simple.jar" />
                <pathelement location="./jettylib/tomcat-api.jar" />
            </classpath>
            <!-- These variables are stored in build.properties.
                  End-users can override by creating the file override.properties -->
            <link offline="true" href="${javasedocs.url}" packagelistLoc="../../installer/resources/package-lists/java/" />
            <link offline="true" href="${javaeedocs.url}" packagelistLoc="../../installer/resources/package-lists/javaee/" />
            <link offline="true" href="${jettydocs.url}" packagelistLoc="../../installer/resources/package-lists/jetty/" />
            <link offline="true" href="${wrapperdocs.url}" packagelistLoc="../../installer/resources/package-lists/wrapper/" />
        </javadoc>
    </target>

    <target name="servletJavadocJar" depends="servletJavadoc">
        <jar jarfile="./build/servlet-i2p-${release.number}-javadoc.jar">
            <fileset dir="./build/servlet-i2p-javadoc" />
            <manifest>
                <attribute name="Specification-Title" value="I2P Servlet classes" />
                <attribute name="Specification-Version" value="${api.version}" />
                <attribute name="Specification-Vendor" value="The I2P Project https://geti2p.net/" />
                <attribute name="Implementation-Title" value="I2P Java Servlet classes" />
                <attribute name="Implementation-Version" value="${full.version}" />
                <attribute name="Implementation-Vendor" value="The I2P Project https://geti2p.net/" />
                <attribute name="Built-By" value="${build.built-by}" />
                <attribute name="Build-Date" value="${build.timestamp}" />
                <attribute name="Base-Revision" value="${workspace.version}" />
            </manifest>
        </jar>
    </target>

    <target name="servletSourcesJar">
        <jar jarfile="./build/servlet-i2p-${release.number}-sources.jar">
            <fileset dir="./java/src" includes="net/i2p/servlet/filters/**" />
            <manifest>
                <attribute name="Specification-Title" value="I2P Servlet classes" />
                <attribute name="Specification-Version" value="${api.version}" />
                <attribute name="Specification-Vendor" value="The I2P Project https://geti2p.net/" />
                <attribute name="Implementation-Title" value="I2P Java Servlet classes" />
                <attribute name="Implementation-Version" value="${full.version}" />
                <attribute name="Implementation-Vendor" value="The I2P Project https://geti2p.net/" />
                <attribute name="Built-By" value="${build.built-by}" />
                <attribute name="Build-Date" value="${build.timestamp}" />
                <attribute name="Base-Revision" value="${workspace.version}" />
            </manifest>
        </jar>
    </target>

</project>
