-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.xml
403 lines (349 loc) · 16.3 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
402
403
<!--
/*
* Copyright 2007 the original author or authors.
*
* 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.
*/
-->
<!--
Ant build file for the Grails Serchable Plugin
The default target (all) does a complete clean build and test.
This should be run before making a release with "grails release-plugin"
-->
<project name="searchable" default="all">
<property environment="ENV" />
<!-- Load properties according to platform and build profile -->
<condition property="os.family" value="windows">
<os family="windows"/>
</condition>
<condition property="os.family" value="mac">
<os family="mac"/>
</condition>
<condition property="os.family" value="unix">
<os family="unix"/>
</condition>
<property file="${os.family}.properties"/>
<property file="${build.profile}.properties"/>
<property file="project.properties" />
<property file="application.properties" />
<!-- Locate Java and set version -->
<property name="target.vm" value="1.5" />
<condition property="using.java.home" value="${java15.home}">
<equals arg1="${target.vm}" arg2="1.5" />
</condition>
<property name="using.java.home" value="${java14.home}" />
<condition property="target.vm.14" value="true">
<equals arg1="${target.vm}" arg2="1.4" />
</condition>
<!-- Locate grails and set executables -->
<property name="grails.home" value="${ENV.GRAILS_HOME}" />
<condition property="grails" value="grails.bat">
<os family="windows"/>
</condition>
<property name="grails" value="grails" />
<condition property="grails-debug" value="grails-debug.bat">
<os family="windows"/>
</condition>
<property name="grails-debug" value="grails-debug" />
<property file="${grails.home}/build.properties" />
<propertyfile file="application.properties">
<entry key="app.grails.version" value="${grails.version}"/>
<entry key="plugins.hibernate" value="${grails.version}"/>
</propertyfile>
<property name="grails.work.dir" value="${ENV.HOME}/.grails/${grails.version}"/> <!-- standard location, may be overriden by -D or previous property files -->
<echo>Building with:
Java ${target.vm} (${using.java.home})
Grails: ${grails.version} (${grails.home})
</echo>
<!-- Set java executable -->
<condition property="java.cmd" value="java.exe">
<os family="windows"/>
</condition>
<property name="java.cmd" value="java" />
<!-- Classpaths -->
<path id="groovy.classpath">
<fileset dir="${grails.home}/lib">
<include name="groovy-all-*.jar" />
<include name="commons-cli-*.jar" />
<include name="junit*.jar" />
<include name="ant*.jar" />
</fileset>
</path>
<path id="classpath">
<fileset dir="lib" includes="*.jar" />
<fileset dir="${grails.home}/lib" includes="*.jar">
<exclude name="ant.jar" />
<exclude name="ant-*.jar" />
</fileset>
<fileset dir="${grails.home}/dist" includes="*.jar" />
<path location="${classes}" />
</path>
<path id="test.classpath">
<pathelement location="${classes.instrumented}"/>
<path refid="classpath" />
<pathelement location="${test.groovy.src}"/>
<pathelement location="${func.test.groovy.src}"/>
<pathelement location="${test.classes}"/>
<fileset dir="${lib.test}" includes="*.jar"/>
<path refid="cobertura.classpath" />
</path>
<!--
<path id="junit.classpath">
<path refid="classpath" />
<pathelement location="${grails.home}/lib/ant-junit.jar" />
<fileset dir="${grails.home}/lib" includes="junit*.jar" />
</path>
-->
<path id="cobertura.classpath">
<fileset dir="${lib.build}/cobertura-1.9" includes="*.jar"/>
</path>
<path id="findbugs.classpath">
<fileset dir="${findbugs.home}/lib" includes="*.jar"/>
</path>
<!-- Taskdefs -->
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="classpath" />
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="classpath" />
<!-- <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" classpathref="junit.classpath" /> -->
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="findbugs.classpath"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${lib.build}/ant-contrib/lib" includes="*.jar"/>
</classpath>
</taskdef>
<!-- Targets -->
<target name="all" depends="clean, compile, test, findbugs-report, package, integration-test" description="Clean, build, test, package"/>
<target name="clean" description="Cleanup after a previous build">
<delete dir="${target}" />
</target>
<target name="compile" description="Compile production (not test) source code">
<mkdir dir="${classes}" />
<javac srcdir="${java.src}" destdir="${classes}" source="${target.vm}" target="${target.vm}" debug="true" classpathref="classpath" />
<groovyc srcdir="${groovy.src}" destdir="${classes}" classpathref="classpath" />
</target>
<target name="instrument" if="with.code.coverage">
<cobertura-instrument todir="${classes.instrumented}">
<classpath refid="test.classpath"/>
<fileset dir="${classes}">
<include name="**/*.class"/>
</fileset>
</cobertura-instrument>
</target>
<macrodef name="compile-tests">
<attribute name="src"/>
<sequential>
<mkdir dir="${test.classes}" />
<javac srcdir="${test.java.src}" destdir="${test.classes}" source="${target.vm}" target="${target.vm}" debug="true" classpathref="classpath" />
<groovyc srcdir="@{src}" destdir="${test.classes}" classpathref="test.classpath" />
<!-- provide some dummy config files to silence irrelevant log output -->
<copy todir="${test.classes}" overwrite="true">
<fileset dir="${test.resources}" />
</copy>
</sequential>
</macrodef>
<macrodef name="run-groovy-tests">
<attribute name="using-java-home"/>
<attribute name="groovy-test-dir"/>
<attribute name="test-name"/>
<sequential>
<mkdir dir="${test.reports}" />
<junit fork="yes" forkmode="once" jvm="@{using-java-home}/bin/${java.cmd}" showoutput="true" failureproperty="tests.failed" printsummary="yes">
<formatter type="brief"/>
<formatter type="xml"/>
<classpath refid="test.classpath" />
<jvmarg value="-XX:MaxPermSize=512m" />
<jvmarg value="-Xmx1024m" />
<jvmarg value="-server" />
<jvmarg value="-Dgroovy.test.dir=@{groovy-test-dir}" />
<jvmarg value="-Dgroovy.test.pattern=**/*Tests.groovy" />
<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${java.debug.port}" />
<test name="groovy.util.AllTestSuite" todir="${test.reports}" outfile="TEST-@{test-name}"/>
</junit>
<if>
<isset property="tests.failed"/>
<then>
<loadfile srcfile="${test.reports}/TEST-@{test-name}.txt" failonerror="yes" property="test.output" />
<fail if="tests.failed">
Tests failed
${test.output}
</fail>
</then>
</if>
</sequential>
</macrodef>
<target name="unit-test" depends="compile" description="Run all unit tests">
<compile-tests src="${test.groovy.src}"/>
<!--<groovyc srcdir="${test.groovy.src}" destdir="${test.classes}" classpathref="test.classpath" />-->
<run-groovy-tests using-java-home="${using.java.home}" groovy-test-dir="${test.groovy.src}" test-name="all-units"/>
</target>
<target name="functional-test" depends="compile" description="Run all functional tests">
<compile-tests src="${func.test.groovy.src}"/>
<!--<groovyc srcdir="${func,test.groovy.src}" destdir="${test.classes}" classpathref="test.classpath" />-->
<run-groovy-tests using-java-home="${using.java.home}" groovy-test-dir="${func.test.groovy.src}" test-name="all-functional"/>
</target>
<target name="test" depends="compile, instrument, unit-test, functional-test, coverage-report" description="Run all unit and functional tests"/>
<target name="single-test" depends="compile" description="Run a single test - requires a '-Dtest=path/to/test/file' argument">
<compile-tests src="${test.groovy.src}"/>
<java classname="groovy.ui.GroovyMain" fork="true" classpathref="test.classpath" failonerror="true">
<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"/>
<arg value="${test}" />
</java>
</target>
<target name="coverage-report" if="with.code.coverage">
<cobertura-report destdir="${coverage.reports}" format="xml">
<fileset dir="${java.src}" includes="**/*.java"/>
<fileset dir="${groovy.src}" includes="**/*.groovy"/>
</cobertura-report>
</target>
<target name="findbugs-report" depends="compile" if="with.findbugs">
<mkdir dir="${findbugs.reports}"/>
<findbugs home="${findbugs.home}"
output="xml"
outputFile="${findbugs.reports}/findbugs.xml"
jvmargs="-Xmx512m">
<auxClasspath refid="classpath" />
<sourcePath path="${java.src}" />
<class location="${classes}" />
</findbugs>
</target>
<macrodef name="grails">
<attribute name="using-java-home"/>
<attribute name="dir" default="${basedir}"/>
<attribute name="arg1"/>
<attribute name="arg2" default=""/>
<attribute name="arg3" default=""/>
<sequential>
<available file="@{using-java-home}" property="using.java.home.available"/>
<fail unless="using.java.home.available">
Not a valid JAVA_HOME: @{using-java-home}
</fail>
<echo>*** Running ${grails} @{arg1} @{arg2} @{arg3} ***</echo>
<!--<echo>*** Running ${grails} -Dgrails.work.dir=${grails.work.dir} @{arg1} @{arg2} @{arg3} ***</echo>-->
<property name="path" value="${grails.home}/bin${path.separator}@{using-java-home}/bin${path.separator}${ENV.PATH}" />
<exec executable="${grails.home}/bin/${grails}" dir="@{dir}" failonerror="yes">
<env key="GRAILS_HOME" value="${grails.home}" />
<env key="JAVA_HOME" value="@{using-java-home}" />
<env key="PATH" value="${path}" />
<!--<arg value="-Dgrails.work.dir=${grails.work.dir}"/>-->
<arg value="@{arg1}"/>
<arg value="@{arg2}"/>
<arg value="@{arg3}"/>
<arg value="--non-interactive"/>
</exec>
</sequential>
</macrodef>
<macrodef name="run-integration-test">
<attribute name="app.name" />
<attribute name="app.dir"/>
<attribute name="app.tests" />
<attribute name="using.java.home" />
<sequential>
<!-- grep the version from the plugin file itself, in case not already defined -->
<groovy>
def pluginFile = new File(project.getProperty("basedir"), "SearchableGrailsPlugin.groovy")
def pattern = ~/^\s*def version = "(.+)"\s*$/
def version
pluginFile.eachLine { line ->
def matcher = pattern.matcher(line)
if (matcher.matches()) {
version = matcher.group(1)
}
}
if (version) project.setProperty("version", version)
</groovy>
<fail unless="version">
Missing version property!
</fail>
<property name="plugin.dist" value="${basedir}/grails-${app.name}-${version}.zip" />
<property name="app.source" value="${basedir}/integration-test/grails-apps" />
<available file="${plugin.dist}" property="plugin.dist.available" />
<fail unless="plugin.dist.available">
No such file: ${plugin.dist}
</fail>
<echo>
========================================================
Running integration test for @{app.name}
dir: @{app.dir}
Java: @{using.java.home}
========================================================
</echo>
<!-- clean previous -->
<delete dir="@{app.dir}"/>
<mkdir dir="@{app.dir}"/>
<!-- create vanilla app -->
<delete dir="${user.home}/.grails/${grails.version}/projects/@{app.name}"/>
<grails dir="${tmpdir}" arg1="create-app" arg2="@{app.name}" using-java-home="@{using.java.home}"/>
<!--
delete any previous compilation output in grails' cache
this is avoids class version problems when switching between Java 1.5 and 1.4
the app.grails.version version comes from the generated app's application.properties file
-->
<property file="@{app.dir}/application.properties" />
<delete dir="${user.home}/.grails/${app.grails.version}/scriptCache"/>
<delete dir="${user.home}/.grails/${app.grails.version}/projects/@{app.name}"/>
<!--Copy app files-->
<copy todir="@{app.dir}" overwrite="true">
<fileset dir="${app.source}/@{app.name}"/>
</copy>
<copy todir="@{app.dir}" overwrite="true">
<fileset dir="${app.source}/@{app.tests}"/>
</copy>
<!--Install Searchable Plugin -->
<grails dir="@{app.dir}" arg1="install-plugin" arg2="${plugin.dist}" using-java-home="@{using.java.home}"/>
<!-- Clean -->
<!--<grails dir="@{app.dir}" arg1="clean" using.java.home="@{using.java.home}"/>-->
<!-- Test app -->
<grails dir="@{app.dir}" arg1="test-app" using-java-home="@{using.java.home}"/>
<if>
<not>
<istrue value="${skip.webtest}"/>
</not>
<then>
<!-- Install web test plugin -->
<condition property="webtest.version" value="0.4">
<equals arg1="${target.vm}" arg2="1.4" />
</condition>
<property name="webtest.version" value=""/>
<grails dir="@{app.dir}" arg1="install-plugin" arg2="webtest" arg3="${webtest.version}" using-java-home="@{using.java.home}"/>
<!-- Web test -->
<condition property="webtest.result.file" value="WebTestResults.xml">
<equals arg1="${webtest.version}" arg2="0.4"/>
</condition>
<property name="webtest.result.file" value="WebTestOverview.xml" /> <!-- 0.5.1 -->
<replace file="@{app.dir}/webtest/conf/webtest.properties" token="webtest_port = 8080" value="webtest_port=${grails.server.port}" />
<replace file="@{app.dir}/webtest/conf/webtest.properties" token="webtest_resultfile = WebTestResults.xml" value="webtest_resultfile = ${webtest.result.file}" />
<grails dir="@{app.dir}" arg1="run-webtest" using-java-home="@{using.java.home}"/>
</then>
</if>
</sequential>
</macrodef>
<target name="integration-test" depends="package,simple-groovy-integration-test,compass-mapping-xml-groovy-integration-test,compass-annotated-groovy-integration-test" description="Runs the integration tests" />
<target name="before-integration-test">
<property name="tmpdir" value="${basedir}/../tmp"/>
<delete dir="${tmpdir}"/>
<mkdir dir="${tmpdir}"/>
</target>
<target name="simple-groovy-integration-test" depends="before-integration-test">
<run-integration-test using.java.home="${using.java.home}" app.name="simple-groovy" app.tests="artist-and-album-tests" app.dir="${tmpdir}/simple-groovy"/>
</target>
<target name="compass-mapping-xml-groovy-integration-test" depends="before-integration-test">
<run-integration-test using.java.home="${using.java.home}" app.name="compass-mapping-xml-groovy" app.tests="artist-and-album-tests" app.dir="${tmpdir}/compass-mapping-xml-groovy"/>
</target>
<target name="compass-annotated-groovy-integration-test" depends="before-integration-test" unless="target.vm.14">
<run-integration-test using.java.home="${using.java.home}" app.name="compass-annotated-groovy" app.tests="artist-and-album-tests" app.dir="${tmpdir}/compass-annotated-groovy"/>
</target>
<target name="package" unless="nopackage" description="Package the plugin - same as 'grails package-plugin'">
<grails arg1="clean" using-java-home="${using.java.home}" />
<grails arg1="package-plugin" using-java-home="${using.java.home}" />
</target>
</project>