<?xml version="1.0"?>

<project xmlns:j="jelly:core" xmlns:u="jelly:util">

  <j:set var="wordSrcDir" value="${maven.word2html.src.dir}"/>


  <goal name="word2html:prepare-filesystem"
    description="Create directories needed for the plugin">
    <j:if test="${!wordSrcDir.equals('MAVEN_WORD2HTML_SRC_DIR_NOT_SET')}">
      <mkdir dir="${maven.build.dir}/docs/"/>
    </j:if>
  </goal>

  <goal name="word2html:generate"
        prereqs="xdoc:init,word2html:prepare-filesystem"
        description="Generate HTML docs from Word via CScript">

    <j:if test="${!wordSrcDir.equals('MAVEN_WORD2HTML_SRC_DIR_NOT_SET')}">
      <echo>scanning: ${wordSrcDir}</echo>

      <fileScanner var="wordFiles">
        <fileset dir="${wordSrcDir}">
          <patternset>
            <include name="**/*.doc"/>
            <exclude name="**/~*.doc"/>
          </patternset>
        </fileset>
      </fileScanner>

      <j:set var="docsDest"
        value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.dest')}"/>

      <j:forEach var="file" items="${wordFiles.iterator()}">
        <echo>Generating from ${file} to ${docsDest}</echo>
        <exec executable="cscript.exe">
          <arg value='//NoLogo'/>
          <arg value='"${plugin.resources}/word2html.vbs" "${file}"' />
          <arg value='"${docsDest}"' />
          <arg value='"${wordSrcDir}"' />
        </exec>

      </j:forEach>

    </j:if>
  </goal>

  <preGoal name="site">
    <j:if test="${!wordSrcDir.equals('MAVEN_WORD2HTML_SRC_DIR_NOT_SET')}">
      <attainGoal name="word2html:generate"/>
    </j:if>
  </preGoal>

</project>
