You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.xml 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <!-- ========================================================================= -->
  2. <!-- Copyright (c) 1999-2001 Xerox Corporation, -->
  3. <!-- 2002 Palo Alto Research Center, Incorporated (PARC). -->
  4. <!-- All rights reserved. -->
  5. <!-- This program and the accompanying materials are made available -->
  6. <!-- under the terms of the Eclipse Public License v 2.0 -->
  7. <!-- which accompanies this distribution and is available at -->
  8. <!-- https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt -->
  9. <!-- -->
  10. <!-- Contributors: -->
  11. <!-- Xerox/PARC initial implementation -->
  12. <!-- ========================================================================= -->
  13. <project name="aspectj-examples" default="spacewar" basedir=".">
  14. <target name="info" >
  15. <echo>
  16. This script builds the AspectJ examples.
  17. Relevant targets:
  18. spacewar build and run spacewar with debugging (default)
  19. all build and run each example
  20. {example} build and run any {example}
  21. (use -projecthelp to list {example} names)
  22. tracing-bc use AspectJ 1.1 bytecode weaving to build tracing example
  23. Setup:
  24. - Run from the doc/examples directory in your AspectJ distribution.
  25. The tasks in ../../lib/aspectjtools.jar are used automatically.
  26. Variants:
  27. - To avoid running (i.e., compile only), define variable "norun"
  28. - To define a variable, use the Ant -D option - e.g., on Windows:
  29. ant -f build.xml -DJAVA_HOME=c:\jdk1.3.1 -Dnorun=skip
  30. </echo>
  31. </target>
  32. <!-- ============================================================= -->
  33. <!-- setup and cleanup targets -->
  34. <!-- ============================================================= -->
  35. <target name="clean" depends="init"
  36. description="clean and create classes/jar dir, .ajesym files">
  37. <delete quiet="on" dir="${classes.dir}"/>
  38. <delete quiet="on" dir="${jar.dir}"/>
  39. <delete quiet="on">
  40. <fileset dir="${example.dir}" includes="**/*.ajesym"/>
  41. </delete>
  42. <mkdir dir="${classes.dir}"/>
  43. <mkdir dir="${jar.dir}"/>
  44. </target>
  45. <target name="init" depends="init.variables,init.taskdefs"/>
  46. <target name="init.variables"
  47. description="init variables">
  48. <!-- build.compiler value to pick up our CompilerAdapter for javac -->
  49. <property name="ajc.adapter"
  50. value="org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter"/>
  51. <!-- required directories - run from examples or predefine -->
  52. <property name="example.dir"
  53. location="${basedir}"/>
  54. <property name="aspectj.lib.dir"
  55. location="${basedir}/../../lib"/>
  56. <!-- required libraries - install or predefine -->
  57. <property name="aspectjrt.jar"
  58. location="${aspectj.lib.dir}/aspectjrt.jar"/>
  59. <property name="aspectjtools.jar"
  60. location="${aspectj.lib.dir}/aspectjtools.jar"/>
  61. <property name="aspectjweaver.jar"
  62. location="${aspectj.lib.dir}/aspectjweaver.jar"/>
  63. <!-- created directories -->
  64. <property name="classes.dir"
  65. location="${example.dir}/classes"/>
  66. <property name="jar.dir"
  67. location="${example.dir}/jars"/>
  68. <!-- checking required libraries -->
  69. <available file="${aspectjtools.jar}"
  70. property="aspectjtools.jar.available"/>
  71. <available file="${aspectjrt.jar}"
  72. property="aspectjrt.jar.available"/>
  73. <property name="example.packages"
  74. value="bean, coordination, evolution, figures, figures.gui,
  75. helloworld, icount, icount.lib, introduction,
  76. observer, shadow, shadow.version1, shadow.version2,
  77. spacewar, telecom, telecom.version1, timeserver, tjp,
  78. tracing, tracing.lib tracing.version1, tracing.version2,
  79. tracing.version3"/>
  80. </target>
  81. <target name="init.taskdefs" depends="init.variables,
  82. aspectjtools.jar.available,
  83. aspectjrt.jar.available"
  84. unless="taskdefs.init">
  85. <!-- sets name of new task to iajc, old task to ajc -->
  86. <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
  87. <classpath>
  88. <pathelement path="${aspectjtools.jar}"/>
  89. </classpath>
  90. </taskdef>
  91. <property name="taskdefs.init" value="true"/>
  92. </target>
  93. <!-- targets to fail unless required libraries available -->
  94. <target name="aspectjrt.jar.available" depends="init.variables"
  95. unless="aspectjrt.jar.available" >
  96. <fail message="expecting aspectjrt.jar at ${aspectjrt.jar}"/>
  97. </target>
  98. <target name="aspectjtools.jar.available" depends="init.variables"
  99. unless="aspectjtools.jar.available" >
  100. <fail message="expecting aspectjtools.jar at ${aspectjtools.jar}"/>
  101. </target>
  102. <!-- ============================================================= -->
  103. <!-- these targets compile and run any example -->
  104. <!-- ============================================================= -->
  105. <target name="Ajx" depends="init"
  106. description="compile {list} and run {class} of example">
  107. <echo message="##### Ajx list=${list} class=${class}" />
  108. <antcall target="clean" />
  109. <!-- can use ajc or iajc here -->
  110. <iajc destdir="${classes.dir}" argfiles="${list}"
  111. fork="true"
  112. forkclasspath="${aspectjtools.jar}"
  113. classpath="${aspectjrt.jar}"/>
  114. <antcall target="Ajx-run" >
  115. <param name="class" value="${class}"/>
  116. </antcall>
  117. </target>
  118. <target name="Ajx-run"
  119. description="run {class} unless {norun} is set"
  120. unless="norun" >
  121. <echo message="##### Ajx-run list=${list} class=${class}" />
  122. <java classname="${class}" fork="yes">
  123. <classpath>
  124. <pathelement path="${classes.dir}"/>
  125. <pathelement path="${aspectjrt.jar}"/>
  126. </classpath>
  127. </java>
  128. </target>
  129. <!-- ============================================================= -->
  130. <!-- example targets -->
  131. <!-- ============================================================= -->
  132. <target name="all"
  133. description="build and run all examples"
  134. depends="bean,intro,intro-clone,intro-compare,intro-hash,
  135. observer,spacewar,spacewar-demo,telecom,
  136. telecom-timing,tracing-none,tracing-1,
  137. tracing-2,tracing-3,tracing-lt,tjp"/>
  138. <target name="nonGui"
  139. description="build and run non-GUI examples"
  140. depends="bean,intro,intro-clone,intro-compare,intro-hash,
  141. telecom,telecom-timing,tracing-none,tracing-1,
  142. tracing-2,tracing-3,tracing-lt,tjp"/>
  143. <target name="bean"
  144. description="build bean example">
  145. <antcall target="Ajx">
  146. <param name="list" value="bean/files.lst"/>
  147. <param name="class" value="bean.Demo"/>
  148. </antcall>
  149. </target>
  150. <target name="intro"
  151. description="build inter-type declaration example">
  152. <antcall target="Ajx">
  153. <param name="list" value="introduction/files.lst"/>
  154. <param name="class" value="introduction.Point"/>
  155. </antcall>
  156. </target>
  157. <target name="intro-clone"
  158. description="build inter-type declaration (clone) example">
  159. <antcall target="Ajx">
  160. <param name="list" value="introduction/files.lst"/>
  161. <param name="class" value="introduction.CloneablePoint"/>
  162. </antcall>
  163. </target>
  164. <target name="intro-compare"
  165. description="build inter-type declaration (Comparable) example">
  166. <antcall target="Ajx">
  167. <param name="list" value="introduction/files.lst"/>
  168. <param name="class" value="introduction.ComparablePoint"/>
  169. </antcall>
  170. </target>
  171. <target name="intro-hash"
  172. description="build inter-type declaration (hashcode) example">
  173. <antcall target="Ajx">
  174. <param name="list" value="introduction/files.lst"/>
  175. <param name="class" value="introduction.HashablePoint"/>
  176. </antcall>
  177. </target>
  178. <target name="observer"
  179. description="build observer example">
  180. <antcall target="Ajx">
  181. <param name="list" value="observer/files.lst"/>
  182. <param name="class" value="observer.Demo"/>
  183. </antcall>
  184. </target>
  185. <target name="spacewar"
  186. description="build spacewar debug example">
  187. <antcall target="Ajx">
  188. <param name="list" value="spacewar/debug.lst"/>
  189. <param name="class" value="spacewar.Game"/>
  190. </antcall>
  191. </target>
  192. <target name="spacewar-demo"
  193. description="build spacewar demo (no debug) example">
  194. <antcall target="Ajx">
  195. <param name="list" value="spacewar/demo.lst"/>
  196. <param name="class" value="spacewar.Game"/>
  197. </antcall>
  198. </target>
  199. <target name="telecom"
  200. description="build telecom basic example">
  201. <antcall target="Ajx">
  202. <param name="list" value="telecom/basic.lst"/>
  203. <param name="class" value="telecom.BasicSimulation"/>
  204. </antcall>
  205. </target>
  206. <target name="telecom-billing"
  207. description="build telecom billing example">
  208. <antcall target="Ajx">
  209. <param name="list" value="telecom/billing.lst"/>
  210. <param name="class" value="telecom.BillingSimulation"/>
  211. </antcall>
  212. </target>
  213. <target name="telecom-timing"
  214. description="build telecome timing example">
  215. <antcall target="Ajx">
  216. <param name="list" value="telecom/timing.lst"/>
  217. <param name="class" value="telecom.TimingSimulation"/>
  218. </antcall>
  219. </target>
  220. <target name="tjp"
  221. description="build thisJoinPoint example">
  222. <antcall target="Ajx">
  223. <param name="list" value="tjp/files.lst"/>
  224. <param name="class" value="tjp.Demo"/>
  225. </antcall>
  226. </target>
  227. <target name="tracing-none"
  228. description="build tracing (base) example">
  229. <antcall target="Ajx">
  230. <param name="list" value="tracing/notrace.lst"/>
  231. <param name="class" value="tracing.ExampleMain"/>
  232. </antcall>
  233. </target>
  234. <target name="tracing-1"
  235. description="build tracing (version 1) example">
  236. <antcall target="Ajx">
  237. <param name="list" value="tracing/tracev1.lst"/>
  238. <param name="class" value="tracing.version1.TraceMyClasses"/>
  239. </antcall>
  240. </target>
  241. <target name="tracing-2"
  242. description="build tracing (version 2) example">
  243. <antcall target="Ajx">
  244. <param name="list" value="tracing/tracev2.lst"/>
  245. <param name="class" value="tracing.version2.TraceMyClasses"/>
  246. </antcall>
  247. </target>
  248. <target name="tracing-3"
  249. description="build tracing (version 3) example">
  250. <antcall target="Ajx">
  251. <param name="list" value="tracing/tracev3.lst"/>
  252. <param name="class" value="tracing.version3.TraceMyClasses"/>
  253. </antcall>
  254. </target>
  255. <!-- ============================================================= -->
  256. <!-- do tracing example using compiler adapter -->
  257. <!-- ============================================================= -->
  258. <target name="tracing-adapter" depends="init"
  259. description="tracing example compiled via javac task">
  260. <antcall target="clean" />
  261. <!-- to fork, set adapter.fork=true
  262. and put aspectjtools.jar on ant classpath -->
  263. <javac destdir="${classes.dir}"
  264. fork="${adapter.fork}">
  265. <src path="${example.dir}"/>
  266. <include name="tracing/*.java"/>
  267. <!-- compilerarg's ignored unless using our compiler adapter -->
  268. <compilerarg compiler="${ajc.adapter}"
  269. line="-verbose -Xlint -proceedOnError"/>
  270. <!-- use separate values if a path might have spaces -->
  271. <compilerarg compiler="${ajc.adapter}"
  272. value="-classpath"/>
  273. <compilerarg compiler="${ajc.adapter}"
  274. value="${aspectjrt.jar}"/>
  275. <compilerarg compiler="${ajc.adapter}"
  276. path="${example.dir}/tracing/version3/Trace.java"/>
  277. <compilerarg compiler="${ajc.adapter}"
  278. path="${example.dir}/tracing/version3/TraceMyClasses.java"/>
  279. </javac>
  280. </target>
  281. <target name="tracing-adapter-ajc" depends="init"
  282. description="tracing example compiled using ajc via compiler adapter">
  283. <!-- aspectjtools.jar must be on system/ant classpath -->
  284. <antcall target="tracing-adapter">
  285. <param name="build.compiler" value="${ajc.adapter}"/>
  286. </antcall>
  287. </target>
  288. <!-- ============================================================= -->
  289. <!-- do tracing example with 1.1 bytecode weaving (binary aspects) -->
  290. <!-- (and use fork/forkclasspath to avoid Eclipse 2.x bug) -->
  291. <!-- ============================================================= -->
  292. <target name="tracing-bc" depends="init"
  293. description="tracing example with bytecode weaving (binary aspects)">
  294. <antcall target="clean" />
  295. <!-- build application classes -->
  296. <iajc outjar="${jar.dir}/tracingApp.jar"
  297. classpath="${aspectjrt.jar}"
  298. fork="true"
  299. forkclasspath="${aspectjtools.jar}"
  300. verbose="off">
  301. <src path="${example.dir}"/>
  302. <include name="tracing/*.java" />
  303. </iajc>
  304. <!-- test standalone application by running without tracing -->
  305. <echo message="---------- running without tracing - START"/>
  306. <java classname="tracing.ExampleMain">
  307. <classpath>
  308. <pathelement path="${aspectjrt.jar}"/>
  309. <pathelement path="${jar.dir}/tracingApp.jar"/>
  310. </classpath>
  311. </java>
  312. <echo message="---------- running without tracing - FINISH "/>
  313. <!-- Build a read-only tracing library -->
  314. <iajc outjar="${jar.dir}/tracingLib.jar"
  315. classpath="${aspectjrt.jar}"
  316. fork="true"
  317. forkclasspath="${aspectjtools.jar}"
  318. verbose="off">
  319. <src path="${example.dir}"/>
  320. <include name="tracing/version3/Trace.java" />
  321. </iajc>
  322. <!-- weave them -->
  323. <!-- This example uses a concrete aspect in source form, -->
  324. <!-- but the aspects could be written to be binary only. -->
  325. <iajc outjar="${jar.dir}/tracedApp.jar"
  326. inpath="${jar.dir}/tracingApp.jar"
  327. aspectpath="${jar.dir}/tracingLib.jar"
  328. classpath="${aspectjrt.jar}"
  329. fork="true"
  330. forkclasspath="${aspectjtools.jar}"
  331. verbose="off">
  332. <src path="${example.dir}"/>
  333. <include name="tracing/version3/TraceMyClasses.java" />
  334. </iajc>
  335. <!-- run with tracing -->
  336. <echo message="---------- running with tracing - START"/>
  337. <java classname="tracing.version3.TraceMyClasses">
  338. <classpath>
  339. <pathelement path="${aspectjrt.jar}"/>
  340. <pathelement path="${jar.dir}/tracingLib.jar"/>
  341. <pathelement path="${jar.dir}/tracedApp.jar"/>
  342. </classpath>
  343. </java>
  344. <echo message="---------- running with tracing - FINISH"/>
  345. </target>
  346. <!-- ============================================================= -->
  347. <!-- do tracing example with 1.2 load-time weaving -->
  348. <!-- (and use fork/forkclasspath to avoid Eclipse 2.x bug) -->
  349. <!-- ============================================================= -->
  350. <target name="tracing-lt" depends="init"
  351. description="tracing example with load-time aspect weaving">
  352. <antcall target="clean" />
  353. <!-- build application classes -->
  354. <iajc outjar="${jar.dir}/tracingApp.jar"
  355. classpath="${aspectjrt.jar}"
  356. fork="true"
  357. forkclasspath="${aspectjtools.jar}"
  358. verbose="off">
  359. <src path="${example.dir}"/>
  360. <include name="tracing/*.java" />
  361. </iajc>
  362. <!-- Build a read-only tracing library -->
  363. <iajc outjar="${jar.dir}/tracingLib.jar"
  364. classpath="${aspectjrt.jar}:${jar.dir}/tracingApp.jar"
  365. fork="true"
  366. forkclasspath="${aspectjtools.jar}"
  367. verbose="off">
  368. <src path="${example.dir}"/>
  369. <include name="tracing/version2/Trace.java" />
  370. <include name="tracing/version2/TraceMyClasses.java" />
  371. </iajc>
  372. <!-- test standalone application by running without tracing -->
  373. <echo message="---------- running without tracing - START"/>
  374. <java classname="tracing.ExampleMain">
  375. <classpath>
  376. <pathelement path="${aspectjrt.jar}"/>
  377. <pathelement path="${jar.dir}/tracingApp.jar"/>
  378. </classpath>
  379. </java>
  380. <echo message="---------- running without tracing - FINISH "/>
  381. <!-- run application with LTW to add tracing -->
  382. <echo message="---------- running with tracing - START"/>
  383. <java classname="tracing.ExampleMain"
  384. fork="true">
  385. <classpath>
  386. <pathelement path="${aspectjweaver.jar}"/>
  387. </classpath>
  388. <jvmarg line="-showversion"/>
  389. <sysproperty key="java.system.class.loader" value="org.aspectj.weaver.loadtime.WeavingURLClassLoader"/>
  390. <sysproperty key="aj.weaving.verbose" value="True"/>
  391. <sysproperty key="org.aspectj.weaver.showWeaveInfo" value="True"/>
  392. <sysproperty key="aj.class.path" path="${jar.dir}/tracingLib.jar:${jar.dir}/tracingApp.jar"/>
  393. <sysproperty key="aj.aspect.path" path="${jar.dir}/tracingLib.jar"/>
  394. </java>
  395. <echo message="---------- running with tracing - FINISH"/>
  396. </target>
  397. </project>