<project default="default" xmlns:j="jelly:core" xmlns:ant="jelly:ant" 
         xmlns:license="license" xmlns:util="jelly:util" xmlns:maven="jelly:maven">

  <goal name="default" prereqs="jar:install"/>

  <preGoal name="java:compile">
    <mkdir dir="${pom.build.sourceDirectory}/org/activemq/selector"/>

    <javacc target="${basedir}/src/grammar/SelectorParser.jj"
      javacchome="${maven.repo.local}/javacc/jars"
      outputdirectory="${pom.build.sourceDirectory}/org/activemq/selector"/>
  </preGoal>

  <goal name="systest" description="Performs a complete system test">
    <attainGoal name="clean"/>
    <attainGoal name="jar:install-snapshot"/>

    <j:if test="${empty(goals)}">
      <j:set var="goals" value="default"/>
    </j:if>

    <maven:reactor
      basedir="${basedir}/modules/systest"
      includes="*/project.xml"
      excludes="jmscts/*,jdbc/*"
      banner="Executing (${goals}):"
      ignoreFailures="false"
      goals="${goals}"
      postProcessing="true"
      />
  </goal>

  <postGoal name="test:compile">

    <!-- Once the tests are compiled... install them -->
    <ant:jar
      jarfile="${maven.build.dir}/${pom.artifactId}-test-${pom.currentVersion}.jar"
      basedir="${maven.test.dest}"
      index="${maven.jar.index}"
      compress="${maven.jar.compress}"
      excludes="${maven.jar.excludes}">   
      
 
      <j:if test="${maven.jar.manifest.available}">
        <ant:setProperty name="manifest" value="${maven.jar.manifest}" />
      </j:if>

      <j:if test="${context.getVariable('maven.jar.includes') != null}">
        <ant:setProperty name="includes" value="${maven.jar.includes}" />
      </j:if>

      <j:set var="licenseFileName"><license:fileName/></j:set>
      <util:file name="${licenseFileName}" var="licenseFile"/>
      <ant:metainf dir="${licenseFile.canonicalFile.parent}">
        <ant:include name="${licenseFile.canonicalFile.name}"/>
      </ant:metainf>            
    </ant:jar>

    <mkdir dir="${maven.repo.local}/${pom.groupId}/jars"/>
    <copy todir="${maven.repo.local}/${pom.groupId}/jars"
          file="${maven.build.dir}/${pom.artifactId}-test-${pom.currentVersion}.jar"/>

  </postGoal>

  <goal name="run:multicasttester" prereqs="setclasspath">
    <echo>Running Multicast Tester </echo>
    <java classname="org.activemq.transport.multicast.MulticastTester" fork="yes" maxmemory="512M">
      <classpath refid="test.classpath"/>
      <j:if test="${empty(ignoreServer) || !empty(debug)}">
        <jvmarg value="-server"/>
      </j:if>
    </java>
  </goal>
  
  <goal name="setclasspath" prereqs="test:compile">
      <path id="test.classpath">
      <pathelement path="src/release/conf"/>
      <pathelement path="${maven.build.dest}"/>
      <pathelement path="target/classes"/>
      <pathelement path="target/test-classes"/>
      <path refid="maven.dependency.classpath"/>
    </path>
  </goal>

  <!-- Determine what the top-level project root is -->
  <j:set var="project.root" value="${pom.parentBasedir().getParentFile().getCanonicalFile()}"/>

  <!-- ================================================================ -->
  <!-- GOALS for running benchmarks -->
  <!-- ================================================================ -->

  <goal name="benchmark:store" prereqs="setclasspath">

    <echo>Running Store Benchmark</echo>
    <j:if test="${empty(MESSAGE_COUNT)}">
    		<j:set var="MESSAGE_COUNT" value="100000"/>
    </j:if>    
    <java classname="org.activemq.store.journal.JournalStoreBenchmark" fork="yes" maxmemory="512M">
      <classpath refid="test.classpath"/>
      <j:if test="${!empty(debug)}">
        <jvmarg value="-Xdebug"/>
        <jvmarg value="-Xnoagent"/>
        <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"/>
        <jvmarg value="-Djava.compiler=NONE"/>    
      </j:if>
      <j:if test="${empty(ignoreServer) || !empty(debug)}">
        <jvmarg value="-server"/>
      </j:if>
      <sysproperty key="MESSAGE_COUNT" value="${MESSAGE_COUNT}"/>
    </java>

  </goal>
  
  <goal name="benchmark:broker" prereqs="setclasspath">
    <echo>Running Broker Benchmark</echo>
    <j:if test="${empty(MESSAGE_COUNT)}">
    		<j:set var="MESSAGE_COUNT" value="1000"/>
    </j:if>    
    <java classname="org.activemq.store.journal.JournalBrokerBenchmark" fork="yes" maxmemory="512M">
      <classpath refid="test.classpath"/>
      <j:if test="${!empty(debug)}">
        <jvmarg value="-Xdebug"/>
        <jvmarg value="-Xnoagent"/>
        <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"/>
        <jvmarg value="-Djava.compiler=NONE"/>    
      </j:if>      
      <j:if test="${!empty(profile)}">
        <jvmarg value="-Xrunoii:${optimizeit.oii.options}"/>
        <jvmarg value="-Xbootclasspath/a:${optimizeit.oibcp.jar.path}"/>
        <jvmarg value="-DGCOPSIZE=5"/>
        <classpath path="${optimizeit.optit.jar.path}"/>
      </j:if>        
      <j:if test="${empty(ignoreServer) || !empty(debug)}">
        <jvmarg value="-server"/>
      </j:if>
      
      <!-- 4 * 50 Meg log files -->
      <sysproperty key="org.activeio.journal.active.DefaultLogFileCount" value="4"/>
      <sysproperty key="org.activeio.journal.active.DefaultLogFileSize"  value="52428800"/>
      
      <sysproperty key="MESSAGE_COUNT" value="${MESSAGE_COUNT}"/>
    </java>

  </goal>

</project>
