-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-macros.xml
173 lines (160 loc) · 6.92 KB
/
build-macros.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!--
* Copyright (C) 2010 Google Inc.
*
* 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: [email protected] (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>