aboutsummaryrefslogtreecommitdiffstats
path: root/docs/dist/doc/examples/build.xml
blob: 37c1dede80ecb179362c2798c3966f8a8630da83 (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
448
449
450
451
452
453
454
455
456
457
458
<!-- ========================================================================= -->
<!-- Copyright (c) 1999-2001 Xerox Corporation,                                -->
<!--               2002 Palo Alto Research Center, Incorporated (PARC).        -->
<!-- All rights reserved.                                                      -->
<!-- This program and the accompanying materials are made available            -->
<!-- under the terms of the Common Public License v1.0                         -->
<!-- which accompanies this distribution and is available at                   -->
<!-- http://www.eclipse.org/legal/cpl-v10.html                                 -->
<!--                                                                           -->
<!-- Contributors:                                                             -->
<!--     Xerox/PARC     initial implementation                                 -->
<!-- ========================================================================= -->

<project name="aspectj-examples" default="spacewar" basedir=".">

    <target name="info" >
      <echo>
  This script builds the AspectJ examples.  

  Relevant targets:
     spacewar        build and run spacewar with debugging (default)
     all             build and run each example
     {example}       build and run any {example} 
                     (use -projecthelp to list {example} names)
     tracing-bc      use AspectJ 1.1 bytecode weaving to build tracing example

  Setup:
     - Run from the doc/examples directory in your AspectJ distribution.
       The tasks in ../../lib/aspectjtools.jar are used automatically.

  Variants:
     - To avoid running (i.e., compile only), define variable "norun"
     - To define a variable, use the Ant -D option - e.g., on Windows:
  
         ant -f build.xml -DJAVA_HOME=c:\jdk1.3.1 -Dnorun=skip

      </echo>
    </target>

    <!-- ============================================================= -->
    <!-- setup and cleanup targets                                     -->
    <!-- ============================================================= -->

    <target name="clean" depends="init"
     description="clean and create classes/jar dir, .ajesym files">
      <delete quiet="on" dir="${classes.dir}"/>
      <delete quiet="on" dir="${jar.dir}"/>
      <delete quiet="on">
        <fileset dir="${example.dir}" includes="**/*.ajesym"/>
      </delete>
      <mkdir dir="${classes.dir}"/>
      <mkdir dir="${jar.dir}"/>
    </target>

    <target name="init"  depends="init.variables,init.taskdefs"/>

    <target name="init.variables" 
     description="init variables">
     
      <!-- build.compiler value to pick up our CompilerAdapter for javac -->
      <property name="ajc.adapter"
	           value="org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter"/>

      <!-- required directories - run from examples or predefine -->
      <property name="example.dir"
            location="${basedir}"/> 
      <property name="aspectj.lib.dir"
            location="${basedir}/../../lib"/> 

      <!-- required libraries - install or predefine -->
      <property name="aspectjrt.jar"
            location="${aspectj.lib.dir}/aspectjrt.jar"/> 
      <property name="aspectjtools.jar"
            location="${aspectj.lib.dir}/aspectjtools.jar"/> 
      <property name="aspectjweaver.jar"
    		location="${aspectj.lib.dir}/aspectjweaver.jar"/>

      <!-- created directories -->
      <property name="classes.dir"
            location="${example.dir}/classes"/> 
      <property name="jar.dir"
            location="${example.dir}/jars"/> 

      <!-- checking required libraries -->
      <available file="${aspectjtools.jar}"
             property="aspectjtools.jar.available"/>
      <available file="${aspectjrt.jar}"
             property="aspectjrt.jar.available"/>

      <property name="example.packages"
               value="bean, coordination, evolution, figures, figures.gui,
                      helloworld, icount, icount.lib, introduction,
                      observer, shadow, shadow.version1, shadow.version2,
                      spacewar, telecom, telecom.version1, timeserver, tjp,
                      tracing, tracing.lib tracing.version1, tracing.version2,
                      tracing.version3"/>
    </target>

    <target name="init.taskdefs" depends="init.variables, 
         aspectjtools.jar.available,
         aspectjrt.jar.available"
         unless="taskdefs.init">
      <!-- sets name of new task to iajc, old task to ajc -->
      <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
          <classpath> 
            <pathelement path="${aspectjtools.jar}"/> 
          </classpath>
      </taskdef>
	  <property name="taskdefs.init" value="true"/>
    </target>

    <!-- targets to fail unless required libraries available -->

    <target name="aspectjrt.jar.available" depends="init.variables" 
          unless="aspectjrt.jar.available" >
      <fail message="expecting aspectjrt.jar at ${aspectjrt.jar}"/>
    </target>

    <target name="aspectjtools.jar.available" depends="init.variables" 
          unless="aspectjtools.jar.available" >
      <fail message="expecting aspectjtools.jar at ${aspectjtools.jar}"/>
    </target>

    <!-- ============================================================= -->
    <!-- these targets compile and run any example                     -->
    <!-- ============================================================= -->
    <target name="Ajx" depends="init"
     description="compile {list} and run {class} of example">
       <echo message="##### Ajx list=${list} class=${class}" />
       <antcall target="clean" />
       <!-- can use ajc or iajc here -->
       <iajc destdir="${classes.dir}" argfiles="${list}" 
       		fork="true"
       		forkclasspath="${aspectjtools.jar}"
          classpath="${aspectjrt.jar}"/>

       <antcall target="Ajx-run" >
         <param name="class" value="${class}"/>
       </antcall>

    </target>

    <target name="Ajx-run" 
     description="run {class} unless {norun} is set" 
          unless="norun" >
       <echo message="##### Ajx-run list=${list} class=${class}" />
       <java classname="${class}" fork="yes">
          <classpath>
           <pathelement path="${classes.dir}"/>
           <pathelement path="${aspectjrt.jar}"/>
          </classpath>
       </java>
    </target>

    <!-- ============================================================= -->
    <!-- example targets                                               -->
    <!-- ============================================================= -->
    <target name="all" 
     description="build and run all examples"
         depends="bean,intro,intro-clone,intro-compare,intro-hash,
                  observer,spacewar,spacewar-demo,telecom,
                  telecom-timing,tracing-none,tracing-1,
                  tracing-2,tracing-3,tracing-lt,tjp"/>

    <target name="nonGui" 
     description="build and run non-GUI examples"
         depends="bean,intro,intro-clone,intro-compare,intro-hash,
                  telecom,telecom-timing,tracing-none,tracing-1,
                  tracing-2,tracing-3,tracing-lt,tjp"/>

    <target name="bean"
     description="build bean example">
      <antcall target="Ajx">
        <param name="list"    value="bean/files.lst"/>
        <param name="class"   value="bean.Demo"/>
      </antcall>
    </target>

    <target name="intro"
     description="build inter-type declaration example">
      <antcall target="Ajx">
        <param name="list"    value="introduction/files.lst"/>
        <param name="class"   value="introduction.Point"/>
      </antcall>
    </target>

    <target name="intro-clone"
     description="build inter-type declaration (clone) example">
      <antcall target="Ajx">
        <param name="list"    value="introduction/files.lst"/>
        <param name="class"   value="introduction.CloneablePoint"/>
      </antcall>
    </target>

    <target name="intro-compare"
     description="build inter-type declaration (Comparable) example">
      <antcall target="Ajx">
        <param name="list"    value="introduction/files.lst"/>
        <param name="class"   value="introduction.ComparablePoint"/>
      </antcall>
    </target>

    <target name="intro-hash"
     description="build inter-type declaration (hashcode) example">
      <antcall target="Ajx">
        <param name="list"    value="introduction/files.lst"/>
        <param name="class"   value="introduction.HashablePoint"/>
      </antcall>
    </target>

    <target name="observer"
     description="build observer example">
      <antcall target="Ajx">
        <param name="list"    value="observer/files.lst"/>
        <param name="class"   value="observer.Demo"/>
      </antcall>
    </target>

    <target name="spacewar"
     description="build spacewar debug example">
      <antcall target="Ajx">
        <param name="list"    value="spacewar/debug.lst"/>
        <param name="class"   value="spacewar.Game"/>
      </antcall>
    </target>

    <target name="spacewar-demo"
     description="build spacewar demo (no debug) example">
      <antcall target="Ajx">
        <param name="list"    value="spacewar/demo.lst"/>
        <param name="class"   value="spacewar.Game"/>
      </antcall>
    </target>

    <target name="telecom"
     description="build telecom basic example">
      <antcall target="Ajx">
        <param name="list"    value="telecom/basic.lst"/>
        <param name="class"   value="telecom.BasicSimulation"/>
      </antcall>
    </target>

    <target name="telecom-billing"
     description="build telecom billing example">
      <antcall target="Ajx">
        <param name="list"    value="telecom/billing.lst"/>
        <param name="class"   value="telecom.BillingSimulation"/>
      </antcall>
    </target>

    <target name="telecom-timing"
     description="build telecome timing example">
      <antcall target="Ajx">
        <param name="list"    value="telecom/timing.lst"/>
        <param name="class"   value="telecom.TimingSimulation"/>
      </antcall>
    </target>

    <target name="tjp"
     description="build thisJoinPoint example">
      <antcall target="Ajx">
        <param name="list"    value="tjp/files.lst"/>
        <param name="class"   value="tjp.Demo"/>
      </antcall>
    </target>

    <target name="tracing-none"
     description="build tracing (base) example">
      <antcall target="Ajx">
        <param name="list"    value="tracing/notrace.lst"/>
        <param name="class"   value="tracing.ExampleMain"/>
      </antcall>
    </target>

    <target name="tracing-1"
     description="build tracing (version 1) example">
      <antcall target="Ajx">
        <param name="list"    value="tracing/tracev1.lst"/>
        <param name="class"   value="tracing.version1.TraceMyClasses"/>
      </antcall>
    </target>

    <target name="tracing-2"
     description="build tracing (version 2) example">
      <antcall target="Ajx">
        <param name="list"    value="tracing/tracev2.lst"/>
        <param name="class"   value="tracing.version2.TraceMyClasses"/>
      </antcall>
    </target>

    <target name="tracing-3"
     description="build tracing (version 3) example">
      <antcall target="Ajx">
        <param name="list"    value="tracing/tracev3.lst"/>
        <param name="class"   value="tracing.version3.TraceMyClasses"/>
      </antcall>
    </target>

    <!-- ============================================================= -->
    <!-- do tracing example using compiler adapter -->
    <!-- ============================================================= -->
    <target name="tracing-adapter" depends="init"
     description="tracing example compiled via javac task">
       <antcall target="clean" />
       <!-- to fork, set adapter.fork=true 
            and put aspectjtools.jar on ant classpath -->
       <javac destdir="${classes.dir}" 
                 fork="${adapter.fork}">
         <src path="${example.dir}"/>
         <include name="tracing/*.java"/>
         
         <!-- compilerarg's ignored unless using our compiler adapter -->
		 <compilerarg compiler="${ajc.adapter}" 
		 	line="-verbose -Xlint -proceedOnError"/>
		 <!-- use separate values if a path might have spaces -->
		 <compilerarg compiler="${ajc.adapter}" 
		 	value="-classpath"/>
		 <compilerarg compiler="${ajc.adapter}" 
		 	value="${aspectjrt.jar}"/>
		 <compilerarg compiler="${ajc.adapter}" 
		     path="${example.dir}/tracing/version3/Trace.java"/>
		 <compilerarg compiler="${ajc.adapter}" 
		     path="${example.dir}/tracing/version3/TraceMyClasses.java"/>
       </javac>	   
    </target>

    <target name="tracing-adapter-ajc" depends="init"
     description="tracing example compiled using ajc via compiler adapter">
		<!-- aspectjtools.jar must be on system/ant classpath -->
		<antcall target="tracing-adapter">
			<param name="build.compiler" value="${ajc.adapter}"/> 
		</antcall>
	</target>
	
    <!-- ============================================================= -->
    <!-- do tracing example with 1.1 bytecode weaving (binary aspects) -->
    <!-- (and use fork/forkclasspath to avoid Eclipse 2.x bug)         -->
    <!-- ============================================================= -->
    <target name="tracing-bc" depends="init"
     description="tracing example with bytecode weaving (binary aspects)">
       <antcall target="clean" />

       <!-- build application classes -->
       <iajc outjar="${jar.dir}/tracingApp.jar"
          classpath="${aspectjrt.jar}"
          fork="true"
          forkclasspath="${aspectjtools.jar}"
            verbose="off">
         <src path="${example.dir}"/>
         <include name="tracing/*.java" />
       </iajc>

       <!-- test standalone application by running without tracing -->
       <echo message="---------- running without tracing - START"/>
       <java classname="tracing.ExampleMain">
         <classpath>
            <pathelement path="${aspectjrt.jar}"/> 
            <pathelement path="${jar.dir}/tracingApp.jar"/> 
         </classpath>
       </java>
       <echo message="---------- running without tracing - FINISH "/>

       <!-- Build a read-only tracing library -->
       <iajc outjar="${jar.dir}/tracingLib.jar"
          classpath="${aspectjrt.jar}"
          fork="true"
          forkclasspath="${aspectjtools.jar}"
            verbose="off">
         <src path="${example.dir}"/>
         <include name="tracing/version3/Trace.java" />
       </iajc>

       <!-- weave them -->
       <!-- This example uses a concrete aspect in source form, -->
       <!-- but the aspects could be written to be binary only. -->
       <iajc outjar="${jar.dir}/tracedApp.jar"
             inpath="${jar.dir}/tracingApp.jar"
         aspectpath="${jar.dir}/tracingLib.jar" 
          classpath="${aspectjrt.jar}"
          fork="true"
          forkclasspath="${aspectjtools.jar}"
            verbose="off">
         <src path="${example.dir}"/>
         <include name="tracing/version3/TraceMyClasses.java" />
       </iajc>

       <!-- run with tracing -->
       <echo message="---------- running with tracing - START"/>
       <java classname="tracing.version3.TraceMyClasses">
         <classpath>
            <pathelement path="${aspectjrt.jar}"/> 
            <pathelement path="${jar.dir}/tracingLib.jar"/> 
            <pathelement path="${jar.dir}/tracedApp.jar"/> 
         </classpath>
       </java>
       <echo message="---------- running with tracing - FINISH"/>

    </target>

    <!-- ============================================================= -->
    <!-- do tracing example with 1.2 load-time weaving                 -->
    <!-- (and use fork/forkclasspath to avoid Eclipse 2.x bug)         -->
    <!-- ============================================================= -->
    <target name="tracing-lt" depends="init"
     description="tracing example with load-time aspect weaving">
       <antcall target="clean" />

       <!-- build application classes -->
       <iajc outjar="${jar.dir}/tracingApp.jar"
          classpath="${aspectjrt.jar}"
          fork="true"
          forkclasspath="${aspectjtools.jar}"
            verbose="off">
         <src path="${example.dir}"/>
         <include name="tracing/*.java" />
       </iajc>

       <!-- Build a read-only tracing library -->
       <iajc outjar="${jar.dir}/tracingLib.jar"
          classpath="${aspectjrt.jar}:${jar.dir}/tracingApp.jar"
          fork="true"
          forkclasspath="${aspectjtools.jar}"
            verbose="off">
         <src path="${example.dir}"/>
         <include name="tracing/version2/Trace.java" />
         <include name="tracing/version2/TraceMyClasses.java" />
       </iajc>

       <!-- test standalone application by running without tracing -->
       <echo message="---------- running without tracing - START"/>
       <java classname="tracing.ExampleMain">
         <classpath>
            <pathelement path="${aspectjrt.jar}"/> 
            <pathelement path="${jar.dir}/tracingApp.jar"/> 
         </classpath>
       </java>
       <echo message="---------- running without tracing - FINISH "/>

       <!-- run application with LTW to add tracing -->
       <echo message="---------- running with tracing - START"/>
       <java classname="tracing.ExampleMain"
         fork="true">
         <classpath>
            <pathelement path="${aspectjweaver.jar}"/> 
         </classpath>
		 <jvmarg line="-showversion"/>
		 <sysproperty key="java.system.class.loader" value="org.aspectj.weaver.WeavingURLClassLoader"/>
         <sysproperty key="aj.weaving.verbose" value="True"/>
       	 <sysproperty key="org.aspectj.weaver.showWeaveInfo" value="True"/>
         <sysproperty key="aj.class.path" path="${jar.dir}/tracingLib.jar:${jar.dir}/tracingApp.jar"/>
         <sysproperty key="aj.aspect.path" path="${jar.dir}/tracingLib.jar"/>
       </java>
       <echo message="---------- running with tracing - FINISH"/>

    </target>

</project>