<?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="runtime" basedir=".." default="compile">

  <description>
    Runtime Sub-Project
    ===================
    
    The runtime project implements all of the interfaces from the 
    javax.xml.bind.* packages necessary to support marshalling,
    unmarshalling, and validation.
  </description>
  
    <!-- import build properties -->
    <property file="${basedir}/build.properties" />

  <!-- classpath -->
  <path id="javac.classpath">
    <fileset dir="${jaxb.libs.redist}" includes="*.jar"/>
    <fileset dir="${jaxb.libs.rebundle}" includes="**/*.jar"/>
    <fileset dir="${jaxb.libs.util}" includes="*.jar" excludes="ant.jar"/>
  </path>
  
  <path id="txw.classpath">
    <path refid="javac.classpath"/>
    <pathelement path="${jaxb.libs.runtime2}/txw2.jar"/>
    <pathelement path="${jaxb.libs.util}/txwc2.jar"/>
    <pathelement path="${jaxb.libs.util}/args4j.jar"/>
    <pathelement path="${jaxb.libs.compiler}/rngom.jar"/>
    <pathelement path="${codemodel.classes}"/>
  </path>

    
    <target name="generate-array-listers">
        <macrodef name="generateCopiesForPrimitives">
          <attribute name="srcdir"/>
          <attribute name="destdir"/>
          <attribute name="prefix" />
          <sequential>
            <!-- macro to replace one file -->
            <macrodef name="generate">
              <attribute name="primitive"/>
              <attribute name="box"/>
              <sequential>
                <copy file="@{srcdir}/@{prefix}Byte.java" tofile="@{destdir}/@{prefix}@{box}.java"/>
                <replace file="@{destdir}/@{prefix}@{box}.java">
                  <replacefilter token="byte" value="@{primitive}"/>
                  <replacefilter token="Byte" value="@{box}"/>
                </replace>
              </sequential>
            </macrodef>
            
            <mkdir dir="@{destdir}"/>
            <generate primitive="boolean" box="Boolean" />
            <generate primitive="char"    box="Character" />
            <generate primitive="short"   box="Short" />
            <generate primitive="int"     box="Integer" />
            <generate primitive="long"    box="Long" />
            <generate primitive="float"   box="Float" />
            <generate primitive="double"  box="Double" />
          </sequential>
        </macrodef>
        
        <!-- generate ArrayLister for other primitive types -->
        <generateCopiesForPrimitives
          srcdir=       "${runtime.root}/src/com/sun/xml/bind/v2/runtime/reflect"
          destdir="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect"
          prefix="PrimitiveArrayLister" />

        <!-- generate Accessor for fields -->
        <generateCopiesForPrimitives
          srcdir=       "${runtime.root}/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          destdir="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          prefix="FieldAccessor_" />

        <!-- generate Accessor for methods -->
        <generateCopiesForPrimitives
          srcdir=       "${runtime.root}/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          destdir="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          prefix="MethodAccessor_" />

        <!-- generate TransducedAccessor for fields -->
        <generateCopiesForPrimitives
          srcdir=       "${runtime.root}/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          destdir="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          prefix="TransducedAccessor_field_" />
        <!-- the char version won't be correct. Don't use it. Char is rare anyway. -->
        <delete file="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt/TransducedAccessor_field_Character.java"/>
        <!-- integer version is also hand-coded. -->
        <delete file="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt/TransducedAccessor_field_Integer.java"/>
        <delete file="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt/TransducedAccessor_field_Boolean.java"/>

        <!-- generate TransducedAccessor for methods -->
        <generateCopiesForPrimitives
          srcdir=       "${runtime.root}/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          destdir="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt"
          prefix="TransducedAccessor_method_" />
        <!-- the char version won't be correct. Don't use it. Char is rare anyway. -->
        <delete file="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt/TransducedAccessor_method_Character.java"/>
        <!-- integer version is also hand-coded. -->
        <delete file="${runtime.root}/build/src/com/sun/xml/bind/v2/runtime/reflect/opt/TransducedAccessor_method_Integer.java"/>
    </target>
    
    <target name="generate-annotation-proxies"
           description="generate annotation proxies">
      <taskdef name="apgen" classname="com.sun.tools.GeneratorTask">
        <classpath>
          <pathelement path="${apgen.classes}" />
          <pathelement path="${jaxb.libs.compiler}/istack-commons-tools.jar"/>
          <pathelement path="${jaxb.libs.compiler}/codemodel.jar" />
        </classpath>
      </taskdef>

      <property name="jaxb-api.path" value="${jaxb.libs.redist}/jaxb-api.jar"/>
      <mkdir dir="${runtime.root}/build/src"/>
      <apgen destdir="${runtime.root}/build/src"
        package="com.sun.xml.bind.v2.model.annotation" licence="${jaxb.root}/licenceheader.txt">
        <classes includes="javax.xml.bind.annotation.XmlAttribute" />
        <classes includes="javax.xml.bind.annotation.XmlElement" />
        <classes includes="javax.xml.bind.annotation.XmlElementDecl" />
        <classes includes="javax.xml.bind.annotation.XmlElementRef" />
        <classes includes="javax.xml.bind.annotation.XmlElementRefs" />
        <classes includes="javax.xml.bind.annotation.XmlEnum" />
        <classes includes="javax.xml.bind.annotation.XmlRootElement" />
        <classes includes="javax.xml.bind.annotation.XmlSchema" />
        <classes includes="javax.xml.bind.annotation.XmlTransient" />
        <classes includes="javax.xml.bind.annotation.XmlType" />
        <classes includes="javax.xml.bind.annotation.XmlValue" />
    	<classes includes="javax.xml.bind.annotation.XmlSchemaType" />
        <endorse path="${jaxb-api.path}"/>
        <classpath>
          <pathelement path="${jaxb-api.path}"/>
        </classpath>
      </apgen>
    </target>

    <target name="txwc"
      description="generate the s4s generator library code">

      <taskdef name="txwc" classname="com.sun.tools.txw2.TxwTask">
        <classpath refid="txw.classpath"/>
      </taskdef>

      <taskdef name="licence" classname="com.sun.tools.LicenceTask">
        <classpath>
          <pathelement path="${apgen.classes}" />
          <pathelement path="${jaxb.libs.compiler}/istack-commons-tools.jar"/>
          <pathelement path="${jaxb.libs.compiler}/codemodel.jar" />
        </classpath>
      </taskdef>

      <mkdir dir="${runtime.root}/build/src" />
      <txwc schema="${runtime.src}/com/sun/xml/bind/v2/schemagen/xmlschema/xmlschema-for-jaxb.rng"
        destdir="${runtime.root}/build/src"
        package="com.sun.xml.bind.v2.schemagen.xmlschema"
        methodChaining="true"/>

      <licence licence="${jaxb.root}/licenceheader.txt">
        <fileset dir="${runtime.root}/build/src" includes="com/sun/xml/bind/v2/schemagen/xmlschema/*.java"/>
      </licence>
    </target>

    <target name="codegen" depends="generate-array-listers,generate-annotation-proxies,txwc"
            description="run all the code generators in the runtime" />

    <!-- compile Java source files -->
    <target name="compile" depends="codegen"
                description="compile all runtime src into jaxb-ri/runtime/build/classes">
        <mkdir dir="${runtime.classes}" />

        <!-- always delete this prop file so that the latest build id can be set -->
        <delete file="${runtime.classes}/com/sun/xml/bind/Messages.properties"/>

        <javac srcdir="${runtime.src}:${runtime.root}/build/src" destdir="${runtime.classes}"
            debug="${compile.debug}" optimize="${compile.optimize}"
        	source="1.5" target="1.5"
            deprecation="${compile.deprecation}" >
            <classpath refid="javac.classpath" />
            <compilerarg line="${runtime.compilerarg}"/>
        </javac>
        
        <copy toDir="${runtime.classes}">
            <fileset dir="${runtime.src}" includes="**/*.properties" />
        </copy>
    </target>

    <!-- generate javadoc -->
    <target name="javadoc">
        <mkdir dir="${runtime.root}/build/api" />
        <javadoc
            destdir="${runtime.root}/build/api"
            use="true" defaultexcludes="yes"
            author="false"
            version="false"
            windowtitle="JAXB RI runtime"
            useexternalfile="true"
            access="public">
            <fileset dir="${runtime.src}" includes="com/sun/xml/bind/*.java, com/sun/xml/bind/annotation/*.java, com/sun/xml/bind/api/*.java "/>
            <classpath refid="javac.classpath"/>
            <arg value="-quiet"/>
        </javadoc>
        <!-- javadoc should copy those files, but it doesn't seem to do that -->
        <copy todir="${runtime.root}/build/api">
          <fileset dir="${runtime.src}" includes="**/doc-files/**/*"/>
        </copy>
    </target>

    <!-- remove all intermediate files -->
    <target name="clean"
            description="clean jaxb-ri/runtime/build">
        <parallel>
            <delete dir="${runtime.root}/build" />
            <delete file="${runtime.root}/manifest.rt" />
        </parallel>
    </target>
    
    <!-- run unit test -->
    <target name="test-runtime" 
          depends="compile"
          description="execute client unit tests - requires junit.jar on system classpath">
      
      <mkdir dir="${runtime.test.classes}"/>
      <mkdir dir="${runtime.root}/log"/>
      
      <javac srcdir="${runtime.test}" destdir="${runtime.test.classes}"
        debug="true" optimize="true"
      	source="1.5" target="1.5"
        deprecation="${compile.deprecation}" >
        
        <classpath>
          <path refid="javac.classpath" />
          <pathelement path="${runtime.classes}" />
        </classpath>
      </javac>
      
      <echo>running JUnit</echo>
      <junit printsummary="yes" fork="no" haltonerror="yes" haltonfailure="yes">

        <classpath>
          <path refid="javac.classpath" />
          <pathelement path="${runtime.classes}"/>
          <pathelement path="${runtime.test.classes}"/>
        </classpath>
        
        <batchtest todir="${runtime.root}/log">
            <formatter usefile="true" type="xml"/>
            <fileset dir="${runtime.test.classes}" includes="**/*Test.class" />
        </batchtest>
        
      </junit>
    </target>
</project>
