<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You 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.
-->
<project default="all" basedir="." name="xmlgraphics-commons">

  <!-- See build.properties and build-local.properties for overriding build settings. -->
  <!-- build-local.properties is not stored in SVN and overrides values from build.properties -->
  <property environment="env"/>
  <property file="${basedir}/build-local.properties"/>
  <property file="${basedir}/build.properties"/>

  <property name="Name" value="Apache XML Graphics Commons"/>
  <property name="name" value="xmlgraphics-commons"/>
  <property name="year" value="1999-2024"/>

  <property name="javac.debug" value="on"/>
  <property name="javac.optimize" value="off"/>
  <property name="javac.deprecation" value="on"/>
  <property name="javac.source" value="1.8"/>
  <property name="javac.target" value="1.8"/>
  <property name="javac.fork" value="no"/>

  <property name="junit.fork" value="on"/>
  <property name="junit.haltonfailure" value="off"/>
  <property name="junit.printsummary" value="off"/>
  <property name="junit.formatter.brief" value="on"/>

  <property name="javadoc.packages" value="org.apache.xmlgraphics.*"/>
  
  <property name="internal-codecs.disabled" value="false"/>
  
  <property name="src.dir" value="${basedir}/src/main"/>
  <property name="src.java.dir" value="${src.dir}/java"/>
  <property name="src.res.dir" value="${src.dir}/resources"/>
  <property name="lib.dir" value="${basedir}/lib"/>
  <property name="optional.lib.dir" value="${lib.dir}/build" />

  <property name="test.dir" value="${basedir}/src/test"/>
  <property name="test.java.dir" value="${test.dir}/java"/>
  <property name="test.res.dir" value="${test.dir}/resources"/>

  <property name="tools.dir" value="${basedir}/src/tools"/>
  <property name="tools.checkstyle.dir" value="${tools.dir}/resources/checkstyle"/>
  <property name="tools.findbugs.dir" value="${tools.dir}/resources/findbugs"/>

  <property name="build.dir" value="${basedir}/build"/>
  <property name="build.classes.dir" value="${build.dir}/classes"/>
  <property name="build.javadocs.dir" value="${build.dir}/javadocs"/>
  
  <property name="dist.bin.dir" value="${basedir}/dist-bin"/>
  <property name="dist.src.dir" value="${basedir}/dist-src"/>
  <property name="dist.bin.result.dir" value="${dist.bin.dir}/${name}-${version}"/>
  <property name="dist.src.result.dir" value="${dist.src.dir}/${name}-${version}"/>
  <property name="samedir" value="${basedir}"/>

  <!-- .NET support (using IKVM) -->
  <property name="ikvm.dir" value="."/>
  <property name="ikvmc" value="${ikvm.dir}/bin/ikvmc.exe"/>
  
  <property name="copy.dependencies.arg" value=""/>
  
  <condition property="isWindows">
    <os family="windows" />
  </condition>
  <condition property="isUnix">
    <os family="unix" />
  </condition>  

  <tstamp>
    <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
  </tstamp>

  <path id="libs-build-classpath">
    <fileset dir="${lib.dir}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${lib.dir}/build">
      <include name="*.jar"/>
    </fileset>
  </path>

  <path id="libs-run-classpath">
    <path refid="libs-build-classpath"/>
    <fileset dir="${build.dir}">
      <include name="${name}.jar"/>
    </fileset>
  </path>

  <fileset dir="${basedir}" id="dist.bin">
    <include name="examples/**"/>
    <include name="LICENSE"/>
    <include name="NOTICE"/>
    <include name="README"/>
    <include name="KEYS"/>
    <include name="status.xml"/>
  </fileset>

  <fileset dir="${basedir}" id="dist.bin.lib">
    <patternset id="dist.lib">
      <include name="lib/commons-io*"/>
      <include name="lib/commons-logging*"/>
      <include name="lib/README*"/>
    </patternset>
  </fileset>

  <fileset dir="${basedir}" id="dist.src.lib.build">
    <patternset id="dist.lib.build">
      <include name="lib/build/hamcrest.core*"/>
      <include name="lib/build/mockito-core*"/>
      <include name="lib/build/objenesis*"/>
      <include name="lib/build/resolver*"/>
    </patternset>
  </fileset>

  <fileset dir="${basedir}" id="dist.src">
    <include name="src/**"/>
    <include name="test/**"/>
    <patternset refid="dist.lib"/>
    <patternset refid="dist.lib.build"/>
    <include name="examples/**"/>
    <include name="LICENSE"/>
    <include name="NOTICE"/>
    <include name="README"/>
    <include name="KEYS"/>
    <include name="status.xml"/>
    <include name="*.pom"/>
    <include name="pom.xml"/>
    <include name="build.*"/>
    <include name="checkstyle*"/>
    <exclude name="checkstyle-noframes.xsl"/>
  </fileset>

  <!-- =================================================================== -->
  <!-- Initialization target                                               -->
  <!-- =================================================================== -->
  <target name="info">
    <echo message="------------------- ${Name} ${version} [${year}] ----------------"/>
    <echo message="See build.properties and build-local.properties for additional build settings"/>
    <echo message="${ant.version}"/>
    <echo message="VM: ${java.vm.version}, ${java.vm.vendor}"/>
    <echo message="JAVA_HOME: ${env.JAVA_HOME}"/>
  </target>
  
  <target name="init" depends="info, init-avail"/>

  <target name="init-avail">
    <available property="jdk15.present" classname="java.lang.StringBuilder"/>
    <fail message="${Name} requires at least Java 1.5" unless="jdk15.present"/>
    
    <condition property="internal-codecs.eff.disabled">
      <equals arg1="${internal-codecs.disabled}" arg2="true"/>
    </condition>

    <available property="junit.present" classname="junit.framework.TestCase"
        classpathref="libs-build-classpath"/>
    <condition property="junit.message" value="JUnit Support PRESENT">
      <equals arg1="${junit.present}" arg2="true"/>
    </condition>
    <condition property="junit.message" value="JUnit Support NOT Present - Committers are required to have JUnit working">
      <not>
        <equals arg1="${junit.present}" arg2="true"/>
      </not>
    </condition>
    <echo message="${junit.message}"/>

    <condition property="IKVM.present">
      <and>
        <available file="${ikvmc}"/>
        <equals arg1="${internal-codecs.eff.disabled}" arg2="true"/>
      </and>
    </condition>
    <condition property="ikvm.message" value="IKVM Support PRESENT and ENABLED">
      <equals arg1="${IKVM.present}" arg2="true"/>
    </condition>
    <condition property="ikvm.message" value="IKVM Support NOT Present">
      <not>
        <available file="${ikvmc}"/>
      </not>
    </condition>
    <condition property="ikvm.message" value="IKVM Support DISABLED">
      <not>
        <equals arg1="${IKVM.present}" arg2="true"/>
      </not>
    </condition>
    <echo message="${ikvm.message}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Help on usage                                                       -->
  <!-- =================================================================== -->
  <target name="usage">
    <echo message="Use the -projecthelp option instead"/>
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source directory                                       -->
  <!-- =================================================================== -->
  <target name="compile" depends="compile-java, compile-copy-resources" description="Compiles the source code"/>

  <target name="compile-copy-resources" description="Copies the resource files into the build directory">
    <mkdir dir="${build.classes.dir}"/>
    <copy todir="${build.classes.dir}">
      <fileset dir="${src.res.dir}"/>
    </copy>
  </target>

  <target name="compile-pattern-with-codecs" depends="init" unless="internal-codecs.eff.disabled">
    <echo message="Internal codecs will be compiled."/>
    <patternset id="compile-pattern">
      <include name="**/*.java"/>
    </patternset>
  </target>
  <target name="compile-pattern-without-codecs" depends="init" if="internal-codecs.eff.disabled">
    <echo message="Internal codecs will be skipped."/>
    <patternset id="compile-pattern">
      <include name="**/*.java"/>
      <exclude name="**/image/codec/tiff/**/*.java"/>
      <exclude name="**/image/writer/internal/TIFFImageWriter*.java"/>
    </patternset>
  </target>
  <target name="compile-java" depends="init, compile-pattern-with-codecs, compile-pattern-without-codecs">
    <!-- create directories -->
    <mkdir dir="${build.classes.dir}"/>
    <javac destdir="${build.classes.dir}" fork="${javac.fork}" debug="${javac.debug}"
           deprecation="${javac.deprecation}" optimize="${javac.optimize}"
           source="${javac.source}" target="${javac.target}" includeAntRuntime="true">
      <src path="${src.java.dir}"/>
      <patternset refid="compile-pattern"/>
      <classpath refid="libs-build-classpath"/>
      <compilerarg value="-Xlint:cast"/>
    </javac>
  </target>

  <!-- =================================================================== -->
  <!-- Creates JAR files                                                   -->
  <!-- =================================================================== -->

  <target name="uptodate-jar-main" depends="compile">
    <uptodate property="jar.main.uptodate" targetfile="${build.dir}/${name}.jar">
      <srcfiles dir= "${build.classes.dir}"/>
    </uptodate>
  </target>

  <target name="jar-main" depends="compile,uptodate-jar-main" description="Generates the main jar file" unless="jar.main.uptodate">
    <jar jarfile="${build.dir}/${name}-${version}.jar" basedir="${build.classes.dir}">
      <manifest>
        <attribute name="Implementation-Title" value="${Name}"/>
        <attribute name="Implementation-Version" value="${version}"/>
        <attribute name="Implementation-Vendor" value="The Apache Software Foundation (http://xmlgraphics.apache.org/)"/>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>

  <target name="package.NET" depends="jar-main" if="IKVM.present" description="Generates the .NET DLL using IKVM">
    <property name="commons-io" value="commons-io-1.1"/>
    <exec executable="${ikvmc}">
      <arg value="-reference:${ikvm.dir}/bin/IKVM.GNU.Classpath.dll"/>
      <arg value="-target:library"/>
      <arg value="-out:${build.dir}\${commons-io}.dll"/>
      <arg value="${lib.dir}\${commons-io}.jar"/>
    </exec>
    <exec executable="${ikvmc}">
      <arg value="-reference:${ikvm.dir}/bin/IKVM.GNU.Classpath.dll"/>
      <arg value="-reference:${build.dir}/${commons-io}.dll"/>
      <!--arg value="-reference:${ikvm.dir}/bin/IKVM.AWT.WinForms.dll"/-->
      <arg value="-target:library"/>
      <arg value="-out:${build.dir}\${name}-${version}.dll"/>
      <arg value="${build.dir}\${name}-${version}.jar"/>
    </exec>
  </target>

  <target name="uptodate-jar-sources" depends="init">
    <uptodate property="jar.sources.uptodate" targetfile="${build.dir}/${name}-${version}-sources.jar">
      <srcfiles dir="${src.java.dir}"/>
    </uptodate>
  </target>

  <target name="jar-sources" depends="uptodate-jar-sources" description="Generates a jar file with all the sources" unless="jar.sources.uptodate">
    <patternset id="java-only">
      <include name="**/*.java"/>
    </patternset>
    <jar jarfile="${build.dir}/${name}-${version}-sources.jar">
      <manifest>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <fileset dir="${src.java.dir}">
        <patternset refid="java-only"/>
      </fileset>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>

  <target name="package" depends="mvn-jars,jar-main, package.NET" description="Generates the jar files"/>
  
  <target name="mvn-jars" depends="mvn-jars-unix,mvn-jars-windows" unless="dev">
    <delete failonerror="false">
      <fileset dir="${basedir}/lib">
        <include name="*.jar"/>
        <exclude name="checkstyle*.jar"/>
      </fileset>
    </delete>
    <copy todir="${basedir}/lib">
      <fileset dir="${basedir}/target/dependency">
        <include name="*.jar"/>
      </fileset>
    </copy>
  </target>
  <target name="mvn-jars-unix" if="isUnix" unless="dev">
    <exec executable="mvn" dir="${basedir}" failonerror="true">
      <arg value="clean"/>
      <arg line="${copy.dependencies.arg} dependency:copy-dependencies -DskipTests"/>
    </exec>
  </target>
  <target name="mvn-jars-windows" if="isWindows" unless="dev">
    <exec executable="cmd" dir="${basedir}" failonerror="true">
	  <arg value="/c"/>
	  <arg value="mvn"/>    
      <arg value="clean"/>
      <arg line="${copy.dependencies.arg} dependency:copy-dependencies -DskipTests"/>
    </exec>
  </target>   

  <!-- =================================================================== -->
  <!-- Testing                                                             -->
  <!-- =================================================================== -->
  <target name="junit-init" depends="init-avail">
    <condition property="junit.formatter.brief.use">
      <istrue value="${junit.formatter.brief}"/>
    </condition>
  </target>
  <target name="junit-compile" depends="package,junit-init" if="junit.present">
    <mkdir dir="${build.dir}/test-classes"/>
    <mkdir dir="${build.dir}/test-reports"/>
    <javac destdir="${build.dir}/test-classes" fork="${javac.fork}"
           debug="${javac.debug}" deprecation="${javac.deprecation}"
           optimize="${javac.optimize}" source="${javac.source}"
           target="${javac.target}" includeAntRuntime="true">
      <src path="${test.java.dir}"/>
      <patternset refid="compile-pattern"/>
      <classpath>
        <path refid="libs-build-classpath"/>
        <fileset dir="${build.dir}">
          <include name="${name}-${version}.jar"/>
        </fileset>
      </classpath>
      <compilerarg value="-Xlint:cast"/>
    </javac>
    <copy todir="${build.dir}/test-classes" includeEmptyDirs="false">
      <fileset dir="${test.res.dir}"/>
      <fileset dir="${test.java.dir}">
        <exclude name="**/*.java"/>
        <exclude name="**/*.html"/>
      </fileset>
    </copy>
  </target>
  <target name="junit-basic" depends="junit-compile" description="Runs the standard JUnit test suite" if="junit.present">
    <echo message="Running basic functionality tests"/>
    <junit haltonerror="no" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="test.junit.error" failureproperty="test.junit.failure" printsummary="${junit.printsummary}">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <jvmarg value="-enableassertions"/>
      <formatter type="brief" usefile="false" if="junit.formatter.brief.use"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-build-classpath"/>
        <fileset dir="build">
          <include name="${name}-${version}.jar"/>
        </fileset>
      </classpath>
      <batchtest fork="${junit.fork}" todir="${build.dir}/test-reports">
        <fileset dir="${test.java.dir}">
          <include name="**/*Test*.java"/>
          <exclude name="**/*TestSuite.java"/>
          <exclude name="**/image/writer/internal/TIFFImageWriter*.java" if="internal-codecs.eff.disabled"/>
        </fileset>
      </batchtest>
    </junit>
  </target>

  <target name="junit" depends="junit-basic" description="Runs all JUnit tests" if="junit.present">
    <fail>
      <condition>
        <or>
          <isset property="test.junit.error"/>
          <isset property="test.junit.failure"/>
        </or>
      </condition>
NOTE:
**************************************************************************
* One or more of the Junit tests had Failures or Errors or were skipped! *
*         Please check the output above for relevant messages.           *
**************************************************************************
    </fail>
    <echo>All Junit tests passed!</echo>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation                                       -->
  <!-- =================================================================== -->
  <target name="javadocs" depends="init" description="Generates javadocs">
    <property name="javadoc.public"  value="false"/>
    <property name="javadoc.package" value="false"/>
    <property name="javadoc.private" value="false"/>
    <condition property="javadoc.level" value=" (level: private)">
      <equals arg1="${javadoc.private}" arg2="true"/>
    </condition>
    <condition property="javadoc.level" value=" (level: package)">
      <equals arg1="${javadoc.package}" arg2="true"/>
    </condition>
    <condition property="javadoc.level" value=" (level: public)">
      <equals arg1="${javadoc.public}" arg2="true"/>
    </condition>
    <property name="javadoc.level" value=""/>
    <echo message="Producing the javadoc files${javadoc.level}"/>
    <mkdir dir="${build.javadocs.dir}"/>

    <javadoc
        packagenames="${javadoc.packages}"
        destdir="${build.javadocs.dir}"
        author="true"
        version="true"
        windowtitle="${Name} ${version} API"
        doctitle="Apache XML Graphics Commons"
        bottom="Copyright ${year} The Apache Software Foundation. All Rights Reserved."
        overview="${src.dir}/java/org/apache/xmlgraphics/overview.html"
        use="true"
        failonerror="true"
        public="${javadoc.public}"
        package="${javadoc.package}"
        private="${javadoc.private}"
        source="${javac.source}">
      <header><![CDATA[${name} ${version}]]></header>
      <footer><![CDATA[${name} ${version}]]></footer>
      <link offline="false" href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
      <classpath>
        <path refid="libs-build-classpath"/>
        <pathelement path="${java.class.path}"/>
      </classpath>
      <sourcepath>
        <pathelement path="${src.java.dir}"/>
      </sourcepath>
      <group title="Images">
        <package name="org.apache.xmlgraphics.image"/>
        <package name="org.apache.xmlgraphics.image.*"/>
      </group>
      <group title="Java2D">
        <package name="org.apache.xmlgraphics.java2d"/>
        <package name="org.apache.xmlgraphics.java2d.*"/>
      </group>
      <group title="PDF, PostScript...">
        <package name="org.apache.xmlgraphics.ps"/>
        <package name="org.apache.xmlgraphics.ps.*"/>
        <package name="org.apache.xmlgraphics.pdf"/>
        <package name="org.apache.xmlgraphics.pdf.*"/>
      </group>
      <group title="Fonts">
        <package name="org.apache.xmlgraphics.fonts"/>
      </group>
      <group title="XMP Metadata">
        <package name="org.apache.xmlgraphics.xmp"/>
        <package name="org.apache.xmlgraphics.xmp.*"/>
      </group>
      <group title="Utility">
        <package name="org.apache.xmlgraphics.util"/>
        <package name="org.apache.xmlgraphics.util.*"/>
      </group>
    </javadoc>
  </target>

  <target name="jar-javadocs" depends="javadocs">
    <jar jarfile="${build.dir}/${name}-${version}-javadoc.jar">
      <manifest>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <fileset dir="${build.javadocs.dir}"/>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>

  <!-- =================================================================== -->
  <!-- Checkstyle                                                          -->
  <!-- =================================================================== -->
  <property name="checkstyle.location" value="${optional.lib.dir}/checkstyle-5.5-all.jar" />
  <property name="checkstyle.config" value="${tools.checkstyle.dir}/checkstyle.xml" />
  <property name="checkstyle.suppressions.file" value="${tools.checkstyle.dir}/suppressions.xml" />
  <path id="checkstyle-classpath">
    <path refid="libs-build-classpath"/>
    <pathelement location="${checkstyle.location}"/>
  </path>
  <condition property="checkstyle.avail">
    <and>
      <available classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
        <classpath refid="checkstyle-classpath"/>
      </available>
      <available file="${checkstyle.config}"/>
    </and>
  </condition>
  <target name="checkstyle-avail" unless="checkstyle.avail">
    <echo message="Checkstyle support NOT present. Please download it from http://checkstyle.sf.net/ and"/>
    <echo message="... please provide ${checkstyle.location}"/>
    <echo message="... please provide ${checkstyle.config}"/>
  </target>
  <target name="checkstyle" depends="package, checkstyle-avail" if="checkstyle.avail" description="Runs Checkstyle for a code quality report">
    <taskdef name="checkstyle" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" classpathref="checkstyle-classpath"/>
    <mkdir dir="${build.dir}"/>
    <checkstyle config="${checkstyle.config}" failonviolation="true" maxWarnings="0">
      <classpath>
        <path refid="checkstyle-classpath"/>
        <pathelement location="${build.classes.dir}"/>
        <pathelement location="${build.sandbox-classes.dir}"/>
        <pathelement location="${build.codegen-classes.dir}"/>
      </classpath>
      <fileset dir="${src.dir}" includes="**/*.java"/>
      <fileset dir="${basedir}/src/test" includes="**/*.java"/>
      <formatter type="xml" toFile="${build.dir}/report_checkstyle.xml"/>
      <formatter type="plain"/>
    </checkstyle>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the distribution                                            -->
  <!-- =================================================================== -->
  <target name="dist" depends="distclean,dist-src,dist-bin,maven-artifacts" description="Generates the distribution package"/>

  <!-- IMPORTANT: .NET binaries must not be included in the distribution. License policy! -->

  <target name="dist-bin" depends="all,javadocs">
    <echo message="Building the binary distribution files (zip,tar)"/>
    <mkdir dir="${dist.bin.result.dir}"/>
    <copy todir="${dist.bin.result.dir}">
      <fileset refid="dist.bin"/>
      <fileset refid="dist.bin.lib"/>
    </copy>
    <copy todir="${dist.bin.result.dir}/javadocs">
      <fileset dir="${build.javadocs.dir}"/>
    </copy>
    <mkdir dir="${dist.bin.result.dir}/build"/>
    <copy todir="${dist.bin.result.dir}/build" file="build/${name}-${version}.jar"/>

    <!--property name="bin.suffix" value="bin-jdk${java.specification.version}"/-->
    <property name="bin.suffix" value="bin"/>
    <zip zipfile="${name}-${version}-${bin.suffix}.zip" basedir="${dist.bin.dir}" includes="**"/>
    <tar longfile="gnu"
         destfile="${name}-${version}-${bin.suffix}.tar">
      <tarfileset dir="${dist.bin.dir}">
        <include name="**"/>
      </tarfileset>
    </tar>
    <gzip zipfile="${name}-${version}-${bin.suffix}.tar.gz" src="${name}-${version}-${bin.suffix}.tar"/>
    <delete file="${name}-${version}-${bin.suffix}.tar"/>
  </target>

  <target name="dist-src" depends="all">
    <echo message="Building the source distribution files (zip,tar)"/>
    <mkdir dir="${dist.src.result.dir}"/>
    <copy todir="${dist.src.result.dir}">
      <fileset refid="dist.src"/>
    </copy>

    <zip zipfile="${name}-${version}-src.zip">
      <zipfileset dir="${dist.src.dir}" filemode="644" dirmode="755">
        <include name="**"/>
      </zipfileset>
    </zip>
    <tar longfile="gnu"
         destfile="${name}-${version}-src.tar" >
      <tarfileset dir="${dist.src.dir}" mode="644" dirmode="755">
        <include name="**"/>
      </tarfileset>
    </tar>
    <gzip zipfile="${name}-${version}-src.tar.gz" src="${name}-${version}-src.tar"/>
    <delete file="${name}-${version}-src.tar"/>
  </target>

  <target name="release-dist" depends="dist" description="Generates the distribution package and signs the release">
    <!--property name="bin.suffix" value="bin-jdk${java.specification.version}"/-->
    <property name="bin.suffix" value="bin"/>
    <input message="Passphrase for your default private key" addproperty="pwd">
        <handler classname="org.apache.tools.ant.input.SecureInputHandler" />
    </input>
    <antcall target="sha512">
      <param name="sign.archive" value="${name}-${version}-src.zip"/>
    </antcall>
    <antcall target="sign-file">
      <param name="sign.archive" value="${name}-${version}-src.zip"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
    <antcall target="sha512">
      <param name="sign.archive" value="${name}-${version}-src.tar.gz"/>
    </antcall>
    <antcall target="sign-file">
      <param name="sign.archive" value="${name}-${version}-src.tar.gz"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
    <antcall target="sha512">
      <param name="sign.archive" value="${name}-${version}-${bin.suffix}.zip"/>
    </antcall>
    <antcall target="sign-file">
      <param name="sign.archive" value="${name}-${version}-${bin.suffix}.zip"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
    <antcall target="sha512">
      <param name="sign.archive" value="${name}-${version}-${bin.suffix}.tar.gz"/>
    </antcall>
    <antcall target="sign-file">
      <param name="sign.archive" value="${name}-${version}-${bin.suffix}.tar.gz"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
  </target>

  <target name="sha512">
    <property name="sha512.exec" value="sha512sum"/>
    <property name="sha512.options" value=""/>
    <exec executable="${sha512.exec}" output="${sign.archive}.sha512">
      <arg line="${sha512.options} ${sign.archive}"/>
    </exec>
  </target>

  <target name="sign-file">
    <property name="gpg.exec" value="gpg"/>
    <property name="gpg.options" value="--armor --detach-sign --force-v3-sigs --batch --verbose --passphrase-fd 0"/>
    <delete file="${sign.archive}.asc"/>
    <exec executable="${gpg.exec}" inputstring="${pwd}">
      <arg line="${gpg.options} ${sign.archive}"/>
    </exec>
  </target>
  
  <!-- =================================================================== -->
  <!-- Maven artifacts                                                     -->
  <!-- =================================================================== -->
  <target name="maven-artifacts" depends="jar-main, jar-sources, jar-javadocs" description="Builds a Maven artifact that can be uploaded to a Maven repository">
    <filter  token="version" value="${version}"/>
    <mkdir dir="${build.dir}/maven"/>
    <copy file="${basedir}/xmlgraphics-commons-pom-template.pom" tofile="${build.dir}/maven/pom.xml" filtering="true"/>
    <fileset id="bundle-files" dir="${build.dir}">
      <patternset>
      <include name="${name}-${version}.jar"/>
      <include name="${name}-${version}-sources.jar"/>
      <include name="${name}-${version}-javadoc.jar"/>
      </patternset>
      <patternset>
      <include name="maven/pom.xml"/>
      </patternset>
    </fileset>
    <checksum algorithm="sha-512" fileext=".sha512">
      <fileset refid="bundle-files"/>
    </checksum>
    <input message="Passphrase for your default private key" addproperty="pwd">
        <handler classname="org.apache.tools.ant.input.SecureInputHandler" />
    </input>
    <antcall target="sign-file">
      <param name="sign.archive" value="${build.dir}/${name}-${version}.jar"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
    <antcall target="sign-file">
      <param name="sign.archive" value="${build.dir}/${name}-${version}-sources.jar"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
    <antcall target="sign-file">
      <param name="sign.archive" value="${build.dir}/${name}-${version}-javadoc.jar"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
    <antcall target="sign-file">
      <param name="sign.archive" value="${build.dir}/maven/pom.xml"/>
      <param name="pwd" value="${pwd}"/>
    </antcall>
    <jar jarfile="${build.dir}/${name}-${version}-bundle.jar">
      <manifest>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <fileset dir="${build.dir}">
        <patternset>
          <include name="${name}-${version}.jar*"/>
          <include name="${name}-${version}-sources.jar*"/>
          <include name="${name}-${version}-javadoc.jar*"/>
        </patternset>
      </fileset>
      <fileset dir="${build.dir}/maven">
        <patternset>
          <include name="pom.xml*"/>
        </patternset>
      </fileset>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
    <move file="${build.dir}/${name}-${version}-bundle.jar" todir="${basedir}"/>
  </target>
  
  <!-- =================================================================== -->
  <!-- Clean targets                                                       -->
  <!-- =================================================================== -->
  <target name="clean" description="Cleans the build directory">
    <delete dir="${build.dir}"/>
  </target>

  <target name="distclean" depends="clean" description="Cleans the distribution target directories">
    <delete dir="${dist.src.dir}"/>
    <delete dir="${dist.bin.dir}"/>
    <delete>
      <fileset dir="${basedir}" includes="${name}-*.tar.gz*"/>
      <fileset dir="${basedir}" includes="${name}-*.zip*"/>
      <fileset dir="${basedir}" includes="${name}-*-bundle.jar*"/>
    </delete>
  </target>
  
  <!-- =================================================================== -->
  <!-- Default Target                                                      -->
  <!-- =================================================================== -->

  <target name="all" depends="package, junit"/> <!-- "all" target for us Makefile converts ;-) -->

  <!-- =================================================================== -->
  <!-- Special target for Gump                                             -->
  <!-- =================================================================== -->

  <target name="gump" depends="all, javadocs"/>

<!-- =================================================================== -->
<!-- Findbugs                                                            -->
<!-- =================================================================== -->
  <property name="findbugs.lib" value="${findbugs.home.dir}/lib"/>
  <path id="libs-findbugs">
    <fileset dir="${findbugs.lib}">
      <include name="*.jar"/>
    </fileset>
  </path>
  <target name="findbugs-avail" unless="findbugs.home.dir">
    <echo message="Findbugs Support NOT Present. Please download it from http://findbugs.sf.net/ and set findbugs.home.dir in build-local.properties"/>
  </target>
  <target name="findbugs" depends="init, findbugs-avail, compile-java" if="findbugs.home.dir">
    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="libs-findbugs"/>
    <findbugs home="${findbugs.home.dir}" output="text" reportLevel="low" effort="max" excludeFilter="${tools.findbugs.dir}/exclusions.xml" jvmargs="-Xmx1024m" warningsProperty="findbugs.warnings">
      <sourcePath path="${src.java.dir}"/>
      <class location="${build.classes.dir}"/>
      <auxClasspath>
        <path refid="libs-build-classpath"/>
        <path>
          <fileset dir="${ant.library.dir}">
            <include name="ant.jar"/>
            <include name="ant-launcher.jar"/>
          </fileset>
        </path>
      </auxClasspath>
    </findbugs>
    <fail if="findbugs.warnings"/>
  </target>  

</project>
