<?xml version="1.0"?>
<!--

    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

    Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.

    The contents of this file are subject to the terms of either the GNU
    General Public License Version 2 only ("GPL") or the Common Development
    and Distribution License("CDDL") (collectively, the "License").  You
    may not use this file except in compliance with the License.  You can
    obtain a copy of the License at
    https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
    or packager/legal/LICENSE.txt.  See the License for the specific
    language governing permissions and limitations under the License.

    When distributing the software, include this License Header Notice in each
    file and include the License file at packager/legal/LICENSE.txt.

    GPL Classpath Exception:
    Oracle designates this particular file as subject to the "Classpath"
    exception as provided by Oracle in the GPL Version 2 section of the License
    file that accompanied this code.

    Modifications:
    If applicable, add the following below the License Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyright [year] [name of copyright owner]"

    Contributor(s):
    If you wish your version of this file to be governed by only the CDDL or
    only the GPL Version 2, indicate your decision by adding "[Contributor]
    elects to include this software in this distribution under the [CDDL or GPL
    Version 2] license."  If you don't indicate a single choice of license, a
    recipient has the option to distribute your version of this file under
    either the CDDL, the GPL Version 2 or to extend the choice of license to
    its licensees as provided above.  However, if you add GPL Version 2 code
    and therefore, elected the GPL Version 2 license, then the option applies
    only if the new code is made subject to such option by the copyright
    holder.

-->

<project name="reflection" basedir=".." default="compile">
  <description>
    Reflection Library Sub-Project

    The reflection library module provides a library to process
    JAXB annotations at runtime. We ship this in a different package
    to avoid class collisions and compatibility issues between the RI
    and this library.
  </description>

  <!-- import build properties -->
  <property file="build.properties" />
  <import file="${jaxb.root}/build-taskdefs.xml" />

  <target name="compile"
    description="creates a distribution bundle for the JAXB2 reflection library">

    <!-- this is very inefficient, but it builds everything we need -->
    <ant dir="${jaxb.root}" target="compile" />

    <macrodef name="rename">
      <attribute name="srcdir" />
      <sequential>
        <prename srcdir="@{srcdir}"
          destdir="${reflection.root}/build/src" excludes="com/sun/xml/bind/v2/package-info.java">

          <pattern from="com.sun.xml.bind.v2" to="org.jvnet.jaxb.reflection" />
          <pattern from="com.sun.xml.bind" to="org.jvnet.jaxb.reflection.impl" />
        </prename>
      </sequential>
    </macrodef>

    <!-- rename packages -->
    <rename srcdir="${runtime.src}"/>
    <rename srcdir="${runtime.root}/build/src" />
    <rename srcdir="${runtime.root}/arch-doc" />
    <rename srcdir="${reflection.src}" />

    <mkdir dir="${reflection.classes}"/>
    <javac srcdir="${reflection.root}/build/src" destdir="${reflection.classes}" debug="on" source="1.5" target="1.5">
      <classpath>
        <fileset dir="${jaxb.libs.redist}" includes="*.jar"/>
        <fileset dir="${jaxb.libs.runtime2}" includes="**/*.jar"/>
      </classpath>
    </javac>
  </target>

  <target name="javadoc" depends="compile" >
    <arch-doc destdir="${reflection.root}/build/javadoc" title="JAXB2 reflection library" access="public">
      <params>
        <packageset dir="${reflection.root}/build/src">
          <include name="org/jvnet/jaxb/reflection/**" />
          <exclude name="org/jvnet/jaxb/reflection/bytecode" />
          <exclude name="org/jvnet/jaxb/reflection/impl/**" />
          <exclude name="org/jvnet/jaxb/reflection/model/impl" />
          <exclude name="org/jvnet/jaxb/reflection/runtime/**" />
        </packageset>
      </params>
    </arch-doc>
  </target>

  <target name="jar" depends="compile">
    <jar jarfile="${reflection.root}/build/jaxb2-reflection.jar">
      <fileset dir="${reflection.root}/build/src" includes="**/*.properties" />
      <fileset dir="${reflection.classes}" />
      <zipgroupfileset dir="${jaxb.libs.runtime2}" includes="istack-commons-runtime.jar" />
    </jar>
  </target>

  <target name="dist" depends="javadoc, jar">
    <!-- build id can be overridden -->
    <tstamp />
    <property name="build.id" value="${DSTAMP}" />

    <zip file="${reflection.root}/build/src.zip">
      <fileset dir="${reflection.root}/build/src" />
    </zip>

    <zip file="${reflection.root}/build/jaxb2-reflection.zip">
      <zipfileset prefix="jaxb2-reflection"
        dir="${reflection.root}/build" includes="jaxb2-reflection.jar" />
      <zipfileset prefix="jaxb2-reflection"
        dir="${reflection.root}/build" includes="javadoc/**/*, src.zip"/>
      <zipfileset fullpath="jaxb2-reflection/license.html"
        dir="${jaxb.root}" includes="License.html"/>
    </zip>

    <ant dir="tools/installer-builder" />

    <taskdef name="installerBuilder" classname="com.sun.tools.xjc.installer.builder.BuilderTask">
        <classpath>
            <fileset dir="${jaxb.libs.util}" includes="*.jar"/>
        </classpath>
    </taskdef>

    <installerBuilder
      jarFile="${reflection.root}/build/jaxb2-reflection.${build.id}.jar"
      licenseFile="${jaxb.root}/License.txt"
      zipFile="${reflection.root}/build/jaxb2-reflection.zip" />
  </target>

  <target name="clean">
    <delete dir="${reflection.root}/build" />
  </target>

</project>
