<?xml version="1.0" encoding="UTF-8"?>
<!--
    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.
    -->
<!--
  Ant tasks used to create Javadoc across all of Beam.
-->
<project>

  <property name="collect.dir" location="target/collected"/>
  <property name="output.dir" location="../target/site/javadoc"/>

  <!-- One target to do the work. It collects the sources and runs javadoc. -->
  <target name="javadoc">
    <!-- suck up all the java code into one place. -->
    <copy todir="${collect.dir}">
      <fileset dir="..">
        <include name="**/src/main/java/**/*.java"/>
        <exclude name="**/maven-archetypes/**"/>
        <exclude name="**/nexmark/**"/>
      </fileset>
      <!-- For each pathname, turn X/src/main/java/Y to Y. This
           results in one Java source tree. -->
      <mapper type="regexp" from="^.*/src/main/java/(.*)$$" to="\1"/>
    </copy>

    <copy todir="${collect.dir}">
      <fileset dir="../../../runners">
        <include name="**/src/main/java/**/*.java"/>
      </fileset>
      <!-- For each pathname, turn X/src/main/java/Y to Y. This
           results in one Java source tree. -->
      <mapper type="regexp" from="^.*/src/main/java/(.*)$$" to="\1"/>
    </copy>

    <!-- Run javadoc. -->
    <javadoc sourcepath="${collect.dir}"
      destdir="${output.dir}"
      classpath="${compile_classpath}"
      Overview="overview.html"
    >
      <!-- Get some Javadoc options set up by Maven. -->
      <arg line="${beam.javadoc_opts}"/>
      <!-- Setup offline links for some packages. -->
      <link href="http://avro.apache.org/docs/1.7.7/api/java/"
        offline="true" packageListLoc="avro-docs"/>
      <link
        href="https://developers.google.com/api-client-library/java/google-api-java-client/reference/1.22.0/"
        offline="true" packageListLoc="apiclient-docs"/>
      <link
        href="https://developers.google.com/api-client-library/java/google-oauth-java-client/reference/1.22.0/"
        offline="true" packageListLoc="oauth-docs"/>
      <link
        href="https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/java/latest/"
        offline="true" packageListLoc="bq-docs"/>
      <link href="http://googlecloudplatform.github.io/google-cloud-java/0.8.0/apidocs/index.html"
        offline="true" packageListLoc="datastore-docs"/>
      <link href="http://google.github.io/guava/releases/20.0/api/docs/"
        offline="true" packageListLoc="guava-docs"/>
      <link href="http://fasterxml.github.io/jackson-annotations/javadoc/2.7/"
        offline="true" packageListLoc="jackson-annotations-docs"/>
      <link href="http://fasterxml.github.io/jackson-databind/javadoc/2.7/"
        offline="true" packageListLoc="jackson-databind-docs"/>
      <link href="http://hamcrest.org/JavaHamcrest/javadoc/1.3/"
        offline="true" packageListLoc="hamcrest-docs"/>
      <link href="http://www.joda.org/joda-time/apidocs"
        offline="true" packageListLoc="joda-docs"/>
      <link href="http://junit.sourceforge.net/javadoc/"
            offline="true" packageListLoc="junit-docs"/>

      <excludepackage name="org.apache.beam.examples.*"/>
      <excludepackage name="org.apache.beam.fn.*"/>
      <excludepackage name="org.apache.beam.runners.apex.translation.*"/>
      <excludepackage name="org.apache.beam.runners.core.*"/>
      <excludepackage name="org.apache.beam.runners.dataflow.internal.*"/>
      <excludepackage name="org.apache.beam.runners.flink.examples.*"/>
      <excludepackage name="org.apache.beam.runners.flink.translation.*"/>
      <excludepackage name="org.apache.beam.runners.spark.examples.*"/>
      <excludepackage name="org.apache.beam.runners.spark.translation.*"/>
      <excludepackage name="org.apache.beam.sdk.transforms.reflect.*"/>
      <excludepackage name="org.apache.beam.sdk.runners.*"/>
      <excludepackage name="org.apache.beam.sdk.util.*"/>
    </javadoc>
    <!-- make a jar file to push to central -->
    <jar destfile="${output.jar}" basedir="${output.dir}"/>
  </target>
</project>
