<?xml version="1.0"?>

<!--
 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
 Copyright 1997-2007 Sun Microsystems, Inc. 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.html
 or glassfish/bootstrap/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 glassfish/bootstrap/legal/LICENSE.txt.
 Sun designates this particular file as subject to the "Classpath" exception
 as provided by Sun in the GPL Version 2 section of the License file that
 accompanied this code.  If applicable, add the following below the License
 Header, with the fields enclosed by brackets [] replaced by your own
 identifying information: "Portions Copyrighted [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="samples" basedir=".." default="compile">
  <description>
    Sample Apps Sub-Project
    =======================

    Automated sample app generation. Meta files that describe each
    sample app are used to generate Ant build.xml files, test, etc.
  </description>

  <!-- import build properties -->
  <property file="${basedir}/build.properties"/>

  <!-- this property controls how the stylesheet generates classpath
       information in the sample build.xml files.  Legal values are:

           'workspace' - samples can be run from samples/samples-src/...
           'RI' - samples can be run from dist/samples/...
           'JWSDP' - sample can be run from $JWSDP_HOME/jaxb/samples/...

       during regular workspace builds, this property will default to
       'workspace' so the sample can be run in place.
  -->
  <property name="samples.target" value="workspace"/>
  <property environment="env"/>

  <!-- setup classpath -->
  <path id="classpath">
    <pathelement path="."/>
    <pathelement path="${samples.classes}"/>
    <fileset dir="${jaxb.libs}" includes="**/*.jar"/>
    <pathelement path="${test.classes}"/>
    <pathelement location="${env.JAVA_HOME}/lib/tools.jar"/>
  </path>

  <path id="unittest-classpath">
    <path refid="classpath"/>
    <pathelement location="../../jaxb-unit/tools/lib/util/emma.jar"/>
  </path>

  <!-- compile Java source files -->
  <target name="compile" description="compile sample app processor code">
    <mkdir dir="${samples.classes}"/>
    <javac srcdir="${samples.src}" destdir="${samples.classes}"
           debug="${compile.debug}" optimize="${compile.optimize}"
           deprecation="${compile.deprecation}">
      <classpath refid="classpath"/>
    </javac>
    <!-- copy other resources into build dir -->
    <copy toDir="${samples.classes}">
      <fileset dir="${samples.src}" includes="**/*.xsl"/>
      <fileset dir="${samples.src}" includes="**/*.rnc"/>
    </copy>
  </target>

  <dirset dir="${samples.samples-src}">
    <exclude name="**/CVS"/>
  </dirset>

  <!-- run the sample app processors -->
  <target name="generate-samples" depends="process-samples"
          description="generate build.xml into the samples-src directory."/>
  <target name="process-samples" depends="compile">
    <property name="samples.work" value="${samples.root}/work"/>
    <delete dir="${samples.work}"/>
    <mkdir dir="${samples.work}"/>

    <java classname="processor.SampleProcessorDriver" fork="true" failonerror="true">
      <classpath refid="classpath"/>
      <arg line="-dir ${samples.samples-src}"/>
      <arg line="-work ${samples.work}"/>
      <arg value="-validating"/>
      <arg line="-ant ${samples.target}"/>
      <!--jvmarg value="-Xdebug" /-->
      <!--jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,address=8000" /-->
    </java>
  </target>

  <!-- run each of the sample apps and compare the output to the expected results -->
  <target name="test-samples" depends="clean, compile"
          description="run each of the samples and report pass/fail results">
    <property name="samples.work" value="${samples.root}/work"/>
    <delete dir="${samples.work}"/>
    <mkdir dir="${samples.work}"/>

    <java classname="processor.SampleProcessorDriver" fork="true" failonerror="true">
      <classpath refid="unittest-classpath"/>
      <jvmarg line="-Xmx512m"/>
      <arg line="-dir ${samples.samples-src}"/>
      <arg line="-work ${samples.work}"/>
      <arg value="-validating"/>
      <arg value="-execute"/>
      <arg value="-verbose"/>
      <arg line="-ant ${samples.target}"/>
    </java>
  </target>

  <!-- remove all intermediate files -->
  <target name="clean" description="clean generated artifacts">
    <delete dir="${samples.build}"/>
    <!-- clean generated artifacts from test runs under samples-src/* -->
    <delete includeemptydirs="true">
      <fileset dir="${samples.samples-src}" includes="**/build.xml"/>
      <!--fileset dir="${samples.samples-src}" includes="**/gen-src/**/*"/-->
      <fileset dir="${samples.samples-src}" includes="**/gen-src/"/>
      <fileset dir="${samples.samples-src}" includes="**/classes/"/>
      <fileset dir="${samples.samples-src}" includes="**/build.out"/>
    </delete>
    <delete dir="${samples.root}/work"/>
  </target>


</project>
