<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright (c) 2009 Tasktop Technologies and others.
    All rights reserved. This program and the accompanying materials
    are made available under the terms of the Eclipse Public License v1.0
    which accompanies this distribution, and is available at
    http://www.eclipse.org/legal/epl-v10.html
   
    Contributors:
         Tasktop Technologies - initial API and implementation
 -->
<project name="org.eclipse.mylyn.help.ui" default="all">
    <description>
            Generate Eclipse help content for the Mylyn user guide
    </description>
	
	<!-- To run this from Eclipse launch "org.eclipse.mylyn.help.ui build-helper.xml.launch" -->		

	<property name="mylyn.help.doc.url.base" value="http://wiki.eclipse.org"/>
	<property name="mylyn.wiki.url.base" value="${mylyn.help.doc.url.base}/Mylyn"/>
	<property name="imageFolder" value="images"/>
	
	<!-- used by pom.xml, currently disabled due to lack of Tycho integration
	<path id="wikitext.tasks.classpath">
		<pathelement path="${wikitext.tasks.classpath.path}"/>
	</path>
	-->
	
	<path id="wikitext.tasks.classpath">
		<pathelement location="../../org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext.core/@dot"/>
		<pathelement location="../../org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext.core/bin"/>
		<pathelement location="../../org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext.core/bin_ant"/>
		<pathelement location="../../org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext.core.ant/bin"/>
		<pathelement location="../../org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext.mediawiki.core/@dot"/>
		<pathelement location="../../org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext.mediawiki.core/bin"/>
		<pathelement location="../../org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext.mediawiki.core/bin_ant"/>
	</path>

	<taskdef classpathref="wikitext.tasks.classpath" resource="org/eclipse/mylyn/internal/wikitext/mediawiki/core/tasks/tasks.properties"/>
	<taskdef classpathref="wikitext.tasks.classpath" resource="org/eclipse/mylyn/wikitext/core/ant/tasks.properties"/>
	
	<target name="init">
		<mkdir dir="tmp"/>
	</target>
	
	<target name="clean" depends="init">
		<delete includeemptydirs="true" failonerror="false">
			<fileset dir="tmp"/>
		</delete>
	</target>

    <target name="all" depends="init" description="Generate Eclipse help content for the Mylyn user guide">
		
    	<mediawiki-to-eclipse-help
    		wikiBaseUrl="${mylyn.help.doc.url.base}"
			validate="true"
			failonvalidationerror="true"
			prependImagePrefix="${imageFolder}"
			formatoutput="true"
			defaultAbsoluteLinkTarget="mylyn_external"
    		dest="${basedir}"
    		title="Mylyn"
    		generateUnifiedToc="false">
    		<path name="Mylyn/User_Guide" title="Mylyn User Guide" generateToc="true"/>
    		<path name="Mylyn/FAQ" title="Mylyn FAQ" generateToc="true"/>
			<stylesheet url="book.css"/>
    		<pageAppendum>

= Updating This Document =

This document is maintained in a collaborative wiki.  If you wish to update or modify this document please visit 
{url}</pageAppendum>
    	</mediawiki-to-eclipse-help>
    	<replaceregexp file="Mylyn-User-Guide-toc.xml" match="(&lt;topic.*?href=&quot;Mylyn/User_Guide/Task-Repository-Connectors.html.*?&gt;(\s*&lt;topic\s*href=&quot;.*?&quot;\s*label=&quot;.*&quot;&gt;\s*?&lt;/topic&gt;)+)(\s*)(&lt;/topic&gt;)"
    			    		replace="\1\3&lt;anchor id=&quot;additions-repository-connectors&quot;/&gt;\3\4"
    						flags="s"/>
    	<antcall target="test"/>
    </target>
	

	<target name="test" depends="init" description="verify that all of the HTML files are well-formed XML">
		<echo level="info">
Validating help content XML and HTML files: The Eclipse help system expects well-formed XML
			
If validation fails it is because either:
			
* the userguide source code is poorly formed, or
* the WikiText MediaWiki parser has a bug
			
Problems with userguide source are usually caused by improper use of HTML markup in the MediaWiki source,
or inadvertently starting a line with a space character (in MediaWiki this starts a preformatted block)
		</echo>

		<!-- 
		Don't bother with DTD validation: we only care if the files are well-formed.
		We therefore provide an empty DTD 
		-->
		<mkdir dir="tmp"/>
		<echo file="tmp/__empty.dtd" message=""/>
		<xmlvalidate lenient="true">
			<fileset dir="Mylyn">
				<include name="**/*.xml"/>
			</fileset>
			<fileset dir="Mylyn">
				<include name="**/*.html"/>
			</fileset>
			<fileset dir=".">
				<include name="*toc.xml"/>
			</fileset>
			<dtd publicid="-//W3C//DTD XHTML 1.0 Transitional//EN" location="${basedir}/tmp/__empty.dtd"/>
		</xmlvalidate>
	</target>
</project>
