Permalink
Fetching contributors…
Cannot retrieve contributors at this time
516 lines (453 sloc) 22.9 KB
<?xml version="1.0"?>
<!--
Use the targets in this script to convert the separate markdown chapter files of
our documents into complete markdown, html, odt, and epub files.
Remember to use the script in the root directory of the document to be
converted, NOT THIS ONE.
For example, use the "ant markdown-to-all" command from the
documentation/trunk/userGuide directory to convert the userGuide into complete
English markdown, html, odt, and epub documents.
-->
<project name="Markdown Document Conversion" default="echo-props" basedir=".">
<property name="project.dir" value=".." />
<path id="lib.classpath">
<fileset dir="${project.dir}/lib" includes="*.jar" />
<fileset dir="${project.dir}/code/liferay-doc-utils/lib" includes="*.jar" />
</path>
<path id="project.classpath">
<path refid="lib.classpath" />
</path>
<property environment="env" />
<property file="../build.${USERNAME}.properties" />
<property file="../build.${user.name}.properties" />
<property file="../build.${env.COMPUTERNAME}.properties" />
<property file="../build.${env.HOST}.properties" />
<property file="../build.${env.HOSTNAME}.properties" />
<property file="../build.properties" />
<!-- property "doc.dir" will be specified in the build.xml of the document root directory. -->
<property name="lang" value="en"/>
<property name="build.dir" value="./build"/>
<property name="dist.dir" value="./dist"/>
<property name="pandoc.app" location="/home/${user.name}/.cabal/bin/pandoc"/>
<!-- taskdefs -->
<taskdef name="checkimgs" classname="com.liferay.documentation.util.CheckImagesTask">
<classpath>
<fileset dir="${project.dir}/lib" includes="*.jar" />
<!-- Use below instead of above fileset when testing changes to classes
<pathelement path="${project.dir}/code/liferay-doc-utils/classes"/>
-->
<fileset dir="${project.dir}/code/liferay-doc-utils/lib" includes="*.jar" />
</classpath>
</taskdef>
<taskdef name="checkdocprops" classname="com.liferay.documentation.util.CheckDocPropsTask">
<classpath>
<fileset dir="${project.dir}/lib" includes="*.jar" />
<!-- Use below instead of above fileset when testing changes to classes
<pathelement path="${project.dir}/code/liferay-doc-utils/classes"/>
-->
<fileset dir="${project.dir}/code/liferay-doc-utils/lib" includes="*.jar" />
</classpath>
</taskdef>
<taskdef name="cleanimgs" classname="com.liferay.documentation.util.CleanImagesTask">
<classpath>
<fileset dir="${project.dir}/lib" includes="*.jar" />
<!-- Use below instead of above fileset when testing changes to classes
<pathelement path="${project.dir}/code/liferay-doc-utils/classes"/>
-->
<fileset dir="${project.dir}/code/liferay-doc-utils/lib" includes="*.jar" />
</classpath>
</taskdef>
<taskdef name="numberimages" classname="com.liferay.documentation.util.NumberImagesTask">
<classpath>
<fileset dir="${project.dir}/lib" includes="*.jar" />
<!-- Use below instead of above fileset when testing changes to classes
<pathelement path="${project.dir}/code/liferay-doc-utils/classes"/>
-->
<fileset dir="${project.dir}/code/liferay-doc-utils/lib" includes="*.jar" />
</classpath>
</taskdef>
<taskdef name="stripheaderids" classname="com.liferay.documentation.util.StripHeaderIdsTask">
<classpath>
<fileset dir="${project.dir}/lib" includes="*.jar" />
<!-- Use below instead of above fileset when testing changes to classes
<pathelement path="${project.dir}/code/liferay-doc-utils/classes"/>
-->
<fileset dir="${project.dir}/code/liferay-doc-utils/lib" includes="*.jar" />
</classpath>
</taskdef>
<taskdef name="concatmarkdown" classname="com.liferay.documentation.util.ConcatMarkdown">
<classpath>
<fileset dir="${project.dir}/lib" includes="*.jar" />
<fileset dir="${project.dir}/code/liferay-doc-utils/lib" includes="*.jar" />
</classpath>
</taskdef>
<!-- targets -->
<target name="display-pandoc-version">
<exec executable="${pandoc.app}">
<arg value="-v" />
</exec>
</target>
<target name="echo-props">
<echo message="pandoc.app -> ${pandoc.app}"/>
</target>
<target name="check-images" description="verifies all images referenced in markdown files for a document or chapter">
<checkimgs docdir="${doc.dir}" lang="${lang}" chapter="${chapter}">
</checkimgs>
</target>
<target name="check-doc-props" description="checks that all document dirs have a valid doc.properties file">
<checkdocprops lang="${lang}" basedir="${project.dir}">
</checkdocprops>
</target>
<target name="clean-all" description="deletes residual directories">
<echo message="... deleting build directory"/>
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="clean-dist" description="deletes dist directory">
<echo message="... deleting dist directory"/>
<delete dir="${dist.dir}"/>
</target>
<target name="clean-images" description="removes unused images for a document">
<cleanimgs docdir="${doc.dir}" lang="${lang}">
</cleanimgs>
</target>
<target name="clean-lang" description="deletes build/${lang} directory">
<echo message="... deleting language specific residual directories"/>
<delete dir="${build.dir}/${lang}"/>
<delete dir="${dist.dir}/${lang}"/>
</target>
<target name="prepare" description="creates build/${lang} directory">
<echo message="... creating build/${lang} directory"/>
<mkdir dir="${build.dir}/${lang}"/>
<copy todir="${build.dir}/images">
<fileset dir="./${lang}/images"/>
</copy>
</target>
<target name="prepare-dist" depends="check-images, number-headers, number-images-dir" description="numbers the headers and images in the files, creates dist directory, copies images and overriding with language specific images">
<echo message="... creating ${dist.dir}/${lang} directory"/>
<mkdir dir="${dist.dir}/${lang}"/>
<copy todir="${dist.dir}/${lang}/images">
<fileset dir="images" includes="*.*"/>
</copy>
<copy overwrite="true" todir="${dist.dir}/${lang}/images">
<fileset dir="${lang}/images" includes="*.*"/>
</copy>
</target>
<target name="dist" depends="clean-lang, prepare-dist, concat-markdown-files" description="prepares document zip file for asset import">
<property file="./doc.properties" />
<copy todir="${dist.dir}/${lang}">
<fileset dir="${build.dir}/${lang}">
<include name="${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</fileset>
</copy>
<zip destfile="${dist.dir}/${lang}/${lang}-${product.abbrev}-${product.version}-${doc.dir}.zip">
<fileset dir="${dist.dir}/${lang}" includes="images/*.*"/>
<fileset dir="${dist.dir}/${lang}" includes="${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</zip>
</target>
<target name="concat-markdown-files" depends="prepare" description="concatenates multiple markdown files into a single one">
<property file="./doc.properties" />
<echo message="... concatenating markdown files for ${product.name} ${product.version}-${doc.name} (${lang})"/>
<concat destfile="./${build.dir}/${lang}/${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown" fixlastline = "yes">
<fileset dir="./${lang}" casesensitive="yes">
<include name="**/*.markdown"/>
</fileset>
</concat>
</target>
<target name="markdown-to-html" depends="check-images, add-markdown-metadata" description="converts markdown file to an html file">
<echo message="... converting ${product.name} ${product.version}-${doc.name} (${lang}) to html"/>
<!-- pandoc -f markdown -t html -o test-guide.html test-guide.markdown -->
<exec executable="${pandoc.app}">
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="html"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>
<arg value="-smart"/>-->
<arg value="-o"/>
<arg value="${build.dir}/${lang}/${lang}-${product.abbrev}-${product.version}-${doc.dir}.html"/>
<arg value="${build.dir}/${lang}/${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</exec>
</target>
<target name="markdown-to-html-win" depends="check-images, concat-markdown-files" description="converts markdown file to an html file on windows">
<echo message="... converting ${product.name} ${product.version}-${doc.name} (${lang}) to html"/>
<!-- pandoc -f markdown -t html +RTS K64m -RTS -o 01-chapter-02.html 01-chapter-02.markdown -->
<exec executable="cmd" dir="${build.dir}/${lang}">
<arg value="/C" />
<arg value="pandoc"/>
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="html"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>-->
<arg value="-smart"/>
<arg value="-o"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.html"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</exec>
</target>
<target name="markdown-to-odt" depends="check-images, add-markdown-metadata" description="converts markdown file to an odt file">
<echo message="... converting ${product.name} ${product.version}-${doc.name} (${lang}) to odt"/>
<!-- pandoc -f markdown -t odt -o test-guide.odt test-guide.markdown -->
<exec executable="${pandoc.app}" dir="${build.dir}/${lang}">
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="odt"/>
<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>
<arg value="-smart"/>
<arg value="-o"/>
<arg value="./${lang}-${product.abbrev}-${product.version}-${doc.dir}.odt"/>
<arg value="./${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</exec>
</target>
<target name="markdown-to-odt-win" depends="check-images, concat-markdown-files" description="converts markdown file to an ODT file on Windows">
<echo message="... converting ${product.name} ${product.version}-${doc.name} (${lang}) to odt on windows"/>
<!-- pandoc -f markdown -t odt +RTS K64m -RTS -o 01-chapter-02.odt 01-chapter-02.markdown -->
<exec executable="cmd" dir="${build.dir}/${lang}">
<arg value="/C" />
<arg value="pandoc"/>
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="odt"/>
<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>
<arg value="-smart"/>
<arg value="-o"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.odt"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</exec>
</target>
<target name="markdown-to-epub" depends="check-images, add-markdown-metadata" description="converts markdown file to an epub file">
<echo message="... converting ${product.name} ${product.version}-${doc.name} (${lang}) to epub"/>
<!-- pandoc -f markdown -t epub -o test-guide.epub test-guide.markdown -->
<exec executable="${pandoc.app}" dir="${build.dir}/${lang}">
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="epub"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>
<arg value="-smart"/>-->
<arg value="-o"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.epub"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</exec>
</target>
<target name="markdown-to-epub-win" depends="check-images, concat-markdown-files" description="converts markdown file to an epub file on windows">
<echo message="... converting ${product.name} ${product.version}-${doc.name} (${lang}) to epub"/>
<exec executable="cmd" dir="${build.dir}/${lang}">
<arg value="/C" />
<arg value="pandoc"/>
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="epub"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>-->
<arg value="-o"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.epub"/>
<arg value="${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
</exec>
</target>
<target name="markdown-to-all" depends="markdown-to-html,markdown-to-odt,markdown-to-epub" description="converts markdown file to html, odt, and epub files" />
<target name="markdown-to-all-win" depends="markdown-to-html-win,markdown-to-odt-win,markdown-to-epub-win" description="converts markdown file to html, odt, and epub files on windows" />
<target name="number-headers" depends="check-doc-props" description="numbers the headers of markdown files found in ${lang}/chapters/">
<java
classname="com.liferay.documentation.util.NumberHeadersTask"
classpathref="project.classpath"
failonerror="true"
fork="true"
>
<arg value="${doc.dir}"/>
<arg value="${lang}"/>
</java>
</target>
<target name="number-images-dir" description="numbers the images of markdown files found in ${lang}/chapters/">
<numberimages lang="${lang}" docDir="${doc.dir}">
</numberimages>
</target>
<target name="strip-header-ids-dir" description="strips out the header ids of markdown files found in ${lang}/chapters/">
<stripheaderids lang="${lang}" docDir="${doc.dir}">
</stripheaderids>
</target>
<target name="copy-single-chapter" depends="prepare" description="copies chapter to be converted">
<echo message="... copying ${chapter}"/>
<copy file="./en/chapters/${chapter}.markdown" todir="./${build.dir}/${lang}"/>
<move file="./${build.dir}/${lang}/${chapter}.markdown" tofile="./${build.dir}/${lang}/${lang}-${chapter}.markdown" />
</target>
<target name="chapter-to-html" depends="check-images, copy-single-chapter" description="converts single markdown chapter to an html file">
<echo message="... converting ${chapter} (${lang}) to html"/>
<!-- pandoc -f markdown -t html -o 01-introduction-to-liferay-ui.html 01-introduction-to-liferay-ui.markdown -->
<exec executable="${pandoc.app}" dir="${build.dir}/${lang}">
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="html"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>
<arg value="-smart"/>-->
<arg value="-o"/>
<arg value="${lang}-${chapter}.html"/>
<arg value="${lang}-${chapter}.markdown"/>
</exec>
</target>
<target name="chapter-to-html-win" depends="check-images, copy-single-chapter" description="converts single markdown chapter to an html file on windows">
<echo message="... converting ${chapter} (${lang}) to html"/>
<!-- pandoc -f markdown -t html -o 01-introduction-to-liferay-ui.html 01-introduction-to-liferay-ui.markdown -->
<exec executable="cmd" dir="${build.dir}/${lang}">
<arg value="/C" />
<arg value="pandoc"/>
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="html"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>-->
<arg value="-smart"/>
<arg value="-o"/>
<arg value="${lang}-${chapter}.html"/>
<arg value="${lang}-${chapter}.markdown"/>
</exec>
</target>
<target name="chapter-to-odt" depends="copy-single-chapter" description="converts single markdown chapter to an odt file">
<echo message="... converting ${chapter} (${lang}) to odt"/>
<!-- pandoc -f markdown -t odt -o 01-introduction-to-liferay-ui.odt 01-introduction-to-liferay-ui.markdown -->
<exec executable="${pandoc.app}" dir="${build.dir}/${lang}">
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="odt"/>
<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>
<arg value="-smart"/>
<arg value="-o"/>
<arg value="./${lang}-${chapter}.odt"/>
<arg value="./${lang}-${chapter}.markdown"/>
</exec>
</target>
<target name="chapter-to-odt-win" depends="copy-single-chapter" description="converts single markdown chapter to an odt file on windows">
<echo message="... converting ${chapter} (${lang}) to odt"/>
<!-- pandoc -f markdown -t odt -o 01-introduction-to-liferay-ui.odt 01-introduction-to-liferay-ui.markdown -->
<exec executable="cmd">
<arg value="/C" />
<arg value="pandoc"/>
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="odt"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>-->
<arg value="-smart"/>
<arg value="-o"/>
<arg value="${build.dir}/${lang}/${lang}-${chapter}.odt"/>
<arg value="${build.dir}/${lang}/${lang}-${chapter}.markdown"/>
</exec>
</target>
<target name="chapter-to-epub" depends="copy-single-chapter" description="converts single markdown chapter to an epub file">
<echo message="... converting ${chapter} (${lang}) to epub"/>
<!-- pandoc -f markdown -t epub -o 01-introduction-to-liferay-ui.odt 01-introduction-to-liferay-ui.markdown -->
<exec executable="${pandoc.app}">
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="epub"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>
<arg value="-smart"/>-->
<arg value="-o"/>
<arg value="${build.dir}/${lang}/${lang}-${chapter}.epub"/>
<arg value="${build.dir}/${lang}/${lang}-${chapter}.markdown"/>
</exec>
</target>
<target name="chapter-to-epub-win" depends="copy-single-chapter" description="converts single markdown chapter to an epub file on windows">
<echo message="... converting ${chapter} (${lang}) to epub"/>
<!-- pandoc -f markdown -t epub -o 01-introduction-to-liferay-ui.odt 01-introduction-to-liferay-ui.markdown -->
<exec executable="cmd">
<arg value="/C" />
<arg value="pandoc"/>
<arg value="-f" />
<arg value="markdown"/>
<arg value="-t"/>
<arg value="epub"/>
<!--<arg value="+RTS"/>
<arg value="-K64m"/>
<arg value="-RTS"/>-->
<arg value="-smart"/>
<arg value="-o"/>
<arg value="${build.dir}/${lang}/${lang}-${chapter}.epub"/>
<arg value="${build.dir}/${lang}/${lang}-${chapter}.markdown"/>
</exec>
</target>
<target name="chapter-to-all" depends="chapter-to-html,chapter-to-odt,chapter-to-epub" description="converts markdown chapter file to html, odt, and epub files" />
<target name="chapter-to-all-win" depends="chapter-to-html-win,chapter-to-odt-win,chapter-to-epub-win" description="converts markdown chapter file to html, odt, and epub files on windows" />
<target name="reset-images" description="resets the image numbers in a markdown chapter file">
<echo message="... resetting image numbers in ${chapter} (${lang})"/>
<java jar="../lib/liferay-doc-utils.jar" fork="true">
<arg value="ResetImages"/>
<arg value="./${lang}/chapters/${chapter}.markdown"/>
<!-- This is useful if you want to save the output to a new file without overwriting the original <arg value="${build.dir}/${chapter}.markdown"/> -->
</java>
</target>
<!-- Example: From liferay-docs/userGuide, enter the following command: ant number-images -Dchapter=12-administering-liferay-portal. Check liferay-docs/userGuide/build for your new file. The images should be numbered correctly. -->
<target name="number-images" depends="reset-images" description="numbers the images in a markdown chapter file">
<echo message="... numbering images in ${chapter} (${lang})"/>
<java jar="../lib/liferay-doc-utils.jar" fork="true">
<!-- <arg value="${build.dir}/${chapter}.markdown"/> -->
<arg value="NumberImages"/>
<arg value="./${lang}/chapters/${chapter}.markdown" />
<!-- This is useful if you want to save the output to a new file without overwriting the original <arg value="${build.dir}/${chapter}.markdown"/> -->
</java>
</target>
<!-- deprecated on Jan. 6, 2012 -->
<target name="add-markdown-metadata" depends="concat-markdown-files" description="adds metadata to the top of a concatenated markdown file">
<echo message="... adding metadata to ${product.name} ${product.version}-${doc.name} (${lang})"/>
<java jar="../lib/liferay-doc-utils.jar" fork="true">
<arg value="AddMarkdownMetadata"/>
<arg value="./${build.dir}/${lang}/${lang}-${product.abbrev}-${product.version}-${doc.dir}.markdown"/>
<arg value="${title}"/>
<arg value="${author}"/>
<arg value="${date}"/>
</java>
</target>
<target name="add-markdown-ch-template" description="adds metadata template to the top of a markdown chapter file">
<echo message="... adding metadata template to ${chapter} (${lang})"/>
<java jar="../lib/liferay-doc-utils.jar" fork="true">
<arg value="AddMarkdownChTemplate"/>
<arg value="./${lang}/chapters/${chapter}.markdown"/>
</java>
</target>
<target name="add-index" description="adds an index to the LaTeX source of a document before converting it to PDF">
<echo message="... adding index"/>
<java jar="../lib/liferay-doc-utils.jar" fork="true">
<arg value="AddIndex"/>
<arg value="en/print/en-userGuide.tex"/>
<arg value="userguide.lexicon"/>
<arg value="en/print/indexed-en-userGuide.tex"/>
</java>
<exec executable="xelatex">
<arg value="en/print/indexed-en-userGuide.tex"/>
</exec>
<exec executable="makeindex">
<arg value="en/print/indexed-en-userGuide"/>
</exec>
<exec executable="xelatex">
<arg value="en/print/indexed-en-userGuide.tex"/>
</exec>
</target>
</project>