<?xml version="1.0" encoding="UTF-8"?>
<!--
     Copyright (c) 2005, 2007 IBM Corporation 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:
         IBM Corporation - initial API and implementation
 -->

<project name="RSE DStore ISV Doc Build" default="all" basedir=".">

	<property name="javadoc.link.location" value="${basedir}/javadoc.link.location"/>

	<target name="init">
		<available file="${basedir}/index" property="index.present" />
		<path id="path_bootclasspath">
			<fileset dir="${java.home}/lib">
				<include name="*.jar"/>
			</fileset>
		</path>
		<property name="bootclasspath" refid="path_bootclasspath"/>
		<condition property="safeBaseLocation"
			value="${baseLocation}"
			else="${eclipse.home}">
			<isset property="baseLocation"/>
		</condition>
		<delete dir="${javadoc.link.location}" />
	</target>

	<target name="computeClasspath" unless="javadoc.classpath">
		<!-- Construct the javadoc classpath and store it in a property. -->
		<echo level="info" message="Computing classpath ..."/>
		
		<!-- Add platform dependencies required by your plug-in here.
			 Note that this pattern expects Eclipse to have 
			 been installed into the platform directory structure, as is
			 the case during the build. -->
		<patternset id="platform.classpath.pattern">
			<include name="**/org.eclipse.core*.jar"/>
			<include name="**/org.eclipse.core*/**/*.jar"/>
        	<include name="**/org.eclipse.ui*.jar"/>
        	<include name="**/org.eclipse.ui*/**/*.jar"/>
        	<include name="**/org.eclipse.osgi*.jar"/>
        	<include name="**/org.eclipse.osgi*/**/*.jar"/>
        	<include name="**/org.eclipse.equinox*.jar"/>
        	<include name="**/org.eclipse.equinox*/**/*.jar"/>
        	<include name="**/org.eclipse.jface*.jar"/>
        	<include name="**/org.eclipse.jface*/**/*.jar"/>
        	<include name="**/org.junit*.jar"/>
        	<include name="**/org.junit*/**/*.jar"/>
			<include name="**/com.ibm.icu*.jar"/>
		</patternset>
			
		<pathconvert property="javadoc.classpath">
			<path>				
				<fileset dir="${safeBaseLocation}">
					<patternset refid="platform.classpath.pattern"/>
		    	</fileset>
			</path>
		</pathconvert>
		<echo level="info" message="Done computing classpath."/>
		<echo level="info" message="Bootclasspath is: ${bootclasspath}"/>
		<echo level="debug" message="Classpath is: ${javadoc.classpath}"/>
	</target>

	<target name="extractLinks">
		<mkdir dir="${javadoc.link.location}"/>
		
		<patternset id="package.list">
			<include name="**/package-list"/>
		</patternset>
		
		<!-- We only need the package-list files out of these -->
		<unzip dest="${javadoc.link.location}/platform/">
			<patternset refid="package.list"/>
			<fileset dir="${safeBaseLocation}/plugins">
				<include name="org.eclipse.platform.doc.isv*.jar"/>
			</fileset>
		</unzip>
	</target>

	<target name="all" depends="init" unless="index.present">
		<antcall target="convertSchemaToHtml" />
		<antcall target="generateJavadoc" />
		<antcall target="build.index" />
	</target>

	<target name="build.index" description="Builds search index for the plug-in: org.eclipse.dstore.doc.isv" if="eclipse.running">
		<help.buildHelpIndex manifest="${basedir}/plugin.xml" destination="${basedir}" />
	</target>

	<target name="convertSchemaToHtml" if="eclipse.running">
		<property name="dest" value="reference/extension-points" />
		<!--
		<record name="${basedir}/temp.convert.txt" action="start" />
		<pde.convertSchemaToHTML manifest="../org.eclipse.dstore.core/plugin.xml" destination="${dest}" />
		<record name="${basedir}/temp.convert.txt" action="stop" />
		-->
	</target>

	<target name="getJavadocPath">
		<available file="${java.home}/../bin/javadoc.exe" property="javadoc" value="${java.home}/../bin/javadoc.exe" />
		<available file="${java.home}/../bin/javadoc" property="javadoc" value="${java.home}/../bin/javadoc" />
		<available file="/usr/bin/javadoc" property="javadoc" value="/usr/bin/javadoc" />
		<available file="/shared/tools/tm/ibm-java2-ppc64-50/bin/javadoc" property="javadoc" value="/shared/tools/tm/ibm-java2-ppc64-50/bin/javadoc" />
	</target>

	<target name="generateJavadoc" depends="getJavadocPath,extractLinks,computeClasspath" if="javadoc">
		<property name="optionsFile" value="temp.options.txt" />
		<copy file="options.txt" tofile="${optionsFile}" overwrite="true" />
		
		<condition property="argsListDelimiter" value=":">
			<os family="unix" />
		</condition>
		<condition property="argsListDelimiter" value=";">
			<os family="windows" />
		</condition>

		<replaceregexp file="${basedir}/${optionsFile}" flags="g" match="(\r\n?|\n);" replace="${argsListDelimiter}" />
		<replace file="${basedir}/${optionsFile}" token="@rt@" value="${bootclasspath}" />
		<replace file="${basedir}/${optionsFile}" token="@cp@" value="${javadoc.classpath}" />
		<replace file="${basedir}/${optionsFile}" token="@baseLocation@" value="${safeBaseLocation}" />
		<replace file="${basedir}/${optionsFile}" token="@javadoc.link.location@" value="${javadoc.link.location}" />

		<!--scrub isv plugin directories of any preexisting api doc content-->
		<delete dir="reference/api" />
		<mkdir dir="reference/api" />

		<echo message="sep = ${argsListDelimiter}"/>
		<echo message="javadoc = ${javadoc}"/>
		<exec dir="." executable="${javadoc}" output="temp.bin.log" resultproperty="javadocResult">
			<arg line="@${basedir}/${optionsFile} -J-Xmx1000M" />
		</exec>
		<echo message="javadoc result = ${javadocResult}"/>
	</target>

</project>














