-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
400 lines (390 loc) · 16.7 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
<?xml version="1.0"?>
<!-- $Id$
vim:sts=2:sw=2:
Version: $Revision$
-->
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="irrigation" default="build-all" basedir=".">
<!-- default keystore and jar signing properties, override in build.properties -->
<property name='keystore.alias' value='foraging' />
<property name='keystore.file' value='commons.jks' />
<property name='keystore.storepass' value='default_keystore_storepass' />
<property name='tsa.url' value='http://timestamp.digicert.com' />
<!-- auto-install ivy if needed -->
<property name='ivy.install.version' value='2.4.0'/>
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" />
</condition>
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<target name="download-ivy" unless="offline">
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<target name="init-ivy" depends="download-ivy">
<!-- try to load ivy here from ivy home, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
ivy is in at least one of ant's lib dir or the local lib dir. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="resolve" description="--> retrieve dependencies with ivy" depends='init-ivy'>
<!-- <ivy:retrieve pattern='${lib.dir}/[artifact]-[revision].[ext]'/> -->
<ivy:retrieve/>
</target>
<!-- Load all properties from the build.properties file,
then try to define defaults for all the properties.
The property definitions in the build.properties file
will have precedence.
-->
<property file="build.properties"/>
<!-- default compilation properties -->
<property name="src.dir" value="src/main/java"/>
<property name="build.dir" value="target/classes"/>
<!-- default web & deployment properties -->
<property name="web.dir" value="src/main/webapp"/>
<property name="server.port" value="16001"/>
<property name="codebase.url" value="http://${server.address}/${ant.project.name}"/>
<property name="client.class" value="edu.asu.commons.irrigation.client.IrrigationClient"/>
<property name="facilitator.class" value="edu.asu.commons.irrigation.facilitator.Facilitator"/>
<property name="server.class" value="edu.asu.commons.irrigation.server.IrrigationServer"/>
<property name="framework.jar" value="sesef.jar"/>
<property name="dist.dir" value="."/>
<property name="resources.dir" value="src/main/resources"/>
<property name="conf.dir" value="${resources.dir}/configuration"/>
<!-- test properties -->
<property name="test.src.dir" value="src/test/java"/>
<property name="test.build.dir" value="target/test-classes"/>
<property name="test.results.dir" value="target/surefire-reports"/>
<property name="javadoc.dir" value="docs/javadoc"/>
<property name="javadoc.private.dir" value="docs/private"/>
<property name="lib.dir" value="lib"/>
<!-- configuration properties and conditions -->
<available file="${conf.dir}/irrigation.xml" property="configuration.exists"/>
<available file="${basedir}/build.properties" property="build.properties.exists"/>
<!-- Set up the CLASSPATH, includes all jars in the lib
directory and all built files for both the main project
and the tests -->
<path id="project.classpath">
<pathelement location="."/>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="${build.dir}"/>
<pathelement location="${test.build.dir}"/>
<pathelement location="${resources.dir}"/>
</path>
<path id="runtime.classpath">
<path refid="project.classpath"/>
<pathelement location="${java.home}/lib/javaws.jar"/>
</path>
<target name="help">
<echo>
NOTE: At minimum you will need to modify the default web.dir and
server.address properties in the build.properties file before invoking deploy
or build-all.
Currently deploying to ${web.dir} with a web address of ${codebase.url}.
Experiment server will start on ${server.address}, listening on port ${server.port}.
Available targets:
compile - Compile all the source code and tests.
clean - Remove all compiled source and test classes.
docs - Create JavaDoc documentation for all source code.
test - Run all JUnit in the test source tree.
build-all - builds the client, server, and facilitator jars.
deploy - invokes build-all and then copies the client and facilitator jars to ${web.dir}
</echo>
</target>
<target name="build-all" depends="facilitator-jar, client-jar, server-jar, compile"/>
<!-- deploys the client + facilitator + sesef jarfiles to the appropriate
webapps directory. -->
<target name="deploy-to" depends="build-all, sign-jars, sign-dependencies">
<mkdir dir="${deploy.dir}"/>
<!--
copy client jar, facilitator jar, and sesef.jar to web deployment
directory
-->
<copy todir="${deploy.dir}" overwrite="true">
<fileset dir="${dist.dir}">
<include name="client.jar"/>
<include name="facilitator.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${resources.dir}/web">
<include name="index.html"/>
<include name="WEB-INF/**"/>
</fileset>
</copy>
<!-- copy images -->
<copy todir="${deploy.dir}/images" overwrite="true" failonerror="false">
<fileset dir="${resources.dir}/images"/>
</copy>
<!--
copy client and facilitator JNLP descriptor files, replacing
url/main class tokens.
-->
<copy file="${resources.dir}/web/client.jnlp" todir="${deploy.dir}" overwrite="true">
<filterset>
<filter token="CODEBASE_URL" value="${codebase.url}"/>
<filter token="MAIN_CLASS" value="${client.class}"/>
<filter token="FRAMEWORK_JAR" value="${framework.jar}"/>
</filterset>
</copy>
<copy file="${resources.dir}/web/facilitator.jnlp" todir="${deploy.dir}" overwrite="true">
<filterset>
<filter token="CODEBASE_URL" value="${codebase.url}"/>
<filter token="MAIN_CLASS" value="${facilitator.class}"/>
<filter token="FRAMEWORK_JAR" value="${framework.jar}"/>
</filterset>
</copy>
<chmod dir="${deploy.dir}" perm="664" type="file" includes="**"/>
<chmod dir="${deploy.dir}" perm="775" type="dir" includes="**"/>
</target>
<!-- fails if requisite build.properties or src/main/resources/configuration/irrigation.xml do not exist -->
<target name="check-configuration">
<fail message="Did not find any configuration files in ${conf.dir}, please copy over an appropriate set of configuration files into ${conf.dir}" unless="${configuration.exists}"/>
<fail message="Please copy build.properties.example to build.properties and edit before proceeding." unless="build.properties.exists"/>
</target>
<target name='demo-configuration' unless='${configuration.exists}'>
<copy todir="${conf.dir}">
<fileset dir="${conf.dir}/demo"/>
</copy>
</target>
<target name='demo-build-properties' unless='${build.properties.exists}'>
<copy tofile='${basedir}/build.properties' file='${basedir}/build.properties.example'/>
</target>
<target name='prepare-demo' depends='demo-configuration,demo-build-properties,compile'>
</target>
<target name="demo" depends="prepare-demo">
<antcall target='deploy'/>
<parallel>
<daemons>
<antcall target='server' />
</daemons>
<sequential>
<sleep seconds='5'/>
<antcall target='fac'/>
</sequential>
<sequential>
<sleep seconds='5'/>
<antcall target='client'/>
</sequential>
<sequential>
<sleep seconds='6'/>
<antcall target='client'/>
</sequential>
<sequential>
<sleep seconds='7'/>
<antcall target='client'/>
</sequential>
<sequential>
<sleep seconds='8'/>
<antcall target='client'/>
</sequential>
<sequential>
<sleep seconds='8'/>
<antcall target='client'/>
</sequential>
</parallel>
</target>
<target name="deploy" depends='check-configuration,configure' if='${configuration.exists}'>
<fail message="Please verify that server.address is properly set in build.properties" unless="server.address"/>
<antcall target="deploy-to">
<param name="deploy.dir" value="${web.dir}"/>
</antcall>
</target>
<target name="client-jar" depends="server-jar">
<antcall target="build-jar">
<param name="main.class" value="${client.class}"/>
<param name="jar.name" value="client.jar"/>
</antcall>
</target>
<target name="facilitator-jar" depends="client-jar">
<antcall target="build-jar">
<param name="main.class" value="${facilitator.class}"/>
<param name="jar.name" value="facilitator.jar"/>
</antcall>
</target>
<target name="server-jar" depends="compile, configure">
<antcall target="build-jar">
<param name="main.class" value="${server.class}"/>
<param name="jar.name" value="server.jar"/>
</antcall>
</target>
<target name="build-jar">
<manifestclasspath property="manifest.classpath" jarfile="${jar.name}">
<classpath refid="project.classpath"/>
</manifestclasspath>
<chmod dir="${build.dir}" perm="a+rx" type="dir" includes="**"/>
<chmod dir="${build.dir}" perm="a+r" type="file" includes="**"/>
<manifest file="manifest.mf">
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
<jar destfile="${dist.dir}/${jar.name}" manifest="manifest.mf">
<fileset dir="${build.dir}">
<include name="edu/asu/commons/**"/>
<include name="data/**"/>
<include name="conf/**"/>
<include name="images/**"/>
</fileset>
</jar>
<chmod file="${dist.dir}/${jar.name}" perm="664"/>
<!--
<signjar destDir="target/signed" alias="vcommons"
keystore="/home/alllee/.keystore"
storepass="vc.keystore.pass" />
-->
</target>
<!-- Prepare for a build by creating appropriate directories -->
<target name="prepare" depends="resolve">
<mkdir dir="${build.dir}"/>
<mkdir dir="${test.build.dir}"/>
<mkdir dir="${dist.dir}"/>
</target>
<!-- Clean up build by deleting build directories -->
<target name="purge">
<echo message="Removing ${user.home}/.ant/cache"/>
<delete dir="${user.home}/.ant/cache"/>
<delete dir="${user.home}/.m2/repository/edu/asu/commons"/>
<antcall target='clean' />
</target>
<target name='clean'>
<delete dir="${build.dir}"/>
<delete dir="${test.build.dir}"/>
<delete dir="${lib.dir}"/>
<delete file="server.jar"/>
<delete file="client.jar"/>
<delete file="facilitator.jar"/>
</target>
<!-- Compile project source files -->
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="on" optimize="off" deprecation="on" includeantruntime="true" source="1.8" target="1.8">
<compilerarg value="-Xlint:unchecked"/>
<classpath refid="project.classpath"/>
</javac>
<copy todir="${build.dir}/images" failonerror="false">
<fileset dir="${resources.dir}/images"/>
</copy>
</target>
<target name="configure">
<copy todir="${build.dir}/conf">
<fileset dir="${conf.dir}"/>
<filterset>
<filter token="SERVER_ADDRESS" value="${server.address}"/>
<filter token="PORT_NUMBER" value="${server.port}"/>
<filter token="CODEBASE_URL" value="${codebase.url}"/>
</filterset>
</copy>
</target>
<target name="profile" depends="test">
<java jar="${project.profiler}" classpathref="project.classpath" fork="true">
<arg value="${hprof.file}"/>
</java>
<!-- do something like java -jar PerfAnal.jar <hprof.txt> -->
</target>
<!-- Build project documentation -->
<target name="docs">
<javadoc sourcepath="${src.dir}" destdir="${javadoc.dir}" packagenames="*" source="1.8" classpathref="project.classpath" link="http://java.sun.com/javase/7/docs/api/ http://commons.asu.edu/src/sesef/api" overview="${src.dir}/overview.html"/>
</target>
<!-- RUN TARGETS -->
<target name="client" depends="compile">
<java classname="${client.class}" classpathref="runtime.classpath" fork="yes"/>
</target>
<target name="fac" depends="compile">
<java classname="${facilitator.class}" classpathref="runtime.classpath" fork="yes"/>
</target>
<target name="deploy-server" depends="deploy, server"/>
<target name="server" depends="compile">
<!-- make sure we update the configuration -->
<copy todir="${build.dir}/conf" overwrite="true">
<fileset dir="${conf.dir}"/>
<filterset>
<filter token="SERVER_ADDRESS" value="${server.address}"/>
<filter token="PORT_NUMBER" value="${server.port}"/>
<filter token="CODEBASE_URL" value="${codebase.url}"/>
</filterset>
</copy>
<java classname="${server.class}" classpathref="runtime.classpath" fork="yes">
<jvmarg value="-server"/>
</java>
</target>
<!-- Compile Tests -->
<target name="compile-tests" depends="compile">
<javac srcdir="${test.src.dir}" destdir="${test.build.dir}" source="1.8" target="1.8" debug="on">
<!-- <compilerarg value='-Xlint:unchecked'/> -->
<classpath refid="project.classpath"/>
</javac>
</target>
<!-- Run Tests -->
<target name="test" depends="compile-tests">
<delete dir="${test.results.dir}"/>
<mkdir dir="${test.results.dir}"/>
<junit fork="yes" haltonfailure="yes" printsummary="yes">
<classpath refid="project.classpath"/>
<batchtest todir="${test.results.dir}">
<formatter usefile="no" type="plain"/>
<formatter type="xml"/>
<fileset dir="${test.build.dir}">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</target>
<property name="savefile.converter.class" value="edu.asu.commons.irrigation.data.IrrigationSaveFileConverter"/>
<!-- default savefile directory is the raw-data directory -->
<property name="savefile.dir" value="raw-data"/>
<target name="convert" depends="compile">
<java classname="${savefile.converter.class}" classpathref="project.classpath" fork="yes">
<arg value="${savefile.dir}"/>
</java>
</target>
<!-- Run Test on GUI -->
<target name="guitest" depends="compile-tests">
<java fork="yes" classname="junit.swingui.TestRunner" taskname="JUnit" failonerror="true" dir="${basedir}">
<jvmarg value="-Djunit.test.path=${test.build.dir}"/>
<sysproperty key="basedir" value="${basedir}"/>
<classpath>
<path refid="project.classpath"/>
</classpath>
</java>
</target>
<!-- generate keystore and sign jars -->
<target name='check-keystore'>
<available file='${keystore.file}' property='keystore.present'/>
</target>
<target name='generate-keystore' depends='check-keystore' unless='keystore.present'>
<genkey alias='${keystore.alias}' verbose='true' storepass='${keystore.storepass}'
validity='365' keystore='${keystore.file}'>
<dname>
<param name='CN' value='commons.asu.edu'/>
<param name='O' value='Arizona State University'/>
<param name='OU' value='Center for Behavior, Institutions, and the Environment'/>
<param name='L' value='Tempe'/>
<param name='ST' value='Arizona'/>
<param name='C' value='US'/>
</dname>
</genkey>
</target>
<target name='sign-jars' depends='generate-keystore'>
<signjar destDir='${dist.dir}' alias='${keystore.alias}' keystore='${keystore.file}' lazy='true' storepass='${keystore.storepass}' tsaurl='${tsa.url}'>
<path>
<fileset dir='${dist.dir}' includes='*.jar' />
</path>
</signjar>
</target>
<target name='sign-dependencies'>
<signjar destDir='${lib.dir}' alias='${keystore.alias}' keystore='${keystore.file}' lazy='true' storepass='${keystore.storepass}' tsaurl='${tsa.url}'>
<path>
<fileset dir='${lib.dir}' includes='*.jar' />
</path>
</signjar>
</target>
</project>