<?xml version="1.0"?>

<project name="htdocs" default="all">

  <!-- Helper that creates an HTML document from any file by wrapping -->
  <!-- it with a pre-element surrounded by appropriate headings.      -->
  <target name="txt2html">
    <loadfile property="main" srcfile="${fromfile}"/>

    <echo message="create ${tofile}"/>
    <copy file="${formatted.html}" tofile="${tofile}" overwrite="true"/>
    <replace file="${tofile}">
	<replacefilter token="$(MAIN)" value="${main}"/>
    </replace>
  </target>

  <target name="bundle_tasks">
    <ant target="bundle_tasks" dir=".."/>
  </target>

  <target name="all"
	  description="Creates html docs for distribution of a release">
    <!-- Set default values for all props used in the htdocs target. -->
    <property name="htdocs.out"     location="../out/htdocs"/>

    <property name="htdocs.dir"     location="."/>
    <property name="htdocs.ht.dir"  location="${htdocs.dir}/html_templates"/>
    <property name="htdocs.hs.dir"  location="${htdocs.dir}/html_src"/>

    <property name="template.html"  location="${htdocs.ht.dir}/template.html"/>
    <property name="formatted.html" location="${htdocs.ht.dir}/formatted.html"/>
    <property name="license.html"   location="${htdocs.hs.dir}/license.html"/>

    <property name="LICENSE.txt"    location="${distrib.dir}/LICENSE.txt"/>

    <property name="htdocs.distname" value="Knopflerfish OSGi, version ${version} - "/>
    <property name="base.url"
	      value="http://www.knopflerfish.org/releases"/>

    <!-- Properties used by the makehtml task. -->
    <property name="htdocs.link.enabled.class" value="navigation_enabled"/>
    <property name="htdocs.link.disabled.class" value="navigation_disabled"/>
    <property name="JAVADOC"
              value="${base.url}/${version}/docs/javadoc"/>
    <property name="css_navigation_enabled"     value="navigation_enabled"/>
    <property name="css_navigation_disabled"    value="navigation_disabled"/>
    <property name="navigation_pages"           value="INDEX PROG ECLIPSE LICENSE INSTALLING RUNNING BUILDING TESTING PROG COMP DESKTOP UBICORE CHANGELOG GIT TUTORIALS"/>

    <property name="release_notes.in.md.file"		location="${knopflerfish.dir}/release_notes.in.md"/>
    <property name="release_notes.distrib.md.file"      location="${distrib.dir}/release_notes.md"/>
    <property name="release_notes.distrib.html.file"    location="${distrib.dir}/release_notes.html"/>
    <property name="release_notes.tmp.html.file"	location="${distrib.tmp.dir}/release_notes.html"/>

    <antcall target="htdocs"/>
 </target>

 <target name="htdocs" depends="bundle_tasks">
   <loadfile property="htdocs.license.content" srcFile="${LICENSE.txt}"/>
   <copy file="${license.html}"
         tofile="${distrib.out.dir}/license.html">
     <filterset begintoken="@" endtoken="@">
       <filter token="LICENSE.txt" value="${htdocs.license.content}"/>
     </filterset>
   </copy>

   <makehtml description=""
             title=""
             template="${htdocs.ht.dir}/blank"
             outdir="${distrib.dir}"
             tofile="release_notes.md"
             fromfile="${release_notes.in.md.file}"
             disable=""/>

   <md2html fromfile="${release_notes.distrib.md.file}"
	    tofile="${release_notes.tmp.html.file}"/>
   
   <makehtml title="${htdocs.distname} Open Source OSGi Serivce Platform"
             description="The ${htdocs.distname} is an Open Source OSGi Service Platform designed to be compliant with the OSGi R5 specifications"
             template="${template.html}"
             outdir="${htdocs.out}"
             tofile="index.html"
             fromfile="${htdocs.dir}/html_src/index_main.html"
             disable="INDEX"/>

   <makehtml title="${htdocs.distname} Develop OSGi bundles"
             description="Information, tips and recommendations for developing OSGi bundles"
             template="${template.html}"
             outdir="${htdocs.out}"
             tofile="programming.html"
             fromfile="${htdocs.dir}/html_src/programming_main.html"
             disable="PROG"/>

    <makehtml title="${htdocs.distname} Knopflerfish Open Source License"
              description="${htdocs.distname} - BSD 3-style open source license"
              template="${template.html}"
              outdir="${htdocs.out}"
              tofile="license.html"
              fromfile="${distrib.out.dir}/license.html"
              disable="LICENSE"/>

    <!-- Standalone HTML version used by the desktop in its update check. -->
    <!-- Ensure that the text "Knopflerfish <VERSION>" is present on -->
    <!-- a singel line. -->
    <makehtml description="Release notes for ${htdocs.distname}"
              title="${htdocs.distname} Release Notes"
              template="${htdocs.ht.dir}/release_notes.html"
              outdir="${distrib.dir}"
              tofile="release_notes.html"
              fromfile="${release_notes.tmp.html.file}"
              disable="CHANGELOG"/>
    <!-- Version for the local documentation site. -->
    <makehtml title="${htdocs.distname} Release Notes"
              description="Release notes for this release of ${htdocs.distname}"
              template="${template.html}"
              outdir="${htdocs.out}"
              tofile="release_notes.html"
              fromfile="${release_notes.tmp.html.file}"
              disable="CHANGELOG"/>

    <makehtml title="${htdocs.distname} What is included in the Knopflerfish distribution"
              description="The contents of the ${htdocs.distname} distribution"
              template="${template.html}"
              outdir="${htdocs.out}"
              tofile="components.html"
              fromfile="${htdocs.dir}/html_src/components_main.html"
              disable="COMP"/>

   <makehtml title="${htdocs.distname} Installing Knopflerfish"
             description="Installing Knopflerfish OSGi"
             template="${template.html}"
             outdir="${htdocs.out}"
             tofile="installing.html"
             fromfile="${htdocs.dir}/html_src/installing.html"
             disable="INSTALLING"/>

   <makehtml title="${htdocs.distname} Running Knopflerfish"
             description="Running Knopflerfish OSGi"
             template="${template.html}"
             outdir="${htdocs.out}"
             tofile="running.html"
             fromfile="${htdocs.dir}/html_src/running.html"
             disable="RUNNING"/>

   <makehtml title="${htdocs.distname} Building"
             description="Building Knopflerfish OSGi"
             template="${template.html}"
             outdir="${htdocs.out}"
             tofile="building.html"
             fromfile="${htdocs.dir}/html_src/building.html"
             disable="BUILDING"/>

   <makehtml title="${htdocs.distname} Testing"
             description="Testing Knopflerfish OSGi"
             template="${template.html}"
             outdir="${htdocs.out}"
             tofile="testing.html"
             fromfile="${htdocs.dir}/html_src/testing.html"
             disable="TESTING"/>

   <makehtml title="${htdocs.distname} the famous KF Desktop bundle, visualizing the OSGi service platform"
             description="The Knopflerfish OSGi Desktop"
             template="${template.html}"
             outdir="${htdocs.out}"
             tofile="desktop.html"
             fromfile="${htdocs.dir}/html_src/desktop_main.html"
             disable="DESKTOP"/>

    <makehtml title="${htdocs.distname} Tutorials"
              description="The tutorials shipped with KF"
              template="${template.html}"
              outdir="${htdocs.out}"
              tofile="tutorials.html"
              fromfile="${htdocs.dir}/html_src/tutorials.html"
	      disable="TUTORIALS"/>

    <makehtml title="${htdocs.distname} OSGi Service Tutorial"
              description="The OSGi Service Tutorial"
              template="${template.html}"
              outdir="${htdocs.out}"
              tofile="osgi_service_tutorial.html"
              fromfile="${htdocs.dir}/html_src/osgi_service_tutorial.html"
	      disable="TUTORIALS"/>

    <makehtml title="${htdocs.distname} OSGi with Security"
              description="Running OSGi with Security"
              template="${template.html}"
              outdir="${htdocs.out}"
              tofile="osgi_with_security.html"
              fromfile="${htdocs.dir}/html_src/osgi_with_security.html"
	      disable="TUTORIALS"/>

    <makehtml title="${htdocs.distname} running on Android / Dalvik"
              description="Tutorial for running KF on Android / Dalvik"
              template="${template.html}"
              outdir="${htdocs.out}"
              tofile="android_dalvik_tutorial.html"
              fromfile="${htdocs.dir}/html_src/android_dalvik_tutorial.html"
	      disable="TUTORIALS"/>

    <echo message="${htdocs.out}"/>
 </target>

</project>
