<?xml version="1.0"?>

<!-- ===================================================================
     Load the deployment configuration from the properties file. We also load
     the run time options and define some properties based on some of the
     values found there
     =================================================================== -->
<project name="dirTools" basedir="." default="">

  <!-- =================================================================
       Build and run the directory tools
       ================================================================= -->

  <target name="dirToolInit" >
    <property name="org.bedework.project.bwtools"
              location="${org.bedework.project.bedework}/../bwtools" />
      
    <property name="app.dest.classes"
              location="${org.bedework.project.bwtools}/dist/tools/classes" />

    <delete dir="${app.dest.classes}" />
    <mkdir dir="${app.dest.classes}" />

    <path id="run.classpath">
      <fileset dir="${org.bedework.project.bwtools}/dist">
         <include name="*.jar"/>
      </fileset>
        <fileset dir="${org.bedework.project.bwtools}/lib">
           <include name="*.jar"/>
        </fileset>
      <pathelement location="${org.bedework.project.bwtools}/resources" />
      <pathelement location="${app.dest.classes}" />
    </path>

    <copy todir="${app.dest.classes}"
          file="${org.bedework.project.bwtools}/resources/log4j.xml" />

    <pathconvert property="run.txt.classpath"
                 refid="run.classpath"
                 targetos="unix"  pathsep=":" />
  </target>

  <target name="initDir" 
          description="Build and run directory init">
    <antfetch antfile="${org.bedework.project.bwtools}/build.xml" inheritall="false"
              target="initDir"
              return="org.bedework.directory.init.status" >
      <propertyset>
        <propertyref prefix="org.bedework.directory."/>
      </propertyset>
      <property name="org.bedework.libcache.dir"
                location="${org.bedework.project.bedework}/libcache"/>
    </antfetch>
  </target>

  <target name="initDirForQuickstart" depends="dirToolInit"
          description="Build and run directory tool to initialise a quickstart system">
    <java classname="org.bedework.tools.directory.DirTool"
          fork="true"
          failonerror="false"
          resultproperty="org.bedework.dirtool.status" >
      <classpath refid="run.classpath" />
      <arg value="-clean-for-quickstart" />
    </java>
  </target>

  <target name="addUser" depends="dirToolInit"
          description="Run directory tools to add a user">
    <java classname="org.bedework.tools.directory.DirTool"
          fork="true"
          failonerror="false"
          resultproperty="org.bedework.dirtool.status" >
      <classpath refid="run.classpath" />
      <arg value="-addUser" />
      <arg value="${org.bedework.directory.account}" />
      <arg value="${org.bedework.directory.firstname}" />
      <arg value="${org.bedework.directory.lastname}" />
      <arg value="${org.bedework.directory.caladdr}" />
      <arg value="${org.bedework.directory.password}" />
    </java>
  </target>

  <target name="addGroup" depends="dirToolInit"
          description="Build and run directory tools to add a group">
    <java classname="org.bedework.tools.directory.DirTool"
          fork="true"
          failonerror="false"
          resultproperty="org.bedework.dirtool.status" >
      <classpath refid="run.classpath" />
      <arg value="-addGroup" />
      <arg value="${org.bedework.directory.group}" />
      <arg value="${org.bedework.directory.group.member}" />
    </java>
  </target>

  <target name="addGroupMember" depends="dirToolInit"
          description="Build and run directory tools to add a group member">
    <java classname="org.bedework.tools.directory.DirTool"
          fork="true"
          failonerror="false"
          resultproperty="org.bedework.dirtool.status" >
      <classpath refid="run.classpath" />
      <arg value="-addGroupMember" />
      <arg value="${org.bedework.directory.group}" />
      <arg value="${org.bedework.directory.group.member}" />
    </java>
  </target>
</project>
