-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.xml
401 lines (355 loc) · 13.5 KB
/
build.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<project name="Cofoja" default="dist" basedir="."
xmlns:if="ant:if"
xmlns:unless="ant:unless"
xmlns:ivy="antlib:org.apache.ivy.ant">
<!-- Configurable properties. -->
<condition property="platform.suffix" value=".${platform}" else="">
<isset property="platform" />
</condition>
<property file="local.properties" />
<property file="local${platform.suffix}.properties" if:set="platform" />
<property file="default.properties" />
<!-- Private properties. -->
<condition property="java8">
<or>
<and>
<isset property="rt.jar" />
<available ignoresystemclasses="true"
classname="java.lang.invoke.LambdaMetafactory">
<classpath location="${rt.jar}" />
</available>
</and>
<and>
<not>
<isset property="rt.jar" />
</not>
<available classname="java.lang.invoke.LambdaMetafactory" />
</and>
</or>
</condition>
<condition property="needs-tools-jar">
<matches pattern="1\.[5678].*" string="${ant.java.version}"/>
</condition>
<condition property="add-opens-tools">
<and>
<istrue value="${add-opens}" />
<not>
<isset property="needs-tools-jar" />
</not>
</and>
</condition>
<property name="lib.dir" location="lib" />
<property name="src.dir" location="src" />
<property name="test.dir" location="test" />
<property name="build.dir" location="build" />
<property name="obj.dir" location="obj${platform.suffix}" />
<property name="dist.dir" location="dist${platform.suffix}" />
<property name="manifest.path"
value="${src.dir}/META-INF/MANIFEST.MF" />
<property name="apt.class"
value="com.google.java.contract.core.apt.AnnotationProcessor" />
<property name="test.configurator.class"
value="com.google.java.contract.tests.Cofoja" />
<path id="base.class.path">
<fileset dir="${lib.dir}">
<include name="asm-*.jar" />
</fileset>
</path>
<path id="build.class.path">
<path refid="base.class.path" />
<pathelement path="${tools.jar}" />
</path>
<path id="test.class.path">
<path refid="base.class.path" />
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<path id="test1.class.path">
<path refid="test.class.path" />
<pathelement path="${obj.dir}/stage2" />
</path>
<path id="test2.class.path">
<path refid="test.class.path" />
<pathelement path="${obj.dir}/stage2" />
<pathelement path="${obj.dir}/test" />
</path>
<!-- Build macros. -->
<presetdef name="ujavac">
<javac encoding="utf-8" debug="${debug}" includeantruntime="false" fork="true">
<bootclasspath location="${rt.jar}" if:set="rt.jar" />
<compilerarg value="-J--add-opens" if:set="add-opens-tools" />
<compilerarg value="-Jjdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED"
if:set="add-opens-tools" />
<compilerarg value="-J--add-opens" if:set="add-opens-tools" />
<compilerarg value="-Jjdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
if:set="add-opens-tools" />
</javac>
</presetdef>
<macrodef name="cofojavac">
<attribute name="srcdir" />
<attribute name="destdir" />
<attribute name="debug" default="false" />
<attribute name="bootstrappath" default="" />
<attribute name="classpathid" />
<element name="contents" optional="true" implicit="true" />
<sequential>
<path id="processor.path">
<path refid="base.class.path" />
<pathelement location="@{bootstrappath}" />
</path>
<ujavac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}">
<classpath refid="@{classpathid}" />
<compilerarg value="-processorpath" unless:blank="@{bootstrappath}" />
<compilerarg value="${toString:processor.path}" unless:blank="@{bootstrappath}" />
<compilerarg value="-processor" />
<compilerarg value="${apt.class}" />
<compilerarg value="-Acom.google.java.contract.classpath=${toString:@{classpathid}}" />
<compilerarg value="-Acom.google.java.contract.sourcepath=@{srcdir}" />
<compilerarg value="-Acom.google.java.contract.classoutput=@{destdir}" />
<contents />
</ujavac>
</sequential>
</macrodef>
<macrodef name="checkjar">
<attribute name="label" />
<attribute name="property" />
<sequential>
<condition property="@{property}.notfound"
value="no such file: "
else="">
<not>
<available file="${@{property}}" />
</not>
</condition>
<echo message="@{label}${@{property}.notfound}${@{property}}" />
</sequential>
</macrodef>
<macrodef name="requirejar">
<attribute name="property" />
<sequential>
<fail message="Cannot find '${@{property}}'. Please link to the appropriate file or set the '@{property}' property to suit your environment. Consult the 'README' file for more information.">
<condition>
<not>
<equals arg1="${@{property}.notfound}" arg2="" />
</not>
</condition>
</fail>
</sequential>
</macrodef>
<macrodef name="barejar">
<attribute name="jarfile" />
<attribute name="basedir" />
<sequential>
<jar jarfile="@{jarfile}"
basedir="@{basedir}"
manifest="${manifest.path}">
<service type="javax.annotation.processing.Processor"
provider="${apt.class}" />
</jar>
</sequential>
</macrodef>
<macrodef name="fulljar">
<attribute name="jarfile" />
<attribute name="barejarfile" />
<sequential>
<jar jarfile="@{jarfile}"
manifest="${manifest.path}">
<service type="javax.annotation.processing.Processor"
provider="${apt.class}" />
<zipfileset includes="**/*.class"
src="@{barejarfile}" />
<zipfileset includes="**/*.class">
<fileset dir="${lib.dir}">
<include name="asm-*.jar" />
</fileset>
</zipfileset>
</jar>
</sequential>
</macrodef>
<macrodef name="bootstrapcomp">
<attribute name="stage" />
<attribute name="bootstrappath" />
<sequential>
<mkdir dir="${obj.dir}/tmp@{stage}" />
<mkdir dir="${obj.dir}/stage@{stage}" />
<cofojavac srcdir="${src.dir}" destdir="${obj.dir}/tmp@{stage}" debug="true"
bootstrappath="@{bootstrappath}" classpathid="build.class.path">
<compilerarg value="-Acom.google.java.contract.dump=${obj.dir}/dump@{stage}" />
</cofojavac>
<cofojab srcdir="${obj.dir}/tmp@{stage}"
destdir="${obj.dir}/stage@{stage}" />
</sequential>
</macrodef>
<!-- Dependency management. -->
<target name="resolve" description="initialize Ivy from ivy.xml">
<ivy:resolve />
</target>
<target name="fetch" depends="resolve"
description="retrieve dependencies with Ivy">
<ivy:retrieve pattern="${lib.dir}/[artifact]-[revision].[ext]"
type="jar" />
</target>
<target name="publish" depends="fetch,dist"
description="publish artifacts with Ivy">
<ivy:publish resolver="local" pubrevision="${version}"
artifactspattern="${dist.dir}/[artifact]-${version}.[ext]" />
</target>
<target name="pom" depends="resolve">
<ivy:deliver deliverpattern="${obj.dir}/ivy.xml" pubrevision="${version}" />
<ivy:makepom ivyfile="${obj.dir}/ivy.xml"
templatefile="cofoja.pom"
pomfile="${dist.dir}/cofoja-${version}.pom">
<mapping conf="*" scope="compile" />
<mapping conf="test" scope="test" />
</ivy:makepom>
</target>
<!-- Initialization. -->
<target name="configure">
<echo message="Configuration" />
<echo message="-------------" />
<sequential if:set="rt.jar">
<checkjar label="JRE RT JAR: " property="rt.jar" />
</sequential>
<sequential if:set="needs-tools-jar">
<checkjar label="JDK Tools JAR: " property="tools.jar" />
</sequential>
<sequential unless:set="needs-tools-jar">
<echo message="JDK Tools JAR: not needed" />
<echo message="Java9 --add-opens: ${add-opens}" />
</sequential>
<sequential if:set="bootstrap.jar">
<checkjar label="Bootstrap JAR: " property="bootstrap.jar" />
</sequential>
<echo message="Snapshot: ${snapshot}" />
<echo message="Debug: ${debug}" />
</target>
<target name="check-tools-jar" if="needs-tools-jar">
<requirejar property="tools.jar" />
</target>
<target name="init" depends="configure,check-tools-jar">
<tstamp />
<condition property="cofoja.version"
value="${version}-${DSTAMP}"
else="${version}">
<equals arg1="${snapshot}" arg2="true" />
</condition>
<property name="cofoja.jar"
value="${dist.dir}/cofoja+asm-${cofoja.version}.jar" />
<property name="cofoja.bare.jar"
value="${dist.dir}/cofoja-${cofoja.version}.jar" />
<property name="cofoja.contracted.jar"
value="${dist.dir}/cofoja+contracts+asm-${cofoja.version}.jar" />
<property name="cofoja.contracted.bare.jar"
value="${dist.dir}/cofoja+contracts-${cofoja.version}.jar" />
<property name="cofoja.javadoc.jar"
value="${dist.dir}/cofoja-${cofoja.version}-javadoc.jar" />
<property name="cofoja.sources.jar"
value="${dist.dir}/cofoja-${cofoja.version}-sources.jar" />
<mkdir dir="${obj.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Simple build. -->
<target name="build" depends="init"
description="build class files">
<mkdir dir="${obj.dir}/bare" />
<ujavac srcdir="${src.dir}" destdir="${obj.dir}/bare">
<classpath refid="build.class.path" />
</ujavac>
</target>
<target name="nobootstrap" depends="build"
description="build JAR files without self-contracts">
<barejar jarfile="${cofoja.bare.jar}" basedir="${obj.dir}/bare" />
<fulljar jarfile="${cofoja.jar}" barejarfile="${cofoja.bare.jar}" />
<property name="bootstrap.jar" value="${cofoja.bare.jar}" />
</target>
<!-- Bootstrap. -->
<target name="antinit" depends="init,nobootstrap">
<mkdir dir="${obj.dir}/build" />
<ujavac srcdir="${build.dir}" destdir="${obj.dir}/build">
<classpath>
<path refid="base.class.path" />
<pathelement path="${java.class.path}" />
<pathelement location="${bootstrap.jar}" />
</classpath>
</ujavac>
<taskdef name="cofojab" classname="PreAgentAntTask">
<classpath>
<path refid="base.class.path" />
<pathelement location="${obj.dir}/build" />
<pathelement location="${bootstrap.jar}" />
</classpath>
</taskdef>
</target>
<target name="stage0" depends="antinit">
<bootstrapcomp stage="0" bootstrappath="${bootstrap.jar}" />
</target>
<target name="stage1" depends="stage0">
<bootstrapcomp stage="1" bootstrappath="${obj.dir}/stage0" />
</target>
<target name="stage2" depends="stage1">
<bootstrapcomp stage="2" bootstrappath="${obj.dir}/stage1" />
</target>
<target name="fullbootstrap" depends="stage2">
<barejar jarfile="${cofoja.contracted.bare.jar}"
basedir="${obj.dir}/stage2" />
<fulljar jarfile="${cofoja.contracted.jar}"
barejarfile="${cofoja.contracted.bare.jar}" />
</target>
<target name="dist" depends="fullbootstrap"
description="build JAR files for distribution">
<javadoc sourcepath="${src.dir}" destdir="${obj.dir}/javadoc">
<classpath refid="build.class.path" />
<arg value="-Xdoclint:all,-missing" if:set="java8" />
</javadoc>
<jar jarfile="${cofoja.javadoc.jar}">
<fileset dir="${obj.dir}/javadoc" />
</jar>
<jar jarfile="${cofoja.sources.jar}">
<fileset dir="${src.dir}" />
</jar>
</target>
<!-- Tests. -->
<target name="buildtest1" depends="stage2">
<mkdir dir="${obj.dir}/test" />
<cofojavac srcdir="${test.dir}" destdir="${obj.dir}/test"
classpathid="test1.class.path">
<include name="**/SeparateGenericSuperclass.java" />
<include name="**/SeparateInterface.java" />
</cofojavac>
</target>
<target name="buildtest2" depends="buildtest1,stage2">
<cofojavac srcdir="${test.dir}" destdir="${obj.dir}/test"
classpathid="test2.class.path">
<compilerarg value="-Acom.google.java.contract.dump=${obj.dir}/test/dump" />
<exclude name="**/SeparateGenericSuperclass.java" />
<exclude name="**/SeparateInterface.java" />
<exclude name="**/Java8*.java" unless:set="java8" />
</cofojavac>
</target>
<target name="test" depends="buildtest2,dist"
description="run tests">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="test.class.path" />
<pathelement path="${obj.dir}/stage2" />
<pathelement location="${obj.dir}/test" />
</classpath>
<jvmarg value="-javaagent:${cofoja.contracted.bare.jar}" />
<jvmarg value="-Dcom.google.java.contract.configurator=${test.configurator.class}" />
<formatter type="plain" />
<batchtest fork="yes" todir="${obj.dir}/test">
<fileset dir="${obj.dir}/test">
<include name="**/*Test.class" />
<exclude name="**/Java8*.class" unless:set="java8" />
</fileset>
</batchtest>
</junit>
</target>
<!-- Book-keeping. -->
<target name="clean"
description="remove generated files">
<delete dir="${obj.dir}" />
<delete dir="${dist.dir}" />
</target>
</project>