blob: f8813d4791c392a7648b3101f6efedf3461f0025 [file] [log] [blame]
<!--
* Licensed 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.
*
* Author: anorth@google.com (Alex North)
-->
<project name="macros">
<!-- Macro which compiles a set of PST message templates -->
<macrodef name="pstmessage">
<attribute name="proto" description="Protocol buffer class file"/>
<sequential>
<runpst proto="@{proto}"
templates='"${src.dir}/org/waveprotocol/pst/templates/api/api.st"
"${src.dir}/org/waveprotocol/pst/templates/builder/builder.st"
"${src.dir}/org/waveprotocol/pst/templates/pojo/pojo.st"
"${src.dir}/org/waveprotocol/pst/templates/jso/jso.st"
"${src.dir}/org/waveprotocol/pst/templates/util/util.st"
"${src.dir}/org/waveprotocol/pst/templates/gson/gson.st"
"${src.dir}/org/waveprotocol/pst/templates/proto/proto.st"'
outputdir="${gen.dir}/messages"/>
</sequential>
</macrodef>
<!-- Macro which runs the PST compiler.
Don't use this directly, use pstmessage. -->
<macrodef name="runpst">
<attribute name="proto" description="Protocol buffer class file"/>
<attribute name="templates" description="Template files"/>
<attribute name="outputdir" description="Output directory"/>
<sequential>
<java failonerror="true" fork="true" classname="org.waveprotocol.pst.PstMain">
<classpath>
<path refid="libpath"/>
<path location="${dist.dir}/pst.jar"/>
<path location="${build.proto.dir}"/>
<fileset dir="${lib.codegen}">
<include name="*/*.jar"/>
</fileset>
</classpath>
<arg line="-s pst"/>
<arg value="-d"/><arg value="@{outputdir}"/>
<arg value="-f"/><arg value="@{proto}"/>
<arg line="@{templates}"/>
</java>
</sequential>
</macrodef>
<!-- Macro which builds a collection of sources -->
<macrodef name="buildjava">
<attribute name="srcpattern" description="Pattern id describing files to build"
default="default-src-pattern"/>
<!--attribute name="srcdir" description="Source root directory"/-->
<attribute name="destdir" description="Build root directory"/>
<element name="javac-elements" description="Extra elements to pass to javac" implicit="true"/>
<sequential>
<patternset id="default-src-pattern">
<include name="**/*.java"/>
</patternset>
<javac destdir="@{destdir}" debug="true">
<exclude name="org/waveprotocol/pst/**"/>
<patternset refid="@{srcpattern}"/>
<!-- TODO(anorth): enable -Werror after fixing warnings. -->
<compilerarg value="-Werror"/>
<compilerarg value="-Xlint:all"/>
<compilerarg value="-Xlint:-serial"/>
<!-- Deprecation warnings are generated for .class files for some
compilers, e.g. org.hamcrest.Matcher -> org.hamcrest.BaseMatcher. -->
<compilerarg value="-Xlint:-deprecation"/>
<javac-elements/>
</javac>
</sequential>
</macrodef>
<!-- Macro which packages class and source files into jars -->
<macrodef name="distlib">
<attribute name="srcpattern" description="Pattern id describing files to package"/>
<attribute name="libname" description="Name prefix for the jars"/>
<sequential>
<jar destfile="${dist.dir}/@{libname}.jar" basedir="${build.src.dir}">
<patternset refid="@{srcpattern}"/>
</jar>
<jar destfile="${dist.dir}/@{libname}-src.jar" basedir="${src.dir}">
<patternset refid="@{srcpattern}"/>
<patternset>
<exclude name="**/build.xml"/>
</patternset>
</jar>
</sequential>
</macrodef>
<!-- Macro which runs unit tests with JUnit -->
<macrodef name="runtests">
<attribute name="forkmode" description="How to fork the JVM for each test/batch"/>
<attribute name="coverage" description="Whether to calculate coverage with EMMA"/>
<element name="tests" description="Fileset describing tests to run" implicit="true"/>
<sequential>
<delete dir="${test.out.dir}"/>
<mkdir dir="${test.out.dir}"/>
<!-- Add instrumentation code -->
<emma enabled="@{coverage}">
<instr instrpath="${build.src.dir}" destdir="${coverage.dir}"
metadatafile="${coverage.dir}/metadata.emma" mode="copy"/>
</emma>
<junit fork="yes" forkmode="@{forkmode}" printsummary="yes"
showoutput="no" haltonfailure="no" failureProperty="test.failed">
<jvmarg value="-Xmx512M"/>
<jvmarg value="-ea"/>
<!-- Emma arguments -->
<jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
<!-- This classpath includes src folders for the gwt.xml files -->
<classpath>
<path location="${coverage.dir}"/>
<path location="${build.proto.dir}"/>
<path location="${build.messages.dir}"/>
<path location="${build.src.dir}"/>
<path location="${build.test.dir}"/>
<path location="${src.dir}"/>
<path location="${test.dir}"/>
<path refid="libpath"/>
<path refid="test.libpath"/>
</classpath>
<!-- Set formatter so that the output is saved in xml files -->
<formatter type="xml"/>
<batchtest todir="${test.out.dir}">
<tests/>
</batchtest>
</junit>
<!-- Parses the xml files previously saved into readable HTML -->
<junitreport todir="${test.out.dir}">
<fileset dir="${test.out.dir}">
<include name="TEST*.xml"/>
</fileset>
<report format="frames" todir="${test.out.dir}"/>
</junitreport>
<!-- Generates the Emma Report -->
<emma enabled="@{coverage}">
<report sourcepath="${src.dir}" depth="method">
<fileset dir="${coverage.dir}" >
<include name="*.emma" />
</fileset>
<html outfile="${coverage.dir}/coverage.html" />
</report>
</emma>
<echo>Test results: file://${test.out.dir}/index.html</echo>
<echo>Coverage results: file://${coverage.dir}/coverage.html</echo>
<fail message="Tests failed. Check log and/or reports: ${test.out.dir}/index.html" if="test.failed"/>
</sequential>
</macrodef>
<!-- Task which compiles GXP templates -->
<taskdef name="gxpc" classname="com.google.gxp.compiler.ant.GxpcTask"
classpath="${lib.runtime}/gxp/gxp-0.2.4-beta.jar" />
</project>