<target name="publisher" depends="build-scala,docs-scala" description="Deploys the Publisher and generates its documentation.">
<jar destfile="${www}/WEB-INF/railo/lib/Publisher.jar" basedir="${build.dir}"/>
<copy file="${scala.home}/lib/scala-library.jar" todir="${www}/WEB-INF/railo/lib"/>
</target>
${www} defines my web root and ${scala.home} defines where Scala is installed on my system.
Read on for more details of the build-scala and docs-scala tasks...The build-scala task compiles the .scala files to .class files (and is very similar to that shown on the Scala website):
<jar destfile="${www}/WEB-INF/railo/lib/Publisher.jar" basedir="${build.dir}"/>
<copy file="${scala.home}/lib/scala-library.jar" todir="${www}/WEB-INF/railo/lib"/>
</target>
<target name="build-scala" depends="init-scala" description="Build the Publisher Scala code.">
<mkdir dir="${build.dir}"/>
<scalac srcdir="${sources.dir}" destdir="${build.dir}" classpathref="build.classpath">
<include name="**/*.scala"/>
</scalac>
</target>
The docs-scala task generates JavaDoc-style API documentation from the source code. It's a good idea to do this automatically every time you build the system so the documentation is always up to date. I don't commit the generated docs to git so that no one accidentally gets hold of an old version.
<mkdir dir="${build.dir}"/>
<scalac srcdir="${sources.dir}" destdir="${build.dir}" classpathref="build.classpath">
<include name="**/*.scala"/>
</scalac>
</target>
<target name="docs-scala" depends="init-scala" description="Generate documentation for the Publisher.">
<mkdir dir="${docs.dir}" />
<scaladoc
srcdir="${sources.dir}"
destdir="${docs.dir}"
deprecation="yes" unchecked="yes" addparams="-access:private"
windowtitle="Publisher Documentation"
doctitle="<div>Publisher</div>"
classpathref="build.classpath">
<include name="**/*.scala" />
</scaladoc>
</target>
And finally the init-scala task sets up the Scala environment for the build / docs tasks:
<mkdir dir="${docs.dir}" />
<scaladoc
srcdir="${sources.dir}"
destdir="${docs.dir}"
deprecation="yes" unchecked="yes" addparams="-access:private"
windowtitle="Publisher Documentation"
doctitle="<div>Publisher</div>"
classpathref="build.classpath">
<include name="**/*.scala" />
</scaladoc>
</target>
<target name="init-scala" description="Set up the environment for Scala.">
<property name="scala-library.jar" value="${scala.home}/lib/scala-library.jar"/>
<path id="build.classpath">
<pathelement location="${scala-library.jar}"/>
<pathelement location="${www}/WEB-INF/lib/mysql-connector-java-bin.jar"/>
<pathelement location="${build.dir}"/>
</path>
<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<pathelement location="${scala.home}/lib/scala-compiler.jar" />
<pathelement location="${scala-library.jar}" />
</classpath>
</taskdef>
</target>
Note that we're relying on the MySQL JDBC driver (the Publisher reads large numbers of records from the database and converts them to a specific XML representation that is needed by a search engine).
The last part of the Ant build file is the high-level properties that specify where Scala is installed and the source, build and docs directories:
<property name="scala-library.jar" value="${scala.home}/lib/scala-library.jar"/>
<path id="build.classpath">
<pathelement location="${scala-library.jar}"/>
<pathelement location="${www}/WEB-INF/lib/mysql-connector-java-bin.jar"/>
<pathelement location="${build.dir}"/>
</path>
<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<pathelement location="${scala.home}/lib/scala-compiler.jar" />
<pathelement location="${scala-library.jar}" />
</classpath>
</taskdef>
</target>
<property name="scala.home" value="${basedir}/../scala"/>
<property name="sources.dir" value="${basedir}/../publisher/src"/>
<property name="build.dir" value="${basedir}/../publisher/build"/>
<property name="docs.dir" value="${basedir}/../publisher/docs"/>
My repo is structured so the build.xml file is in a build folder at the top level, Scala is installed in a scala folder also at the top level (yes, a minimal Scala installation is under git as part of our build process) and the Publisher code is in the publisher folder at the top level (with the source code under a src folder).<property name="sources.dir" value="${basedir}/../publisher/src"/>
<property name="build.dir" value="${basedir}/../publisher/build"/>
<property name="docs.dir" value="${basedir}/../publisher/docs"/>

0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment