summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/antdefs.xml
blob: 21dd005ef81054051fec849d47e00f5b728ab2e8 (plain)
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<!--
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
-->

<!--
   This file is designed to be imported by build.xml files to provide
   definitions for a default set of build targets.  The build.xml file
   can include additional definitions to configure the behavior of these
   default targets.  The build.xml file can also define any additional
   targets that are needed by the project.

   When invoking a build.xml file that imports this file, the following
   environment variables must be set:
     TUSCANY_HOME A directory containing the Tuscany binary distribution.
     JUNIT_JAR The location of the JUnit jar file.  The JUnit version used
       for testing these build files was JUnit 4.5.

   This file defines the following targets that can be used on the
   ant command that invokes the build.xml file:
     "compile" Compiles any Java source files that don't have an up-to-date
       class file, and copies any files in or under the resource directory.
       If the build.xml file contains a <path> element with the id
       "compile-path", the contents of this path are added to the compiler's
       classpath.  Also invokes the following targets:
       . "wsdljava" (defined in the build.xml file) if there are any
           .wsdl files in or under the resource directory
       . "idljava" (defined in the build.xml file) if there are any
           .idl files in or under the resource directory
       . "test" if there are any files in or under the src/test/java
           directory
       . "package" if all previous steps completed successfully
     "test" Compiles any Java unit test files that don't have an
       up-to-date class file, copies any test resources in or under the
       src/test/resources directory, and runs the unit tests.  If the
       build.xml file contains a <path> element with the id "test-path",
       the contents of this path are used for compiling and running the
       unit tests.  In addition, the "compile-path" setting (if specified)
       is used for running unit tests.  If the build.xml file defines the
       "test-setup" property, the "testsetup" target in the build.xml
       file is invoked after copying the test resources.
     "package" Creates a jar file containing the compiled Java class
        files (excluding unit test code) and any files in or under the
        resource directory, unless the jar file is already up to date.
        If the build.xml file defines a path with id "package-path", this
        path is used for the Class-Path manifest entry.
     "run" Runs the class specified by the "run-class" property in the
        build.xml file if this property is defined.  If the build.xml file
        contains a <path> element with id "run-path", the contents of this
        path are added to the run classpath.
     "clean" Deletes all the files produced by the build.

   This file also defines the following targets for invocation by <antcall>
   from the build.xml file:
     "wsimport" Generates Java code from a WSDL file (unless the Java
       code is already up to date) by running the JDK wsimport command.
       Requires the following parameters:
       . <package> the Java package to use for generated code
       . <wsdlfile> the filename of the WSDL file
       . <javaclass> the filename of any Java class file that will be
           generated by running this target on the WSDL file
     "sdojavagen" Generates Java code from a WSDL file (unless the Java
       code is already up to date) by running the SDO XSD2JavaGenerator.
       Requires the same parameters as <wsimport>, plus the following:
       . <prefix> the prefix string for naming the generated factory
     "idlj" Generates Java code from a CORBA IDL file (unless the Java
       code is already up to date) by running the JDK idlj command.
       Requires the following parameters:
       . <idljopts> the options to be used on this idlj command invocation
       . <idlfile> the filename of the IDL file
       . <javaclass> the filename of any Java class file that will be
           generated by running this target for this IDL file

   All other targets defined by this file (with names starting with "#")
   are for internal use from within this file and are not intended to
   be used externally.
-->

<project name="antdefs">
    <property environment="env"/> 
    <fail unless="env.TUSCANY_HOME">
        Error: Please set the TUSCANY_HOME environment variable.
    </fail>
    <fail unless="env.JUNIT_JAR">
        Error: Please set the JUNIT_JAR environment variable.
    </fail>

    <!-- check whether there are any WSDL files in or under the resource directory -->
    <target name="#find-wsdlfiles">
        <fileset id="#allwsdl" dir="src/main/resources">
            <include name="**/*.wsdl"/>
        </fileset>
        <condition property="#wsdlfiles">
            <and>
                <available file="src/main/resources" type="dir"/>
                <resourcecount refid="#allwsdl" when="greater" count="0"/>
            </and>
        </condition>
    </target>

    <!-- call the wsdljava target in the build.xml file if required -->
    <target name="#call-wsdljava" depends="#find-wsdlfiles" if="#wsdlfiles">
        <antcall target="wsdljava"/>
    </target>

    <!-- check whether the WSDL-generated Java code is already up to date -->
    <target name="#wsdlcheck">
        <condition property="#wsdl-uptodate">
            <uptodate srcfile="src/main/resources/${wsdlfile}"
                      targetfile="target/classes/${javaclass}"/>
        </condition>
    </target>

    <!-- run the JDK wsimport command if required -->
    <target name="wsimport" depends="#wsdlcheck" unless="#wsdl-uptodate">
        <mkdir dir="target/jaxws-source"/>
        <exec executable="${java.home}/../bin/wsimport">
            <arg line="-keep -s ./target/jaxws-source -p ${package} 
                       -d ./target/classes src/main/resources/${wsdlfile}"/>
        </exec>
	</target>

    <!-- run the SDO XSD2JavaGenerator if required, then compile the generated Java source -->
    <target name="sdojavagen" depends="#wsdlcheck" unless="#wsdl-uptodate">
        <mkdir dir="target/sdo-source"/>
        <java classname="org.apache.tuscany.sdo.generate.XSD2JavaGenerator" fork="yes" dir=".">
            <arg value="-javaPackage"/>
            <arg value="${package}"/>
            <arg value="-prefix"/>
            <arg value="${prefix}"/>
            <arg value="-noNotification"/>
            <arg value="-noContainment"/>
            <arg value="-noUnsettable"/>
            <arg value="-targetDirectory"/>
            <arg value="target/sdo-source"/>
            <arg value="src/main/resources/${wsdlfile}"/>
            <classpath>
                <pathelement path="${env.TUSCANY_HOME}/lib/tuscany-sca-manifest.jar"/>
            </classpath>
        </java>
        <javac destdir="target/classes" debug="on" source="1.5" target="1.5">
            <src path="target/sdo-source"/>
            <classpath>
                <pathelement path="${env.TUSCANY_HOME}/lib/tuscany-sca-manifest.jar"/>
            </classpath>
        </javac>
    </target>

    <!-- check whether there are any CORBA IDL files in or under the resource directory -->
    <target name="#find-idlfiles">
        <fileset id="#allidl" dir="src/main/resources">
            <include name="**/*.idl"/>
        </fileset>
        <condition property="#idlfiles">
            <and>
                <available file="src/main/resources" type="dir"/>
                <resourcecount refid="#allidl" when="greater" count="0"/>
            </and>
        </condition>
    </target>

    <!-- call the idljava target in the build.xml file if required -->
    <target name="#call-idljava" depends="#find-idlfiles" if="#idlfiles">
        <antcall target="idljava"/>
    </target>

    <!-- check whether the IDL-generated Java code is already up to date -->
    <target name="#idlcheck">
        <condition property="#idl-uptodate">
            <uptodate srcfile="src/main/resources/${idlfile}"
                      targetfile="target/classes/${javaclass}"/>
        </condition>
    </target>

    <!-- run the JDK idlj command if required, then compile the generated Java source -->
    <target name="idlj" depends="#idlcheck" unless="#idl-uptodate">
        <mkdir dir="target/idlj-source"/>
        <exec executable="${java.home}/../bin/idlj">
            <arg value="${idljopts}"/>
            <arg value="-td"/>
            <arg value="target/idlj-source"/>
            <arg value="src/main/resources/${idlfile}"/>
        </exec>
        <javac destdir="target/classes" debug="on" source="1.5" target="1.5">
            <src path="target/idlj-source"/>
        </javac>
    </target>

    <!-- check whether there are any Java source files to compile -->
    <target name="#find-javafiles">
        <fileset id="#alljava" dir="src/main/java">
            <include name="**/*.java"/>
        </fileset>
        <condition property="#javafiles">
            <and>
                <available file="src/main/java" type="dir"/>
                <resourcecount refid="#alljava" when="greater" count="0"/>
            </and>
        </condition>
    </target>

    <!-- check whether a dependency path for the Java compiler was specified -->
    <target name="#check-compile-path">
        <condition property="#compile-path">
            <isreference refid="compile-path"/>
        </condition>
    </target>

    <!-- set classpath for Java compiler to include specified additional path -->
    <target name="#set-classpath" depends="#check-compile-path" if="#compile-path">
        <path id="#javac-classpath">
            <path refid="compile-path"/>
        </path>
    </target>

    <!-- set default classpath for Java compiler if no additional path specified -->
    <target name="#default-classpath" depends="#check-compile-path" unless="#compile-path">
        <path id="#javac-classpath"/>
    </target>

    <!-- compile the Java source files -->
    <target name="#compile-src" depends="#find-javafiles, #set-classpath, #default-classpath" if="#javafiles">
        <javac destdir="target/classes" debug="on" source="1.5" target="1.5">
            <src path="src/main/java"/>
            <classpath>
                <path refid="#javac-classpath"/>
                <pathelement path="${env.TUSCANY_HOME}/lib/tuscany-sca-manifest.jar"/>
            </classpath>
        </javac>
    </target>

    <!-- check whether there are any resources to copy -->
    <target name="#find-resources">
        <fileset id="#allresources" dir="src/main/resources"/>
        <condition property="#resources">
            <and>
                <available file="src/main/resources" type="dir"/>
                <resourcecount refid="#allresources" when="greater" count="0"/>
            </and>
        </condition>
    </target>

    <!-- copy the contents of the resource directory -->
    <target name="#copy-resources" depends="#find-resources" if="#resources">
        <copy todir="target/classes">
            <fileset dir="src/main/resources"/>
        </copy>
    </target>

    <!-- check whether there are any Java files in or under the test directory -->
    <target name="#find-testjava">
        <fileset id="#alltestjava" dir="src/test/java">
            <include name="**/*.java"/>
        </fileset>
        <condition property="#testjava">
            <and>
                <available file="src/test/java" type="dir"/>
                <resourcecount refid="#alltestjava" when="greater" count="0"/>
            </and>
        </condition>
    </target>

    <!-- call the test target if required -->
    <target name="#call-test" depends="#find-testjava" if="#testjava">
        <antcall target="test"/>
    </target>

    <!-- check whether there are any test resources to copy -->
    <target name="#find-testresources">
        <fileset id="#alltestresources" dir="src/test/resources"/>
        <condition property="#testresources">
            <and>
                <available file="src/test/resources" type="dir"/>
                <resourcecount refid="#alltestresources" when="greater" count="0"/>
            </and>
        </condition>
    </target>

    <!-- copy the test resources -->
    <target name="#copy-testresources" depends="#find-testresources" if="#testresources">
        <copy todir="target/test-classes">
            <fileset dir="src/test/resources"/>
        </copy>
    </target>

    <!-- perform additional test setup if required -->
    <target name="#test-setup" if="test-setup">
        <antcall target="testsetup"/>
    </target>

    <!-- check whether a dependency path for the unit tests was specified -->
    <target name="#check-test-path">
        <condition property="#test-path">
            <isreference refid="test-path"/>
        </condition>
    </target>

    <!-- set classpath for unit tests to include specified additional path -->
    <target name="#set-test-classpath" depends="#check-test-path" if="#test-path">
        <path id="#test-classpath">
            <path refid="test-path"/>
        </path>
    </target>

    <!-- set default classpath for unit tests if no additional path specified -->
    <target name="#default-test-classpath" depends="#check-test-path" unless="#test-path">
        <path id="#test-classpath"/>
    </target>

    <!-- run the junit task -->
    <target name="#run-junit" depends="#set-test-classpath, #default-test-classpath, #set-classpath, #default-classpath">
        <junit printsummary="no" haltonfailure="yes" dir="."
               fork="yes" forkmode="once">
            <classpath>
                <pathelement location="target/test-classes"/>
                <path refid="#test-classpath"/>
                <pathelement location="target/classes"/>
                <path refid="#javac-classpath"/>
                <pathelement location="${env.TUSCANY_HOME}/lib/tuscany-sca-manifest.jar"/>
                <pathelement location="${env.JUNIT_JAR}"/>
            </classpath>
            <formatter type="plain" usefile="false"/>
            <batchtest>
                <fileset dir="src/test/java">
                    <include name="**/*TestCase.java"/>
                </fileset>
            </batchtest>
        </junit>
    </target>

    <!-- check whether there are any files in the webapp directory -->
    <target name="#check-webapp">
        <fileset id="#webappfiles" dir="src/main/webapp"/>
        <condition property="#webapp">
            <and>
                <available file="src/main/webapp" type="dir"/>
                <resourcecount refid="#webappfiles" when="greater" count="0"/>
            </and>
        </condition>
    </target>

    <!-- build a war file if there are files in the webapp directory -->
    <target name="#package-war" depends="#check-webapp" if="#webapp">
        <fileset id="#tuscanyjars" dir="${env.TUSCANY_HOME}/modules">
            <include name="tuscany-node-api-*.jar"/>
            <include name="tuscany-node-launcher-*.jar"/>
            <include name="tuscany-sca-api-*.jar"/>
            <exclude name="tuscany-sca-api-extension-*.jar"/>
        </fileset>
        <war destfile="target/${ant.project.name}.war" webxml="src/main/webapp/WEB-INF/web.xml">
            <fileset dir="src/main/webapp"/>
            <lib refid="#tuscanyjars"/>
            <classes dir="target/classes"/>
        </war>
    </target>

    <!-- build a jar file if there are no files in the webapp directory -->
    <target name="#package-jar" depends="#check-webapp" unless="#webapp">
        <antcall target="#create-jar"/>
    </target>

    <!-- create a jar file with or without a Class-Path attribute -->
    <target name="#create-jar" depends="#create-jar-path, #create-jar-nopath"/>

    <!-- check whether a dependency path for the package target was specified -->
    <target name="#check-package-path">
        <condition property="#package-path">
            <isreference refid="package-path"/>
        </condition>
    </target>

    <!-- create a jar file with a Class-Path attribute -->
    <target name="#create-jar-path" depends="#check-package-path" if="#package-path">
        <property name="#parentdir" location=".."/>
        <pathconvert property="#package-classpath" refid="package-path" pathsep=" " dirsep="/">
            <map from="${#parentdir}" to="../.."/>
        </pathconvert>
        <jar destfile="target/${ant.project.name}.jar" basedir="target/classes">
            <manifest>
                <attribute name="Class-Path" value="${#package-classpath}"/>
            </manifest>
        </jar>
    </target>

    <!-- create a jar file without a Class-Path attribute -->
    <target name="#create-jar-nopath" depends="#check-package-path" unless="#package-path">
        <jar destfile="target/${ant.project.name}.jar" basedir="target/classes"/>
    </target>

    <!-- for external use on the ant command line -->
    <target name="compile">
        <echo message="Compiling project ${ant.project.name}"/>
        <mkdir dir="target/classes"/>
        <antcall target="#call-wsdljava"/>
        <antcall target="#call-idljava"/>
        <antcall target="#compile-src"/>
        <antcall target="#copy-resources"/>
        <antcall target="#call-test"/>
        <antcall target="package"/>
    </target>

    <!-- for external use on the ant command line -->
    <target name="test" depends="#find-testjava, #set-test-classpath, #default-test-classpath" if="#testjava">
        <echo message="Testing project ${ant.project.name}"/>
        <mkdir dir="target/test-classes"/>
        <javac destdir="target/test-classes" debug="on" source="1.5" target="1.5">
            <src path="src/test/java"/>
            <classpath>
                <pathelement location="target/classes"/>
                <path refid="#test-classpath"/>
                <pathelement location="${env.TUSCANY_HOME}/lib/tuscany-sca-manifest.jar"/>
                <pathelement location="${env.JUNIT_JAR}"/>
            </classpath>
        </javac>
        <antcall target="#copy-testresources"/>
        <antcall target="#test-setup"/>
        <antcall target="#run-junit"/>
    </target>

    <!-- for external use on the ant command line -->
    <target name="package">
        <echo message="Packaging project ${ant.project.name}"/>
        <antcall target="#package-war"/>
        <antcall target="#package-jar"/>
    </target>

    <!-- for external use on the ant command line -->
    <target name="clean">
        <echo message="Cleaning project ${ant.project.name}"/>
        <delete dir="target" includeemptydirs="true"/>
    </target>

</project>