lucene/solr/solr-ref-guide/build.xml

347 lines
15 KiB
XML

<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project name="solr-ref-guide" default="default" xmlns:asciidoctor="antlib:org.asciidoctor.ant" >
<import file="../common-build.xml"/>
<!-- properties to use in our docs -->
<loadresource property="solr-docs-version">
<!-- NOTE: this is specifically only the "major.minor", it does not include the ".bugfix"
This is because we (currently) only release the guide for minor versions.
-->
<propertyresource name="version"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replaceregex pattern="^(\d+\.\d+)(|\..*)$" replace="\1" flags="s"/>
</tokenfilter>
</filterchain>
</loadresource>
<loadresource property="solr-docs-version-path">
<!-- NOTE: This is the ${solr-docs-version} as a path suitbale for linking to javadocs -->
<propertyresource name="solr-docs-version"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replaceregex pattern="^(\d+)\.(\d+)(|\..*)$" replace="\1_\2_0" flags="s"/>
</tokenfilter>
</filterchain>
</loadresource>
<!-- NOTE: ${solr-guide-version} is the version of this ref-guide.
By default, we assume this is the same as ${solr-docs-version} with a "-DRAFT" suffix
When releasing, specify an explicit value of this property on the command line.
NOTE: the ${solr-guide-version} used *may* be different from the version of Solr the guide
covers if we decide to do a bug-fix release of the ref-guide
Examples: (assume branch_6_1 where version=6.1.SOMETHING)
Basic nightly/local build of the 6.1 guide...
=> ant build-pdf
Official release build of the 6.1 guide...
=> ant build-pdf -Dsolr-guide-version=6.1
Release of a "6.1.1" ref guide, correcting some serious error in the docs
(even if there is no 6.1.1 version - or if we've alreayd released up to 6.1.5 - of Solr itself)
=> ant build-pdf -Dsolr-guide-version=6.1.1
-->
<property name="solr-guide-version" value="${solr-docs-version}-DRAFT" />
<condition property="solr-guide-draft-status" value="" else="DRAFT">
<matches pattern="^\d+\.\d+(|\.\d+)$" string="${solr-guide-version}" />
</condition>
<loadresource property="solr-guide-version-path">
<!-- NOTE: This is the ${solr-guide-version} as a path suitable for use publishing the HTML -->
<propertyresource name="solr-guide-version"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replaceregex pattern="^(\d+)\.(\d+)(-DRAFT)?.*" replace="\1_\2\3" flags="s"/>
</tokenfilter>
</filterchain>
</loadresource>
<!-- where we link to javadocs from the html guide, and if we validate them, is all dependent
on the 'local.javadocs' sysprop -->
<condition property="check-all-relative-links" value="-check-all-relative-links" else="">
<isset property="local.javadocs" />
</condition>
<condition property="html-solr-javadocs"
value="link:../../docs/"
else="https://lucene.apache.org/solr/${solr-docs-version-path}/">
<isset property="local.javadocs" />
</condition>
<condition property="html-lucene-javadocs"
value="link:../../../../lucene/build/docs/"
else="https://lucene.apache.org/core/${solr-docs-version-path}/">
<isset property="local.javadocs" />
</condition>
<!-- for the PDF guide, we always use absolute javadoc urls -->
<property name="pdf-solr-javadocs" value="https://lucene.apache.org/solr/${solr-docs-version-path}/" />
<property name="pdf-lucene-javadocs" value="https://lucene.apache.org/core/${solr-docs-version-path}/" />
<property name="build.content.dir" location="${build.dir}/content" />
<property name="main-page" value="index" />
<property name="pdf-filename" value="apache-solr-ref-guide-${solr-guide-version}.pdf" />
<!-- for pulling in versions of major deps -->
<property prefix="ivyversions" file="${common.dir}/ivy-versions.properties"/>
<!-- ====== TOOLS FOR GENERATING/VALIDATING BITS OF THE SITE / PDF ======= -->
<property name="tools-jar-name" value="solr-ref-guide-tools.jar" />
<path id="tools-compile-classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
<exclude name="**/${tools-jar-name}" />
</fileset>
</path>
<path id="tools-run-classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${build.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="build-tools-jar" depends="resolve" description="Builds the custom java tools use use for generating some data files from page metdata">
<mkdir dir="${build.dir}/classes"/>
<!-- NOTE: we include the ant runtime so we can compile our customized version of the asciidoctor ant task -->
<javac debug="yes"
debuglevel="source,lines,vars"
destdir="${build.dir}/classes"
includeantruntime="true">
<compilerarg value="-Xlint:all"/>
<classpath refid="tools-compile-classpath"/>
<src path="tools/"/>
</javac>
<copy todir="${build.dir}/classes" file="tools/asciidoctor-antlib.xml" />
<jar destfile="${build.dir}/${tools-jar-name}">
<fileset dir="${build.dir}/classes"
includes="**/*.class,**/*.xml"/>
</jar>
</target>
<target name="build-init" description="Prepares the build's 'content' dir, copying over src files and transforming *.template files in the process">
<delete dir="${build.content.dir}" />
<mkdir dir="${build.content.dir}" />
<echo>Copying all non template files from src ...</echo>
<copy todir="${build.content.dir}">
<fileset dir="src">
<exclude name="**/*.template"/>
</fileset>
</copy>
<echo>Copy (w/prop replacement) any template files from src...</echo>
<copy todir="${build.content.dir}">
<fileset dir="src">
<include name="**/*.template"/>
</fileset>
<mapper type="glob" from="*.template" to="*"/>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
</target>
<target name="build-nav-data-files" depends="build-init,build-tools-jar" description="creates nav based data files needed by both the html and pdf artifacts">
<mkdir dir="${build.content.dir}/_data"/>
<java classname="BuildNavAndPDFBody"
failonerror="true"
fork="true">
<classpath refid="tools-run-classpath"/>
<arg value="${build.content.dir}"/>
<arg value="${main-page}"/>
</java>
</target>
<macrodef name="asciidoctor-convert">
<!-- custom macro that fills in all the defaults we care about when running asciidoctor-ant
The primary purpose for this is to build the PDF, but we also use it to build a bare-bones
HTML version for validating the document structure (ie: duplicate anchors, links all point to valid anchors,
etc...) that we can't do with the generated PDF, and that we want to be able to validate
even if the current user doesn't have jekyll installed
-->
<attribute name="sourceDirectory"/>
<attribute name="sourceDocumentName"/>
<attribute name="outputDirectory"/>
<attribute name="backend"/>
<attribute name="solr-javadocs" default="${pdf-solr-javadocs}" />
<attribute name="lucene-javadocs" default="${pdf-lucene-javadocs}" />
<attribute name="headerFooter" default="true" />
<sequential>
<!-- NOTE: we have our own variant on the asciidoctor-ant task, so that sourceDocumentName=""
is treated the same as if it's unset (ie: null)
-->
<taskdef uri="antlib:org.asciidoctor.ant" resource="asciidoctor-antlib.xml"
classpathref="tools-run-classpath"/>
<asciidoctor:convert
sourceDirectory="@{sourceDirectory}"
sourceDocumentName="@{sourceDocumentName}"
baseDir="${build.content.dir}"
outputDirectory="@{outputDirectory}"
preserveDirectories="true"
backend="@{backend}"
headerFooter="@{headerFooter}"
extensions="adoc"
sourceHighlighter="coderay"
imagesDir="${build.content.dir}"
doctype="book"
safemode="unsafe">
<attribute key="attribute-missing" value="warn" />
<attribute key="section-toc" value='' /><!-- we don't use these in the pdf -->
<attribute key="icons" value="font" />
<attribute key="icon-set" value="fa" />
<attribute key="pdf-stylesDir" value="./pdf/themes"/>
<attribute key="pdf-style" value="refguide"/>
<attribute key="pdf-fontsDir" value="./fonts"/>
<attribute key="figure-caption!" value='' />
<attribute key="idprefix" value='' />
<attribute key="idseparator" value='-' />
<!-- attributes used in adoc files -->
<!-- NOTE: If you add any attributes here for use in adoc files, you almost certainly need to also add
them to the _config.yml.template file for building the jekyll site as well
-->
<attribute key="solr-root-path" value="../../../" />
<attribute key="solr-guide-draft-status" value="${solr-guide-draft-status}" />
<attribute key="solr-guide-version" value="${solr-guide-version}" />
<attribute key="solr-docs-version" value="${solr-docs-version}" />
<attribute key="java-javadocs" value="${javadoc.link}" />
<attribute key="solr-javadocs" value="@{solr-javadocs}" />
<attribute key="lucene-javadocs" value="@{lucene-javadocs}" />
<attribute key="build-date" value="${DSTAMP}" />
<attribute key="build-year" value="${current.year}" />
<attribute key="ivy-commons-codec-version" value="${ivyversions./commons-codec/commons-codec}" />
<attribute key="ivy-dropwizard-version" value="${ivyversions.io.dropwizard.metrics.version}" />
<attribute key="ivy-log4j-version" value="${ivyversions.org.log4j.major.version}" />
<attribute key="ivy-opennlp-version" value="${ivyversions./org.apache.opennlp/opennlp-tools}" />
<attribute key="ivy-tika-version" value="${ivyversions.org.apache.tika.version}" />
<attribute key="ivy-velocity-tools-version" value="${ivyversions./org.apache.velocity/velocity-tools}" />
<attribute key="ivy-zookeeper-version" value="${ivyversions./org.apache.zookeeper/zookeeper}" />
</asciidoctor:convert>
</sequential>
</macrodef>
<!-- ====== PDF Build ======= -->
<target name="build-pdf" depends="bare-bones-html-validation,-build-pdf-and-reduce-pdf"
description="Builds the PDF (after building &amp; validating a bare-bones html version)" />
<target name="-build-pdf-and-reduce-pdf" depends="-build-raw-pdf,-reduce-pdf-size">
<!-- NOTE: this does everything realted to building the PDF, but skips the bare-bones-html validation -->
<echo>Finished Building ${build.dir}/${pdf-filename}</echo>
</target>
<target name="-build-raw-pdf"
depends="build-nav-data-files,resolve">
<mkdir dir="${build.dir}/pdf-tmp"/>
<asciidoctor-convert sourceDirectory="${build.content.dir}/pdf"
sourceDocumentName="SolrRefGuide-all.adoc"
outputDirectory="${build.dir}/pdf-tmp"
backend="pdf"
/>
<move file="${build.dir}/pdf-tmp/SolrRefGuide-all.pdf" tofile="${build.dir}/pdf-tmp/RAW-${pdf-filename}" />
</target>
<target name="-reduce-pdf-size" depends="build-init,build-tools-jar">
<java classname="ReducePDFSize"
failonerror="true"
fork="true">
<classpath refid="tools-run-classpath"/>
<arg value="${build.dir}/pdf-tmp/RAW-${pdf-filename}"/>
<arg value="${build.dir}/${pdf-filename}"/>
</java>
</target>
<!-- ======= HTML Site Build =======
Builds site with Jekyll.
This (for now) assumes that Jekyll (http://jekyllrb.com) is installed locally. -->
<target name="build-site"
depends="-build-site"
description="Builds an HTML Site w/Jekyll and verifies the anchors+links are valid" >
<java classname="CheckLinksAndAnchors"
failonerror="true"
fork="true">
<classpath refid="tools-run-classpath"/>
<arg value="${build.dir}/html-site"/>
<arg value="${check-all-relative-links}" />
</java>
<echo>Ready to browse site: ${build.dir}/html-site/${main-page}.html</echo>
</target>
<target name="-build-site"
depends="build-init,build-nav-data-files" >
<echo>Running Jekyll...</echo>
<exec executable="jekyll" dir="${build.content.dir}" failonerror="true">
<arg value="build"/>
</exec>
</target>
<!-- ======= HTML Bare Bones Conversion =======
Does a very raw converstion of the adoc files to HTML for the purpose of link & anchor checking
Unlike the "HTML Site Build" above, this does *NOT* require Jekyll, and can be done entirely
With ivy deps fetched automatically (just like the PDF)
-->
<target name="bare-bones-html-validation" depends="build-init,build-nav-data-files"
description="Builds (w/o Jekyll) a very simple html version of the guide and runs link/anchor validation on it">
<delete dir="${build.dir}/bare-bones-html"/>
<mkdir dir="${build.dir}/bare-bones-html"/>
<asciidoctor-convert sourceDirectory="${build.content.dir}"
sourceDocumentName=""
outputDirectory="${build.dir}/bare-bones-html"
headerFooter="false"
backend="html5"
solr-javadocs="${html-solr-javadocs}"
lucene-javadocs="${html-lucene-javadocs}"
/>
<java classname="CheckLinksAndAnchors"
failonerror="true"
fork="true">
<classpath refid="tools-run-classpath"/>
<arg value="${build.dir}/bare-bones-html"/>
<arg value="-bare-bones" />
<arg value="${check-all-relative-links}" />
</java>
<echo>Validated Links &amp; Anchors via: ${build.dir}/bare-bones-html/</echo>
</target>
<target name="default"
description="Builds both a PDF and HTML versions of the ref guide"
depends="-build-pdf-and-reduce-pdf,build-site">
<!-- NOTE: we don't depend on build-pdf because then we'd also get the bare-bones HTML and do
link validation twice -->
<echo>PDF: ${build.dir}/${pdf-filename}</echo>
<echo>SITE: ${build.dir}/html-site/${main-page}.html</echo>
</target>
</project>