<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project [
   <!ENTITY buildmagic SYSTEM "../tools/etc/buildmagic/buildmagic.ent">
   <!ENTITY libraries SYSTEM "../thirdparty/libraries.ent">
   <!ENTITY modules SYSTEM "../tools/etc/buildmagic/modules.ent">

]>

<!-- ====================================================================== -->
<!--                                                                        -->
<!--  JBoss, the OpenSource J2EE webOS                                      -->
<!--                                                                        -->
<!--  Distributable under LGPL license.                                     -->
<!--  See terms of license at http://www.gnu.org.                           -->
<!--                                                                        -->
<!-- ====================================================================== -->

<!-- $Id: build.xml 59909 2007-01-22 08:34:04Z scott.stark@jboss.org $ -->

<project default="main" name="JBoss/Security">

  <!-- ================================================================== -->
  <!-- Setup                                                              -->
  <!-- ================================================================== -->

  <!--
     | Include the common Buildmagic elements.
     |
     | This defines several different targets, properties and paths.
     | It also sets up the basic extention tasks amoung other things.
   -->

  &buildmagic;

  <!--
     | Initialize the build system.  Must depend on '_buildmagic:init'.
     | Other targets should depend on 'init' or things will mysteriously fail.
   -->

  <target name="init" unless="init.disable" depends="_buildmagic:init">
  </target>

  <!-- ================================================================== -->
  <!-- Configuration                                                      -->
  <!-- ================================================================== -->

  <!--
     | Configure the build system.
     |
     | This target is invoked by the Buildmagic initialization logic and
     | should contain module specific configuration elements.
   -->

  <target name="configure" unless="configure.disable">

    <!-- =================== -->
    <!-- Basic Configuration -->
    <!-- =================== -->

    <!-- Module name(s) & version -->
    <property name="module.name" value="security"/>
    <property name="module.Name" value="JBoss Security(JBossSX)"/>
    <property name="module.version" value="1.0"/>

    <!-- ========= -->
    <!-- Libraries -->
    <!-- ========= -->
    &libraries;
    <!-- The combined library classpath -->
    <path id="library.classpath">
      <path refid="apache.log4j.classpath"/>
      <path refid="apache.xerces.classpath"/>
      <path refid="dom4j.dom4j.classpath"/>
      <path refid="junit.junit.classpath"/>
      <path refid="hsqldb.hsqldb.classpath"/>
      <path refid="oswego.concurrent.classpath"/>
      <path refid="javassist.classpath"/>
      <path refid="jboss.jbossxb.classpath"/>
      <path refid="sun.javamail.classpath"/>
    </path>

    <!-- ======= -->
    <!-- Modules -->
    <!-- ======= -->
    &modules;
    <!-- The combined dependent module classpath -->
    <path id="dependentmodule.classpath">
      <path refid="jboss.j2ee.classpath"/>
      <path refid="jboss.common.classpath"/>
      <path refid="jboss.system.classpath"/>
      <path refid="jboss.naming.classpath"/>
      <path refid="jboss.transaction.classpath"/>
      <path refid="jboss.jmx.classpath"/>
    </path>

    <!-- ===== -->
    <!-- Tasks -->
    <!-- ===== -->

    <!-- Where build generated files will go -->
    <property name="build.reports" value="${module.output}/reports"/>
    <property name="build.classes" value="${module.output}/classes"/>
    <property name="build.lib" value="${module.output}/lib"/>
    <property name="build.api" value="${module.output}/api"/>
    <property name="build.etc" value="${module.output}/etc"/>
    <property name="build.tests" value="${module.output}/tests"/>
    <property name="javac.source" value="5"/>
    <property name="javac.target" value="5"/>

    <!-- The combined thirdparty classpath -->
    <path id="thirdparty.classpath">
      <path refid="library.classpath"/>
      <path refid="dependentmodule.classpath"/>
    </path>

    <!-- classpath and local.classpath must have a value using with a path -->
    <property name="classpath" value=""/>
    <property name="local.classpath" value=""/>

    <!-- The classpath required to build classes. -->
    <path id="javac.classpath">
      <pathelement path="${classpath}"/>
      <pathelement path="${local.classpath}"/>
      <path refid="thirdparty.classpath"/>
    </path>

    <!-- The classpath required to build javadocs. -->
    <path id="javadoc.classpath">
      <path refid="javac.classpath"/>
    </path>

    <!-- Packages to include when generating api documentation -->
    <property name="javadoc.packages" value="org.jboss.*"/>

    <!-- Override JUnit defaults -->
    <property name="junit.timeout" value="240000"/> <!-- 4 minutes -->
    <property name="junit.batchtest.todir" value="${build.reports}"/>
    <property name="junit.jvm.options" value="-Ddummy"/>
     <call target="_default:task-init"/>
  </target>


  <!-- ================================================================== -->
  <!-- Compile                                                            -->
  <!-- ================================================================== -->

  <!--
     |  Compile everything.
     |
     |  This target should depend on other compile-* targets for each
     |  different type of compile that needs to be performed, short of
     |  documentation compiles.
    -->
  <target name="compile"
    depends="compile-parsers, compile-classes, compile-etc"
    description="Compile all source files."/>

  <!-- Compile parsers -->
  <target name="compile-parsers" depends="init">
    <mkdir dir="${build.parsers}/org/jboss/security/auth/login"/>

    <!-- Sun JAAS config file parser -->
    <javacc target="${source.java}/org/jboss/security/auth/login/SunConfigParser.jj"
      outputdirectory="${build.parsers}/org/jboss/security/auth/login"
      javacchome="${sun.javacc.lib}"
      static="false"/>
  </target>

  <!-- Compile all class files -->
  <target name="compile-classes" depends="init">
    <mkdir dir="${build.classes}"/>
    <javac destdir="${build.classes}"
      optimize="${javac.optimize}"
      target="${javac.target}"
      source="${javac.source}"
      debug="${javac.debug}"
      depend="${javac.depend}"
      verbose="${javac.verbose}"
      deprecation="${javac.deprecation}"
      includeAntRuntime="${javac.include.ant.runtime}"
      includeJavaRuntime="${javac.include.java.runtime}"
      includes="${javac.includes}"
      excludes="${javac.excludes}"
      failonerror="${javac.fail.onerror}">
      <src path="${source.java}"/>
      <src path="${build.parsers}"/>
      <classpath refid="javac.classpath"/>
    </javac>
  </target>

  <!-- Compile manifests -->
  <target name="compile-etc" depends="init">
    <mkdir dir="${build.etc}"/>
    <copy todir="${build.etc}" filtering="yes">
      <fileset dir="${source.etc}">
        <include name="**"/>
      </fileset>
    </copy>

    <copy todir="${build.classes}">
      <fileset dir="${source.java}">
        <include name="org/jboss/security/jacc/*.xml"/>
      </fileset>
    </copy>
  </target>


  <!-- ================================================================== -->
  <!-- Archives                                                           -->
  <!-- ================================================================== -->

  <!--
     |  Build all jar files.
    -->
  <target name="jars" description="Builds all jar files."
    depends="_buildmagic:build-bypass-check"
    unless="build-bypass.on">

    <call target="compile"/>

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

    <!-- Build jbosssx.jar -->
    <jar jarfile="${build.lib}/jbosssx.jar"
      manifest="${build.etc}/default.mf">
      <fileset dir="${build.classes}">
        <include name="org/jboss/crypto/**"/>
        <include name="org/jboss/security/**"/>
      </fileset>
      <fileset dir="${source.resources}">
        <include name="dtd/security-policy.dtd"/>
      </fileset>
    </jar>

    <!-- Build jbosssx-client.jar -->
    <jar jarfile="${build.lib}/jbosssx-client.jar"
      manifest="${build.etc}/default.mf">
      <fileset dir="${build.classes}">
        <exclude name="META-INF/MANIFEST.MF"/> <!-- HACK -->
        <include name="org/jboss/crypto/JBossSXProvider.class"/>
        <include name="org/jboss/crypto/digest/*"/>
        <include name="org/jboss/security/*"/>
        <include name="org/jboss/security/auth/callback/*"/>
        <include name="org/jboss/security/auth/login/*"/>
        <exclude name="org/jboss/security/auth/login/XMLLoginConfig.class"/>
        <exclude name="org/jboss/security/auth/login/XMLLoginConfigMBean.class"/>
        <include name="org/jboss/security/jndi/*"/>
        <include name="org/jboss/security/plugins/PBEUtils.class"/>
        <include name="org/jboss/security/srp/PkgCategory.class"/>
        <include name="org/jboss/security/srp/TracePriority.class"/>
        <include name="org/jboss/security/srp/SRPClientSession.class"/>
        <include name="org/jboss/security/srp/SRPServerInterface*.class"/>
        <include name="org/jboss/security/srp/SRPServerProxy.class"/>
        <include name="org/jboss/security/srp/SRPParameters.class"/>
        <include name="org/jboss/security/srp/SRPPermission.class"/>
        <include name="org/jboss/security/srp/SRPConf*.class"/>
        <include name="org/jboss/security/srp/SRPRemoteServer_Stub.class"/>
        <include name="org/jboss/security/srp/SRPRemoteServerInterface.class"/>
        <include name="org/jboss/security/srp/SRPVerifierStore.class"/>
        <include name="org/jboss/security/srp/SRPVerifierStore$*.class"/>
        <include name="org/jboss/security/srp/jaas/SRPLoginModule.class"/>
        <include name="org/jboss/security/srp/jaas/SRPPrincipal.class"/>
        <include name="org/jboss/security/ssl/ClientSocketFactory.class"/>
        <include name="org/jboss/security/ssl/RMISSLClientSocketFactory.class"/>
      </fileset>
    </jar>

    <!-- Build jbosssx-tests.jar -->
    <mkdir dir="${build.tests}"/>
    <jar jarfile="${build.tests}/jbosssx-tests.jar"
      manifest="${build.etc}/default.mf">
      <fileset dir="${build.classes}">
        <include name="org/jboss/test/TestLoginModule.class"/>
      </fileset>
    </jar>

    <!-- Update the build marker to allow bypassing -->
    <touch file="${build-bypass.marker}"/>

  </target>

  <!-- ================================================================== -->
  <!-- Install & Release                                                  -->
  <!-- ================================================================== -->

  <target name="install"
    description="Install the structure for a release."
    depends="all, _buildmagic:install:default"/>

  <target name="release" depends="install"/>

  <target name="release-zip"
    description="Builds a ZIP distribution."
    depends="release, _buildmagic:release:zip"/>

  <target name="release-tar"
    description="Builds a TAR distribution."
    depends="release, _buildmagic:release:tar"/>

  <target name="release-tgz"
    description="Builds a TAR-GZ distribution."
    depends="release, _buildmagic:release:tgz"/>

  <target name="release-all"
    description="Builds a distribution for each archive type."
    depends="release-zip, release-tgz"/>


  <!-- ================================================================== -->
  <!-- Cleaning                                                           -->
  <!-- ================================================================== -->

  <!-- Clean up all build output -->
  <target name="clean"
    description="Cleans up most generated files."
    depends="_buildmagic:clean">
  </target>

  <!-- Clean up all generated files -->
  <target name="clobber"
    description="Cleans up all generated files."
    depends="_buildmagic:clobber, clean">
  </target>


  <!-- ================================================================== -->
  <!-- Misc.                                                              -->
  <!-- ================================================================== -->

  <target name="main"
    description="Executes the default target (most)."
    depends="most"/>

  <target name="all"
    description="Builds everything."
    depends="jars, docs"/>

  <target name="most"
    description="Builds almost everything."
    depends="jars"/>

  <target name="help"
    description="Show this help message."
    depends="_buildmagic:help:standard"/>


  <!-- ================================================================== -->
  <!-- Tests                                                              -->
  <!-- ================================================================== -->

  <!--
     | Run all tests.
   -->

  <target name="tests" depends="init, tests-junit, tests-reports"
    description="Execute all tests.">
  </target>

  <!--
     | Run JUnit tests.
   -->

  <target name="tests-junit" depends="jars">
    <mkdir dir="${build.reports}"/>
    <property name="conf.dir" value="${source.java}/org/jboss/test"/>
    <junit dir="${module.output}"
      printsummary="${junit.printsummary}"
      haltonerror="${junit.haltonerror}"
      haltonfailure="${junit.haltonfailure}"
      fork="${junit.fork}"
      timeout="${junit.timeout}"
      jvm="${junit.jvm}">

      <sysproperty key="output.dir" file="${module.output}"/>
      <sysproperty key="jboss.home" file="${project.root}"/>
      <jvmarg value="${junit.jvm.options}"/>
      <jvmarg value="-Djava.security.debug=access,failure"/>
      <jvmarg value="-Djava.security.manager"/>
      <jvmarg value="-Djava.security.policy=${conf.dir}/tst.policy"/>

      <classpath>
        <pathelement location="${build.classes}"/>
        <pathelement location="${module.source}/main/org/jboss/test"/>
        <path refid="javac.classpath"/>
      </classpath>

      <formatter type="${junit.formatter.type}"
        usefile="${junit.formatter.usefile}"/>

      <batchtest todir="${build.reports}"
        haltonerror="${junit.batchtest.haltonerror}"
        haltonfailure="${junit.batchtest.haltonfailure}"
        fork="${junit.batchtest.fork}">

        <fileset dir="${build.classes}">
          <include name="**/*TestCase.class"/>
          <include name="**/*TestSuite.class"/>
        </fileset>
      </batchtest>
    </junit>
  </target>

  <target name="test-jaas10-junit" depends="compile">
    <mkdir dir="${build.reports}"/>
    <property name="conf.dir" value="${source.java}/org/jboss/test"/>
    <junit dir="${module.output}"
      printsummary="${junit.printsummary}"
      haltonerror="${junit.haltonerror}"
      haltonfailure="${junit.haltonfailure}"
      fork="${junit.fork}"
      timeout="${junit.timeout}"
      jvm="${junit.jvm}">

      <sysproperty key="conf.dir" value="${conf.dir}"/>
      <sysproperty key="output.dir" file="${module.output}"/>
      <sysproperty key="jboss.home" file="${project.root}"/>
      <sysproperty key="jbosstest.deploy.dir" file="${build.lib}"/>
      <jvmarg value="${junit.jvm.options}"/>
      <jvmarg value="-Djava.security.debug=access,failure"/>
      <jvmarg value="-Djava.security.manager"/>
      <jvmarg value="-Djava.security.policy=${conf.dir}/tst.policy"/>

      <classpath>
        <pathelement location="${build.lib}/jbosssx.jar"/>
        <pathelement location="${build.tests}/jbosssx-tests.jar"/>
        <pathelement location="${build.classes}"/>
        <pathelement location="${conf.dir}"/>
        <path refid="javac.classpath"/>
      </classpath>

      <formatter type="${junit.formatter.type}"
        usefile="${junit.formatter.usefile}"/>

      <test todir="${build.reports}" name="org.jboss.test.LoginContextTestCase"/>
    </junit>
  </target>

  <target name="test-jbossjaas-junit" depends="compile">
    <mkdir dir="${build.reports}"/>
    <property name="conf.dir" value="${source.java}/org/jboss/test"/>
    <junit dir="${module.output}"
      printsummary="${junit.printsummary}"
      haltonerror="${junit.haltonerror}"
      haltonfailure="${junit.haltonfailure}"
      fork="${junit.fork}"
      timeout="${junit.timeout}"
      jvm="${junit.jvm}">

      <sysproperty key="output.dir" file="${module.output}"/>
      <sysproperty key="jboss.home" file="${project.root}"/>
      <sysproperty key="jbosstest.deploy.dir" file="${build.lib}"/>
      <jvmarg value="${junit.jvm.options}"/>
      <jvmarg value="-Djava.security.debug=access,failure"/>
      <jvmarg value="-Djava.security.manager"/>
      <jvmarg value="-Djava.security.policy=${conf.dir}/tst.policy"/>
      <sysproperty key="conf.dir" value="${conf.dir}"/>
      <sysproperty key="jboss.home" value="${jboss.home}"/>
      <sysproperty key="output.dir" value="${output.dir}"/>
      <sysproperty key="jbosstest.deploy.dir" value="${build.lib}"/>

      <classpath>
        <pathelement location="${build.lib}/jboss-jaas.jar"/>
        <pathelement location="${build.lib}/jbosssx.jar"/>
        <pathelement location="${build.tests}/jbosssx-tests.jar"/>
        <pathelement location="${build.classes}"/>
        <pathelement location="${conf.dir}"/>
        <path refid="javac.classpath"/>
      </classpath>

      <formatter type="${junit.formatter.type}"
        usefile="${junit.formatter.usefile}"/>

      <test todir="${build.reports}" name="org.jboss.test.LoginContextTestCase"/>
    </junit>
  </target>

  <target name="test-parser-junit" depends="compile">
    <mkdir dir="${build.reports}"/>
    <property name="conf.dir" value="${source.java}/org/jboss/test"/>
    <junit dir="${module.output}"
      printsummary="${junit.printsummary}"
      haltonerror="${junit.haltonerror}"
      haltonfailure="${junit.haltonfailure}"
      fork="${junit.fork}"
      timeout="${junit.timeout}"
      jvm="${junit.jvm}">

      <jvmarg value="${junit.jvm.options}"/>
      <sysproperty key="jbosstest.deploy.dir" file="${build.lib}"/>

      <classpath>
        <pathelement location="${build.classes}"/>
        <pathelement location="${module.source}/main/org/jboss/test"/>
        <path refid="javac.classpath"/>
      </classpath>

      <formatter type="${junit.formatter.type}"
        usefile="${junit.formatter.usefile}"/>

      <test todir="${build.reports}" name="org.jboss.test.SunConfigParserTestCase"/>
    </junit>
  </target>

  <target name="reports" depends="tests-reports"
    description="Generates all reports."/>

  <target name="tests-reports" depends="tests-reports-html"/>

  <target name="tests-reports-html" depends="compile">
    <mkdir dir="${build.reports}/html"/>

    <junitreport todir="${build.reports}">
      <fileset dir="${build.reports}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" todir="${build.reports}/html"/>
    </junitreport>
  </target>

</project>
