   <!-- ===================================================================
         This is basically the <ant /> task, except that it forks
        =================================================================== -->
   <target name="my-forking-ant">
     <echo message="Forking a JVM for target ${target} in file ${file}"/>
     <java classname="org.apache.tools.ant.Main" fork="yes" failonerror="true" dir="${dir}">
       <classpath refid="classpath"/>
       <arg line="-buildfile ${file} ${target}"/>
     </java>
   </target>


  <!-- ===================================================================
    This is an accessory function to echo out fileNames 
       =================================================================== --> 
  <target name="echo-file">
    <basename property="fileName" file="${file}"/>
    <dirname property="dirName" file="${file}"/>
    <echo message="Dir: ${dirName} File: ${fileName}"/>
  </target>

  <!-- ===================================================================
        This is an accessory function to compile some given component
       =================================================================== -->
  <target name="component-compile">
    <echo message="${file}"/>
    <basename property="fileName" file="${file}"/>
    <dirname property="dirName" file="${file}"/>
    <ant inheritAll="false" dir="${dirName}" antfile="${fileName}" target="compile"/>
  </target>

  <!-- ===================================================================
        This is an accessory function to exec JUST the testcase of a 
    component.
       =================================================================== -->
  <target name="batch-component-test">
    <antcall target="echo-file"/>
    <basename property="fileName" file="${file}"/>
    <dirname property="dirName" file="${file}"/>
    <ant inheritAll="false" dir="${dirName}" antfile="${fileName}" target="component-junit-functional"/>
  </target>

  <!-- ===================================================================
        This is an accessory function to execs the full component test
       =================================================================== -->
  <target name="batch-component-run">
    <antcall target="echo-file"/>
    <basename property="fileName" file="${file}"/>
    <dirname property="dirName" file="${file}"/>
    <ant inheritAll="false" dir="${dirName}" antfile="${fileName}" target="run"/>
  </target>

  <!-- =================================================================== -->
  <!-- Determine what dependencies are present                             -->
  <!-- =================================================================== -->

  <target name="setenv">

    <condition property="ant.good">
      <and>
        <contains string="${ant.version}" substring="Apache Ant version"/>
      </and>
    </condition>

    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dest}"/>
    <mkdir dir="${build.lib}"/>
    <mkdir dir="${build.dir}/work"/>

    <available property="servlet.present"
      classname="javax.servlet.Servlet"
      classpathref="classpath"/>

    <available property="regexp.present"
      classname="org.apache.oro.text.regex.Pattern"
      classpathref="classpath"/>

    <available property="junit.present"
      classname="junit.framework.TestCase"
      classpathref="classpath"/>

    <available property="wsdl4j.present"
      classname="javax.wsdl.Definition"
      classpathref="classpath"/>

    <available property="commons-logging.present"
      classname="org.apache.commons.logging.Log"
      classpathref="classpath"/>

    <available property="commons-discovery.present"
      classname="org.apache.commons.discovery.tools.DiscoverSingleton"
      classpathref="classpath"/>

    <available property="commons-httpclient.present"
      classname="org.apache.commons.httpclient.HttpConnection"
      classpathref="classpath"/>

    <available property="log4j.present"
      classname="org.apache.log4j.Category"
      classpathref="classpath"/>

    <available property="activation.present"
      classname="javax.activation.DataHandler"
      classpathref="classpath"/>

    <available property="security.present"
      classname="org.apache.xml.security.Init"
      classpathref="classpath"/>

    <available property="mailapi.present"
      classname="javax.mail.internet.MimeMessage"
      classpathref="classpath"/>

    <available property="httpunit.present"
      classname="com.meterware.httpunit.GetMethodWebRequest"
      classpathref="classpath"/>

    <condition property="jsse.present" >
      <and>
        <available classname="com.sun.net.ssl.X509TrustManager" classpathref="classpath" />
        <available classname="javax.net.SocketFactory" classpathref="classpath" />
        <available classname="com.sun.net.ssl.SSLContext" classpathref="classpath" />
        <available classname="javax.net.ssl.SSLSocketFactory" classpathref="classpath" />
      </and>
    </condition>

    <condition property="attachments.present" >
      <and>
        <available classname="javax.activation.DataHandler" classpathref="classpath" />
        <available classname="javax.mail.internet.MimeMessage" classpathref="classpath" />
      </and>
    </condition>

    <condition property="jimi.present" >
      <available classname="com.sun.jimi.core.Jimi" classpathref="classpath" />
    </condition>

    <condition property="merlinio.present" >
      <available classname="javax.imageio.ImageIO" classpathref="classpath" />
    </condition>

    <condition property="axis-ant.present" >
      <available classname="org.apache.axis.tools.ant.foreach.ForeachTask">
        <classpath>
          <pathelement location="${build.lib}/axis-ant.jar"/>
        </classpath>
      </available>  
    </condition>

    <condition property="jimiAndAttachments.present">
      <and>
        <available classname="javax.activation.DataHandler" classpathref="classpath" />
        <available classname="javax.mail.internet.MimeMessage" classpathref="classpath" />
        <available classname="com.sun.jimi.core.Jimi" classpathref="classpath" />
      </and>
    </condition>

    <condition property="jms.present" >
      <available classname="javax.jms.Message" classpathref="classpath" />
    </condition>

    <available property="post-compile.present" file="post-compile.xml" />

    <property environment="env"/>
    <condition property="debug" value="on">
    <and>
      <equals arg1="on" arg2="${env.debug}"/>
    </and>
    </condition>

    <condition property="castor.present" >
      <available classname="org.exolab.castor.xml.MarshalException" classpathref="classpath" />
    </condition>
    
  </target>

  <!-- print out the current enviroment. 
      Also, probe for javadocs being out of date and set javadoc.notrequired
      to true if they are not needed -->
  <target name="printEnv" depends="setenv" >

    <echo message="-----------------------------------------------------------------"/>
    <echo message="       Build environment for ${Name} ${axis.version} [${year}]   "/>
    <echo message="-----------------------------------------------------------------"/>
    <echo message="Building with ${ant.version}"/>
    <echo message="using build file ${ant.file}"/>
    <echo message="Java ${java.version} located at ${java.home} "/>
    <echo message="-----------------------------------------------------------------"/>

    <echo message="--- Flags (Note: If the {property name} is displayed, "/>
    <echo message="           then the component is not present)" />
    <echo message=""/>

    <echo message="basedir = ${basedir}"/>
    <echo message="axis.home = ${axis.home}"/>
    <echo message="build.dir = ${build.dir}"/>
    <echo message="build.dest = ${build.dest}"/>
    <echo message=""/>
    <echo message="=== Required Libraries ===" />
    <echo message="wsdl4j.present=${wsdl4j.present}" />
    <echo message="commons-logging.present=${commons-logging.present}" />
    <echo message="commons-discovery.present=${commons-discovery.present}" />
    <echo message="log4j.present=${log4j.present}" />
    <echo message="activation.present=${activation.present}" />
    <echo message=""/>
    <echo message="--- Optional Libraries ---" />
    <echo message="servlet.present=${servlet.present}" />
    <echo message="regexp.present=${regexp.present}" />
    <echo message="junit.present=${junit.present}" />
    <echo message="mailapi.present=${mailapi.present}" />
    <echo message="attachments.present=${attachments.present}" />
    <echo message="jimi.present=${jimi.present}" />
    <echo message="security.present=${security.present}" />
    <echo message="jsse.present=${jsse.present}" />
    <echo message="commons-httpclient.present=${commons-httpclient.present}" />
    <echo message="axis-ant.present=${axis-ant.present}" />
    <echo message="httpunit.present=${httpunit.present}" />
    <echo message="jms.present=${jms.present}" />
    <echo message=""/>
    <echo message="--- Property values ---" />
    <echo message="debug=${debug}" />
    <echo message="deprecation=${deprecation}" />
    <echo message="build.compiler=${build.compiler}" />
    <echo message="javac.fork=${javac.fork}" />
    <!-- Set environment variable axis_nojavadocs=true  to never generate javadocs. Case sensative! -->
    <echo message="axis_nojavadocs=${env.axis_nojavadocs}"/>

    <echo message="" />
    <echo message="-- Test Environment for AXIS ---"/>
    <echo message="" />
    <echo message="test.functional.remote = ${test.functional.remote}" />
    <echo message="test.functional.local = ${test.functional.local}" />
    <echo message="test.functional.both = ${test.functional.both}" />
    <echo message="test.functional.reportdir = ${test.functional.reportdir}" />
    <echo message="test.functional.SimpleAxisPort = ${test.functional.SimpleAxisPort}" />
    <echo message="test.functional.TCPListenerPort = ${test.functional.TCPListenerPort}" />
    <echo message="test.functional.fail = ${test.functional.fail}" />
    <echo message="" />

    <uptodate property="javadoc.notoutofdate"
              targetfile="${build.javadocs}/index.html">
      <srcfiles dir="${src.dir}" includes="**/*.java" />
    </uptodate>

    <!-- for ant1.5+, we can use <isset> here -->
    <condition property="axis_nojavadocs" value="true">
      <equals arg1="true" arg2="${env.axis_nojavadocs}"/>
    </condition>
    <condition property="axis_nojavadocs" value="false">
      <equals arg1="${axis_nojavadocs}" arg2="$${axis_nojavadocs}"/>
    </condition>

    <condition property="javadoc.notrequired" value="true">
    <or>
      <equals arg1="${javadoc.notoutofdate}" arg2="true"/>
      <equals arg1="true" arg2="${axis_nojavadocs}"/>
    </or>
    </condition>


  </target>


  <!-- =================================================================== -->
  <!-- Launches the functional test TCP server -->
  <!-- =================================================================== -->
  <target name="start-functional-test-tcp-server" if="junit.present">
    <echo message="Starting test tcp server."/>
    <java classname="samples.transport.tcp.TCPListener" fork="yes" dir="${axis.home}/build">
      <arg line="-p ${test.functional.TCPListenerPort}" /> <!-- arbitrary port -->
      <classpath refid="classpath" />
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Launches the functional test HTTP server -->
  <!-- =================================================================== -->
  <target name="start-functional-test-http-server" if="junit.present">
    <echo message="Starting test http server."/>
    <java classname="org.apache.axis.transport.http.SimpleAxisServer" fork="yes" dir="${axis.home}/build">
        <!-- Uncomment this to use Jikes instead of Javac for compiling JWS Files
        <jvmarg value="-Daxis.Compiler=org.apache.axis.components.compiler.Jikes"/>
        -->
        <jvmarg value="-Daxis.wsdlgen.intfnamespace=http://localhost:${test.functional.ServicePort}"/>
        <jvmarg value="-Daxis.wsdlgen.serv.loc.url=http://localhost:${test.functional.ServicePort}"/>
        <arg line="-p ${test.functional.SimpleAxisPort}" />  <!-- arbitrary port -->
      <classpath refid="classpath" />
    </java>

  </target>

  <!-- =================================================================== -->
  <!-- Launches the functional test HTTP server when testing digital signature -->
  <!-- =================================================================== -->
  <target name="start-functional-test-http-server-secure" if="junit.present" depends="start-signature-signing-and-verification">
    <echo message="Starting test http server."/>
    <java classname="org.apache.axis.transport.http.SimpleAxisServer" fork="yes" dir="${axis.home}/build">
        <!-- Uncomment this to use Jikes instead of Javac for compiling JWS Files
        <jvmarg value="-Daxis.Compiler=org.apache.axis.components.compiler.Jikes"/>
        -->
        <jvmarg value="-Daxis.wsdlgen.intfnamespace=http://localhost:${test.functional.ServicePort}"/>
        <jvmarg value="-Daxis.wsdlgen.serv.loc.url=http://localhost:${test.functional.ServicePort}"/>
        <arg line="-p ${test.functional.SimpleAxisPort}" />  <!-- arbitrary port -->
      <classpath refid="classpath" />
    </java>

  </target>

  <!-- =================================================================== -->
  <!-- Stops the functional test HTTP server -->
  <!-- =================================================================== -->
  <target name="stop-functional-test-http-server" if="junit.present">
    <echo message="Stopping test http server."/>
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="classpath" />
      <arg line="quit"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Stops the functional test HTTP server when testing digital signature -->
  <!-- =================================================================== -->
  <target name="stop-functional-test-http-server-secure" if="junit.present" depends="stop-signature-signing-and-verification">
    <echo message="Stopping test http server."/>
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="classpath" />
      <arg line="quit"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Start Signature Signing and Verification -->
  <!-- =================================================================== -->
  <target name="start-signature-signing-and-verification" if="security.present">
    <!-- Enable transparent Signing of SOAP Messages sent
        from the client and Server-side Signature Verification.
    -->
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="classpath" />
      <arg line="samples/security/serversecuritydeploy.wsdd"/>
    </java>
    <java classname="org.apache.axis.utils.Admin" fork="yes">
      <classpath refid="classpath" />
      <arg value="client"/>
      <arg value="samples/security/clientsecuritydeploy.wsdd"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Stop Signature Signing and Verification -->
  <!-- =================================================================== -->
  <target name="stop-signature-signing-and-verification" if="security.present">
    <!-- Disable transparent Signing of SOAP Messages sent
        from the client and Server-side Signature Verification.
    -->
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="classpath" />
      <arg line="samples/security/serversecurityundeploy.wsdd"/>
    </java>
    <java classname="org.apache.axis.utils.Admin" fork="yes">
      <classpath refid="classpath" />
      <arg value="client"/>
      <arg value="samples/security/clientsecurityundeploy.wsdd"/>
    </java>

  </target>

  <!-- =================================================================== -->
  <!-- Prepares the JUnit functional test -->
  <!-- =================================================================== -->
  <target name="component-junit-functional-prepare" if="junit.present">

    <!-- first, put the JWS where the functional test can see it -->
    <mkdir dir="${axis.home}/build/jws" />
    <copy file="${axis.home}/samples/stock/StockQuoteService.jws" todir="${axis.home}/build/jws" />
    <copy file="${axis.home}/test/functional/AltStockQuoteService.jws" todir="${axis.home}/build/jws" />
    <copy file="${axis.home}/test/functional/GlobalTypeTest.jws" todir="${axis.home}/build/jws"/>

          <path id="deploy.xml.files">
                <fileset dir="${build.dir}">
                  <include name="work/${componentName}/**/deploy.wsdd"/>
                  <include name="${extraServices}/deploy.wsdd" />
                </fileset>
          </path>

          <path id="undeploy.xml.files">
                <fileset dir="${build.dir}">
                  <include name="work/${componentName}/**/undeploy.wsdd"/>
                  <include name="${extraServices}/undeploy.wsdd" />
                </fileset>
          </path>

          <property name="deploy.xml.property" refid="deploy.xml.files"/>
          <property name="undeploy.xml.property" refid="undeploy.xml.files"/>
  </target>
  
  <target name="component-test-run" if="junit.present" depends="start-signature-signing-and-verification">
    <echo message="Execing ${componentName} Test"/>
    <antcall target="component-junit-functional"/>
  </target>

  <target name="component-junit-functional" if="junit.present" depends="component-junit-functional-prepare">
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="classpath" />
      <arg line="${deploy.xml.property}"/>
    </java>

   <junit dir="${axis.home}" printsummary="yes" haltonfailure="${test.functional.fail}" fork="yes">
      <classpath refid="classpath" />
      <formatter type="xml" usefile="${test.functional.usefile}"/>
      <batchtest todir="${test.functional.reportdir}">
        <fileset dir="${build.dest}">
           <include name="${extraTestCases}/*TestCase.class" />
           <include name="${componentName}/*TestCase.class" />
           <include name="${componentName}/**/*TestCase.class" />
           <include name="${componentName}/**/PackageTests.class" />
           <!-- <include name="${componentName}/**/test/*TestSuite.class"/> -->
        </fileset>
      </batchtest>
   </junit>

    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="classpath" />
      <arg line="${undeploy.xml.property}"/>
    </java>
  </target>

  <target name="execute-Component"  depends="transport-layer" >
    <runaxisfunctionaltests
      url="http://localhost:${test.functional.TCPListenerPort}"
      startTarget1="start-functional-test-tcp-server"
      startTarget2="start-functional-test-http-server"
      testTarget="component-test-run"
      stopTarget="stop-functional-test-http-server" />
  </target>

  <target name="transport-layer" depends="setenv" >
    <mkdir dir="${test.functional.reportdir}" />
    <ant inheritAll="false" dir="${axis.home}/samples/transport" antfile="build.xml" target="compile" />
  </target>
