<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is part of the DITA Open Toolkit project hosted on 
     Sourceforge.net. See the accompanying license.txt file for 
     applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2006 All Rights Reserved. -->
<project name="dita2eclipsehelp" default="dita2eclipsehelp">
    <property name="transtype" value="eclipsehelp"/>
    
    <import file="build_init.xml" />
    <import file="build_preprocess.xml" />
    <import file="build_general.xml"/>
	
	   <target name="dita.index.eclipsehelp.init">
	      <condition property="dita.eclipsehelp.index.class" value="org.dita.dost.writer.EclipseIndexWriter"> 
	          <not><isset property="dita.eclipsehelp.index.class"></isset></not> 
	      </condition> 
	   </target>
	
	
    <target name="dita2eclipsehelp"
            unless="noMap"
        depends="build-init, preprocess, copy-css, 
                     dita.topics.xhtml, dita.inner.topics.xhtml, dita.outer.topics.xhtml">
      <antcall target="dita.map.eclipse"></antcall>
    </target>

    <!--<target name="dita.map.eclipse"
        depends="dita.map.eclipse.init, dita.map.eclipse.toc, dita.map.eclipse.index, dita.map.eclipse.plugin, dita.out.map.eclipse.toc, dita.out.map.eclipse.index, dita.out.map.eclipse.plugin" />-->

  <target name="dita.map.eclipse"
    depends=" dita.map.eclipse.init, copy-plugin-files, dita.map.eclipse.fragment.language.init, dita.map.eclipse.fragment.language.country.init, dita.map.eclipse.fragment.error">
    
  </target>
	
	<target name="dita.map.eclipse.init" if="eclipse.plugin"
	            depends="dita.map.eclipse.plugin.init">
	                <antcall target="dita.map.eclipse.generate.plugin"/>                     
	</target>

    <target name="dita.map.eclipse.plugin.init"
            description="Init properties for EclipseHelp">
        <basename property="dita.map.toc.root"
                  file="${dita.input.filename}"
                  suffix=".ditamap" />
        <condition property="args.eclipsehelp.toc" value="${dita.map.toc.root}">
            <not>
                <isset property="args.eclipsehelp.toc" />
            </not>
        </condition>
        <condition property="out.ext" value=".html">
            <not>
                <isset property="out.ext" />
            </not>
        </condition>
        <condition property="noPlugin">
            <equals arg1="${dita.eclipse.plugin}" arg2="no" />
        </condition>
      <condition property="eclipse.fragment.language">
        <and>
          <isset property="args.eclipsehelp.language" />
          <not>
            <isset property="args.eclipsehelp.country" />
          </not>
        </and>
      </condition>
      <condition property="eclipse.fragment.country">
        <and>
          <isset property="args.eclipsehelp.language" />
          <isset property="args.eclipsehelp.country" />
        </and>
      </condition>
      
      <condition property="eclipse.plugin">
        <not>
          <or>
            <isset property="args.eclipsehelp.language" />
            <isset property="args.eclipsehelp.country" />
            <and>
              <isset property="args.eclipsehelp.country" />
              <isset property="args.eclipsehelp.language" />
            </and>
          </or>
        </not>
      </condition>
      <condition property="eclipse.fragment.error">
        <and>
          <isset property="args.eclipsehelp.country" />
          <not>
            <isset property="args.eclipsehelp.language" />
          </not>
        </and>
      </condition>
    	<condition property="args.eclipsehelp.indexsee" value="false">
    	    <not>
    	      <isset property="args.eclipsehelp.indexsee"></isset>
    	    </not>
    	</condition>
    </target>

    <target name="dita.map.eclipse.toc" unless="noMap"
            depends="dita.map.eclipse.plugin.init" if="old.transform"
            description="Build EclipseHelp TOC file">
        <xslt processor="trax"
              basedir="${dita.temp.dir}"
              destdir="${output.dir}"
              includesfile="${dita.temp.dir}${file.separator}${fullditamapfile}"
              extension=".xml"
              classpathref="dost.class.path"
              style="${dita.script.dir}${file.separator}map2eclipse.xsl">
        	<excludesfile name="${dita.temp.dir}${file.separator}${resourceonlyfile}" if="resourceonlyfile"/>
            <includesfile name="${dita.temp.dir}${file.separator}${chunkedditamapfile}" if="chunkedditamapfile"/>
            <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
            <param name="OUTEXT" expression="${out.ext}" if="out.ext" />
            <param name="WORKDIR" expression="${workdir}" if="workdir"/>
        </xslt>
    </target>
    
    <target name="dita.out.map.eclipse.toc" unless="noMap"
        depends="dita.map.eclipse.plugin.init" if="inner.transform"
        description="Build EclipseHelp TOC file">
        <xslt processor="trax"
            basedir="${dita.temp.dir}"
            destdir="${output.dir}"
            includesfile="${dita.temp.dir}${file.separator}${fullditamapfile}"
            classpathref="dost.class.path"
            style="${dita.script.dir}${file.separator}map2eclipse.xsl">
        	<excludesfile name="${dita.temp.dir}${file.separator}${resourceonlyfile}" if="resourceonlyfile"/>
            <includesfile name="${dita.temp.dir}${file.separator}${chunkedditamapfile}" if="chunkedditamapfile"/>
            <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
            <param name="OUTEXT" expression="${out.ext}" if="out.ext" />
            <param name="WORKDIR" expression="${workdir}" if="workdir"/>
            <mapper type="regexp" 
                from="^(${tempdirToinputmapdir.relative.value})(.*?)(\.ditamap)$$" 
                to="\2\.xml"/>
        </xslt>
    </target>
    
    <target name="dita.map.eclipse.index" unless="noMap"
            if="old.transform"
      dita:depends="{dita.map.eclipse.index.pre},dita.map.eclipse.plugin.init,dita.index.eclipsehelp.init" 
    	      xmlns:dita="http://dita-ot.sourceforge.net" 
    	      dita:extension="depends org.dita.dost.platform.InsertDependsAction" 
            description="Build Eclipse Help index file">
    	  <echo level="info"> args.eclipsehelp.indexsee = ${args.eclipsehelp.indexsee} </echo>
    	  <pipeline message="Extract index term."
            module="IndexTermExtract"
            basedir="${basedir}"
            tempdir="${dita.temp.dir}"
            inputmap="${user.input.file}">
          <param name="output" location="${output.dir}${file.separator}${user.input.file}"/>
          <param name="targetext" value="${out.ext}"/>
          <param name="indextype" value="eclipsehelp"/>
          <param name="indexclass" value="${dita.eclipsehelp.index.class}"/>
          <param name="eclipse.indexsee" value="${args.eclipsehelp.indexsee}"/>
          <param name="encoding" value="${args.dita.locale}" if="args.dita.locale"/>
    	  </pipeline>
    </target>
    
    <target name="dita.out.map.eclipse.index" unless="noMap"
        if="inner.transform"
      dita:depends="{dita.map.eclipse.index.pre},dita.map.eclipse.plugin.init,dita.index.eclipsehelp.init" 
    	  xmlns:dita="http://dita-ot.sourceforge.net" 
    	  dita:extension="depends org.dita.dost.platform.InsertDependsAction" 
        description="Build Eclipse Help index file">
    	  <echo level="info"> args.eclipsehelp.indexsee = ${args.eclipsehelp.indexsee} </echo>
        <pipeline message="Extract index term."
            module="IndexTermExtract"
            basedir="${basedir}"
            tempdir="${dita.temp.dir}"
            inputmap="${user.input.file}">
          <param name="output" location="${output.dir}${file.separator}index.xml"/>
          <param name="targetext" value="${out.ext}"/>
          <param name="indextype" value="eclipsehelp"/>
          <param name="indexclass" value="${dita.eclipsehelp.index.class}"/>
          <param name="eclipse.indexsee" value="${args.eclipsehelp.indexsee}"/>
          <param name="encoding" value="${args.dita.locale}" if="args.dita.locale"/>
        </pipeline>
    </target>

    <target name="dita.map.eclipse.plugin"
            unless="noPlugin"
            depends="dita.map.eclipse.plugin.init" if="old.transform"
            description="Build Eclipsehelp plugin file">
        <xslt processor="trax"
              in="${dita.temp.dir}${file.separator}${user.input.file}"
              out="${dita.map.output.dir}${file.separator}plugin.xml"
              classpathref="dost.class.path"
              style="${dita.script.dir}${file.separator}map2plugin.xsl">
            <param name="TOCROOT" expression="${args.eclipsehelp.toc}" />
            <param name="version"
                   expression="${args.eclipse.version}"
                   if="args.eclipse.version" />
            <param name="provider"
                   expression="${args.eclipse.provider}"
                   if="args.eclipse.provider" />
        	  <param name="osgi.symbolic.name" 
        	  	     expression="${args.eclipse.symbolic.name}" 
        	  	     if="args.eclipse.symbolic.name"/>
        	  <outputproperty value="yes" name="indent"/>
        	  <param name="dita.plugin.output" 
        	        expression="dita.eclipse.plugin"/>  
        </xslt>
    </target>
    
    <target name="dita.out.map.eclipse.plugin"
        unless="noPlugin"
        depends="dita.map.eclipse.plugin.init" if="inner.transform"
        description="Build Eclipsehelp plugin file">
        <xslt processor="trax"
            in="${dita.temp.dir}${file.separator}${user.input.file}"
            out="${output.dir}${file.separator}plugin.xml"
            classpathref="dost.class.path"
            style="${dita.script.dir}${file.separator}map2plugin.xsl">
            <param name="TOCROOT" expression="${args.eclipsehelp.toc}" />
            <param name="version"
                expression="${args.eclipse.version}"
                if="args.eclipse.version" />
            <param name="provider"
                expression="${args.eclipse.provider}"
                if="args.eclipse.provider" />
        	  <param name="osgi.symbolic.name" 
        	      expression="${args.eclipse.symbolic.name}" 
        	      if="args.eclipse.symbolic.name"/>
        	  <outputproperty value="yes" name="indent"/>
        	  <param name="dita.plugin.output" 
        	        expression="dita.eclipse.plugin"/>  
        </xslt>
    </target>
  
  <!-- New support for creating Eclipse fragments based on the similar map used to create a plug-in -->
  
  
  
  <target name="dita.map.eclipse.manifest.file"
    unless="noPlugin"
    depends="dita.map.eclipse.plugin.init" if="old.transform"
    description="Build Eclipsehelp manifest.mf file">
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${user.input.file}"
      out="${dita.map.output.dir}${file.separator}META-INF${file.separator}MANIFEST.MF"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}map2plugin.xsl">
      <param name="version"
        expression="${args.eclipse.version}"
        if="args.eclipse.version" />
      <param name="provider"
        expression="${args.eclipse.provider}"
        if="args.eclipse.provider" />
    	<param name="osgi.symbolic.name" 
    	  expression="${args.eclipse.symbolic.name}" 
    	  if="args.eclipse.symbolic.name"/>
      <param name="plugin"
        expression="${eclipse.plugin}" />
      <param name="fragment.country" 
        expression="${args.eclipsehelp.country}" 
        if="eclipse.fragment.country"/>
      <param name="fragment.lang" 
        expression="${args.eclipsehelp.language}" 
        if="args.eclipsehelp.language"/>
      <outputproperty value="text" name="method"/>
      <param name="dita.plugin.output" 
        expression="dita.eclipse.manifest"/>                
    </xslt>
  </target>
  
  <target name="dita.out.map.eclipse.manifest.file"
    unless="noPlugin"
    depends="dita.map.eclipse.plugin.init" if="inner.transform"
    description="Build Eclipsehelp manifest.mf file">
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${user.input.file}"
      out="${dita.map.output.dir}${file.separator}META-INF${file.separator}MANIFEST.MF"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}map2plugin.xsl">
      <param name="version"
        expression="${args.eclipse.version}"
        if="args.eclipse.version" />
      <param name="provider"
        expression="${args.eclipse.provider}"
        if="args.eclipse.provider" />
    	<param name="osgi.symbolic.name" 
    	  expression="${args.eclipse.symbolic.name}" 
    	  if="args.eclipse.symbolic.name"/>
      <param name="plugin"
        expression="${eclipse.plugin}" />
      <param name="fragment.country" 
        expression="${args.eclipsehelp.country}" 
        if="eclipse.fragment.country"/>
      <param name="fragment.lang" 
        expression="${args.eclipsehelp.language}" 
        if="args.eclipsehelp.language"/>
      <outputproperty value="text" name="method"/>
      <param name="dita.plugin.output" 
        expression="dita.eclipse.manifest"/>                
    </xslt>
  </target>
  
  
  <target name="dita.map.eclipse.plugin.properties"
    unless="noPlugin"
    depends="dita.map.eclipse.plugin.init" if="old.transform"
    description="Create eclipse plugin.properties file">
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${user.input.file}"
      out="${output.dir}${file.separator}plugin.properties"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}map2plugin.xsl">
      <outputproperty value="text" name="method"/>
      <param name="dita.plugin.output" 
      	  expression="dita.eclipse.properties"/>
    	<param name="version"
    	    expression="${args.eclipse.version}"
    	    if="args.eclipse.version" />
    	<param name="provider"
    	    expression="${args.eclipse.provider}"
    	    if="args.eclipse.provider" />
    </xslt>
  </target>
  
  <target name="dita.out.map.eclipse.plugin.properties"
    unless="noPlugin"
    depends="dita.map.eclipse.plugin.init" if="inner.transform"
    description="Create eclipse plugin.properties file">
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${user.input.file}"
      out="${output.dir}${file.separator}plugin.properties"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}map2plugin.xsl">
      <outputproperty value="text" name="method"/>
      <param name="dita.plugin.output" expression="dita.eclipse.properties"/>
    	<param name="version"
          expression="${args.eclipse.version}"
          if="args.eclipse.version" />
      <param name="provider"
          expression="${args.eclipse.provider}"
          if="args.eclipse.provider" />
    </xslt>
  </target>
  
  <target name="dita.map.eclipse.fragment.language.init" if="eclipse.fragment.language"
    depends="dita.map.eclipse.plugin.init">
    <property name="fragment.dirname.init" value="nl" />
    <property name="fragment.dirname" value="${fragment.dirname.init}${file.separator}${args.eclipsehelp.language}"/>
    <property name="fragment.property.name" value="${args.eclipsehelp.language}"/>
    <antcall target="dita.map.eclipse.genetrate.fragment"/>
  </target>
  
  <target name="dita.map.eclipse.fragment.language.country.init" if="eclipse.fragment.country"
    depends="dita.map.eclipse.plugin.init">
    <property name="fragment.dirname.init" value="nl" />
    <property name="fragment.dirname" value="${fragment.dirname.init}${file.separator}${args.eclipsehelp.language}${file.separator}${args.eclipsehelp.country}"/>
    <property name="fragment.property.name" value="${args.eclipsehelp.language}_${args.eclipsehelp.country}"/>
    <antcall target="dita.map.eclipse.genetrate.fragment"/>
  </target>
	
	<target name="dita.map.eclipse.fragment.error" if="eclipse.fragment.error"
	                depends="dita.map.eclipse.plugin.init">
	            <echo message="The Eclipse Fragment property args.eclipsehelp.language was not set. "/>
	</target>
  
  <target name="dita.map.eclipse.fragment.move.files"
    if="old.transform">
    <defaultexcludes add="**/META-INF/**"/>
    <defaultexcludes add="**/nl/**"/>
  	<delete file="${output.dir}${file.separator}plugin.xml"/>
  	<delete file="${output.dir}${file.separator}plugincustomization.ini"/>
    <move todir="${dita.map.output.dir}${file.separator}${fragment.dirname}" includeemptydirs="yes">
      <fileset dir="${dita.map.output.dir}" defaultexcludes="yes">
        <exclude name="helpData.xml"/>
      	<exclude name="plugin.properties"/>
      	<exclude name="plugin_${fragment.property.name}.properties"/>
        <exclude name="*.list"/>
      	<exclude name="disabled_book.css"/>
      	<exclude name="narrow_book.css"/>
      	<exclude name="${os}_narrow_book.css"/>
      	<exclude name="book.css"/>
      	<exclude name="plugincustomization.ini"/>
      </fileset>
    </move>
  	<move file="${output.dir}${file.separator}plugin.properties" tofile="${output.dir}${file.separator}plugin_${fragment.property.name}.properties" failonerror="no"/>

  	
  </target>
  
  <target name="dita.out.map.eclipse.fragment.move.files"
    if="inner.transform">
    <defaultexcludes add="**/META-INF/**"/>
    <defaultexcludes add="**/nl/**"/>
  	<delete file="${output.dir}${file.separator}plugin.xml"/>
  	<delete file="${output.dir}${file.separator}plugincustomization.ini"/>
    <move todir="${output.dir}${file.separator}${fragment.dirname}" includeemptydirs="yes">
      <fileset dir="${output.dir}" defaultexcludes="yes">
        <exclude name="helpData.xml"/>
      	<exclude name="plugin.properties"/>
      	<exclude name="plugin_${fragment.property.name}.properties"/>
        <exclude name="*.list"/>
      	<exclude name="disabled_book.css"/>
      	<exclude name="narrow_book.css"/>
      	<exclude name="${os}_narrow_book.css"/>
      	<exclude name="book.css"/>
      	<exclude name="plugincustomization.ini"/>
      </fileset>
    </move>
  	<move file="${output.dir}${file.separator}plugin.properties" tofile="${output.dir}${file.separator}plugin_${fragment.property.name}.properties" failonerror="no"/>
  </target>
  
  <!--<target name="dita.map.eclipse"
    depends="dita.map.eclipse.init, 
    dita.map.eclipse.toc, 
    dita.map.eclipse.index, 
    dita.map.eclipse.plugin, 
    dita.out.map.eclipse.toc, 
    dita.out.map.eclipse.index, 
    dita.out.map.eclipse.plugin" />
  -->
  
  <target name="dita.map.eclipse.generate.plugin" 
    depends="dita.map.eclipse.toc, 
    dita.map.eclipse.index,
    dita.map.eclipse.plugin,
    dita.map.eclipse.plugin.properties, 
    dita.map.eclipse.manifest.file,
    dita.out.map.eclipse.plugin.properties, 
    dita.out.map.eclipse.manifest.file,
    dita.out.map.eclipse.toc, 
    dita.out.map.eclipse.index, 
    dita.out.map.eclipse.plugin" 
    >
    
  </target>
  

  
  <target name="dita.map.eclipse.genetrate.fragment" 
    depends="dita.map.eclipse.toc, 
    dita.map.eclipse.index, 
    dita.map.eclipse.plugin.properties, 
    dita.map.eclipse.manifest.file, 
    dita.out.map.eclipse.plugin.properties, 
    dita.out.map.eclipse.manifest.file, 
    dita.out.map.eclipse.toc, 
    dita.out.map.eclipse.index, 
    dita.out.map.eclipse.plugin,
    dita.map.eclipse.fragment.move.files,
    dita.out.map.eclipse.fragment.move.files">
    
  </target>

    <!-- depecrated: keep for back-compatibility, will be remvoed in a later release -->
    <target name="dita.topics.eclipse" depends="dita.topics.xhtml" />
	
	<target name="copy-plugin-files">
	  	<!-- Look for files that override behavior in Eclipse plugins -->
	  	<!-- <echo>* dita.input.dirname = ${user.input.dir}</echo> -->
	  	<copy todir="${output.dir}">
	  	      <fileset dir="${user.input.dir}">
	  	      	<include name="disabled_book.css"/>
	  	        <include name="narrow_book.css"/>
	  	        <include name="${os}_narrow_book.css"/>
	  	        <include name="book.css"/>
	  	        <include name="plugincustomization.ini"/>
	  	        <include name="helpData.xml"/>
	  	      </fileset>
	  		  
	  	</copy>
	</target>

</project>
