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.

readme-build-and-test-aspectj.html 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <html>
  2. <head>
  3. <title>Build and Test AspectJ</title>
  4. </head>
  5. <body>
  6. <h1>Build and Test AspectJ</h1>
  7. This describes how to build and test AspectJ
  8. for developers working on source code for AspectJ.
  9. It covers building with Ant or Eclipse and testing with
  10. JUnit and the harness used for compiler tests.
  11. For information on how the build works and how to
  12. debug failed builds, see
  13. <a href="readme-build-module.html">
  14. readme-build-module.html</a>.
  15. <ol>
  16. <li>Quick start</li>
  17. <li>Requirements</li>
  18. <li>Standard builds
  19. <ol>
  20. <li>Building using Ant</li>
  21. <li>Building with Eclipse</li>
  22. <li>Running the Ant build scripts from Eclipse</li>
  23. <li>Using Eclipse to compile but Ant to assemble</li>
  24. </ol>
  25. </li>
  26. <li>Running build products
  27. <ol>
  28. <li>Running the compiler, browser, or harness from the command-line</li>
  29. <li>Running the compiler, browser, or harness from Eclipse</li>
  30. <li>Running Ant-built jars from Eclipse</li>
  31. </ol>
  32. </li>
  33. <li>Testing AspectJ
  34. <ol>
  35. <li>Running JUnit tests in Eclipse</li>
  36. <li>Running JUnit tests from the command-line without Eclipse</li>
  37. <li>Running JUnit tests from Ant without Eclipse</li>
  38. <li>Using the test harness to run compiler tests</li>
  39. </ol>
  40. </li>
  41. <li>Releases
  42. <ol>
  43. <li>Release builds</li>
  44. <li>Release preconditions and testing</li>
  45. <li>Release completion</li>
  46. </ol>
  47. </li>
  48. <li>New modules, Java 5, and Ant-only build problems</li>
  49. <li>Build Problems</li>
  50. </ol>
  51. <h3>Quick start</h3>
  52. This is a minimal introduction to building and testing AspectJ.
  53. <p/>Command-line users use CVS to check out something like this:
  54. <pre>
  55. export CVS_ROOT=":pserver:anonymous@dev.eclipse.org:/home/technology"
  56. cvs co org.aspectj/modules</pre>
  57. If using Eclipse, check out the subdirectories of
  58. <code>org.aspectj/modules</code> as Java projects.
  59. Skip modules <code>aspectj-attic</code> and (unless running
  60. compiler tests) <code>tests</code> and most <code>testing*</code>
  61. modules. Do not skip <code>testing-utils</code>,
  62. which is used by other modules.
  63. <p/>Build an AspectJ distribution:
  64. <pre>
  65. cd org.aspectj/modules/build
  66. ../lib/ant/bin/ant -f build.xml</pre>
  67. To speed the build, Eclipse users can adopt the Eclipse-produced .class files:
  68. <pre> ../lib/ant/bin/ant -f build.xml -Dbuild.config=useEclipseCompiles</pre>
  69. Install the distribution (e.g., into build/../aspectj-install):
  70. <pre> java -jar ../aj-build/dist/aspectj-DEVELOPMENT.jar</pre>
  71. You can skip the GUI by specifying an existing, empty writable
  72. target directory using <code>-to {targDir}</code>:
  73. <pre> java -jar ../aj-build/dist/aspectj-DEVELOPMENT.jar -to .</pre>
  74. Test it by running the build script in the examples directory:
  75. <pre> cd ../aspectj-install/doc/examples
  76. ../../ant/bin/ant</pre>
  77. This should build and run the spacewar example.
  78. <h3>Requirements</h3>
  79. To build requires only the AspectJ project modules.
  80. All necessary libraries and tools are in the
  81. <a href="../lib/">lib</a> directory. For command-line users,
  82. that usually means checking out the modules directory:
  83. <pre>
  84. export CVS_ROOT=":pserver:anonymous@dev.eclipse.org:/home/technology"
  85. cvs co org.aspectj/modules
  86. </pre>
  87. Eclipse users should check out subdirectories of
  88. <code>org.aspectj/modules</code> as a Java project.
  89. <p/>
  90. <p>
  91. Not all modules are required.
  92. The <code>aspectj-attic</code> module only has old code,
  93. and the <code>tests</code> and <code>testing-*</code> modules
  94. are only needed to run tests. Also modules with Java 5 source
  95. in <code>{module}/java5-src</code> require Java 5 to build
  96. for the release; the Java 5 source files are ignored when building
  97. under 1.4 or earlier VM's.
  98. </p>
  99. <h3>Standard builds</h3>
  100. <h4>Building using Ant</h4>
  101. To do a build, use Ant to run <a href="build.xml">build.xml</a>
  102. from this <a href=".">build</a> directory.
  103. To run Ant, use the project's <a href="../lib/ant">../lib/ant</a>
  104. scripts and libraries, not your own.
  105. The default target builds the AspectJ distribution;
  106. see the <a href="build.xml">build.xml</a> for other targets.
  107. Consider defining the following flag properties:
  108. <p/>
  109. <table cellpadding="1" border="1">
  110. <tr><th>Property</th><th>Meaning</th>
  111. </tr>
  112. <tr><td>module.name
  113. </td><td>To build any module (esp. those not directly supported
  114. by a target), use the "any-module" target and define
  115. the module name.
  116. </td></tr>
  117. <tr><td>check.build.jar
  118. </td><td>any value cause build to fail if
  119. <code>lib/build/build.jar</code> is out of date. (This is a
  120. built archive of the build module to avoid bootstrapping.)
  121. </td></tr>
  122. <tr><td>build.config
  123. </td><td>override default configuration in build.xml.
  124. Significant values include "verbose" for more output
  125. and "useEclipseCompiles" to assume that Eclipse has
  126. compiled modules into their bin directories, and just
  127. assemble those classes.
  128. </td></tr>
  129. </table>
  130. <p/>
  131. <p>
  132. You can also use the build script in each module and the targets
  133. "test" (default) or "compile". ("clean" removes all build products,
  134. not just those for that module.)
  135. <p/>
  136. For example, to build everything into a release bundle,
  137. with verbose logging
  138. <pre>
  139. cd modules/build
  140. ../lib/ant/bin/ant
  141. </pre>
  142. To build only the asm module (and any modules it requires) using
  143. <code>modules/build</code>:
  144. <pre>
  145. cd modules/build
  146. ../lib/ant/bin/ant -f build.xml any-module -Dmodule.name=asm
  147. </pre>
  148. To run JUnit tests (output to <code>../aj-build/junit</code>)
  149. for the util module using <code>util/build.xml</code>:
  150. <pre>
  151. cd modules/util
  152. ../lib/ant/bin/ant test
  153. </pre>
  154. To build the test harness into
  155. <code>../aj-build/jars/testing-drivers-all.jar</code>:
  156. <pre>
  157. cd modules/build
  158. ../lib/ant/bin/ant -f build.xml build-testing-drivers
  159. </pre>
  160. <h4>Building with Eclipse</h4>
  161. As mentioned above, the modules are Eclipse Java projects, so
  162. once checked out, they should build as-is. That will enable you
  163. to run the compiler or test harness from within Eclipse (see below),
  164. but it will not build the AspectJ release as Ant does.
  165. <h4>Running the Ant build scripts from Eclipse</h4>
  166. When running Ant from Eclipse, be sure to replace the Eclipse Ant
  167. libraries with ours. In the Ant configuration, remove all jars
  168. specified by Eclipse and add all the libraries in
  169. <a href="../lib/ant/lib">../lib/ant/lib</a>
  170. as well as in <a href="../lib/junit">../lib/junit</a>.
  171. (Do not add <code>../lib/build/build.jar</code>, which is
  172. added via a taskdef declaration.)
  173. <p/>
  174. If you find on rebuilding that the build products are not
  175. being regenerated, you may need to manually delete them
  176. or restart eclipse (the files are not being closed); see
  177. <a href="readme-build-module.html">readme-build-module.html</a>
  178. for more information.
  179. <h4>Using Eclipse to compile but Ant to assemble</h4>
  180. Assuming Eclipse is compiling the AspectJ modules successfully,
  181. you can use Ant to assemble the eclipse-build .class files into a
  182. product by including <code>useEclipseCompiles</code> in the
  183. <code>build.config</code>
  184. variable as described above. That reduces the build process
  185. to product assembly, which can be completed in a couple minutes.
  186. (And of course you can run Ant from Eclipse as described above.)
  187. <h4>Running the compiler, browser, or harness from the command-line</h4>
  188. The build produces jar files in
  189. <a href="../aj-build/jars/">../aj-build/jars/</a>,
  190. some of which have manifests specifying the main class, so they
  191. can be run using <code>java -jar {file} {arguments}</code>.
  192. <p/>To run the compiler from the command-line, use the <code>ajbrowser</code> jar file:
  193. <pre>
  194. java -jar aj-build/jars/ajbrowser-all.jar {compile arguments}
  195. </pre>
  196. This will run <code>ajbrowser</code> if you provide no arguments or
  197. only (unflagged) .lst file arguments. To run the test harness,
  198. use the <code>testing-drivers</code> jar file:
  199. <pre>
  200. java -jar aj-build/jars/testing-drivers-all.jar tests/ajcTests.xml ...
  201. </pre>
  202. <h4>Running the compiler, browser, or harness from Eclipse</h4>
  203. To run things within Eclipse, create a run configuration from the
  204. defining module using the main class:
  205. <p/>
  206. <table border="1" cellpadding="1">
  207. <tr><th>Program</th><th>Module</th><th>Main</th></tr>
  208. <tr><td>AspectJ compiler</td><td>org.aspectj.ajdt.core</td><td>org.aspectj.tools.ajc.Main</td></tr>
  209. <tr><td>AspectJ browser</td><td>ajbrowser</td><td>org.aspectj.tools.ajbrowser.Main</td></tr>
  210. <tr><td>Test harness</td><td>testing-drivers</td><td>org.aspectj.testing.drivers.Harness</td></tr>
  211. </table>
  212. <h4>Running Ant-built jars from Eclipse</h4>
  213. You can run build products (built jars) from Eclipse in two ways:
  214. <ul>
  215. <li>Put them on the classpath of some run configuration</li>
  216. <li>Select the jar files and right-click to "open with default editor"
  217. (assuming your system is configured to run .jar files)</li>
  218. </ul>
  219. You might do this to run the installer or test the browser as built.
  220. However, doing so might prevent those jar files from being recreated
  221. in the next build.
  222. It appears that sometimes these jar files are not close during the
  223. Eclipse session, which means they cannot be overwritten in new builds,
  224. even those run from a different Ant process.
  225. If you find that builds are silently failing, try deleting the
  226. build products.
  227. <h3>Testing AspectJ</h3>
  228. Each module has a tree of JUnit tests in the <code>testsrc</code> directory.
  229. These parallel the <code>src</code> directories and contain roll-up suites
  230. for each package
  231. (<code>{module}/testsrc/{packagePath}/{package}Tests.java</code>) and
  232. for the module as a whole
  233. (<code>{module}/testsrc/{module}ModuleTests.java</code>).
  234. <p/>The AspectJ project also has <i>additional</i> custom tests in the
  235. <a href="../tests">tests module</a>,
  236. mainly the compiler tests run by the harness in
  237. <a href="../tests/ajcTests.xml">ajcTests.xml</a>. <u>It is important
  238. to run these additional compiler tests (not covered by the JUnit
  239. suite) before and after any change to the compiler.</u>
  240. <h4>Running JUnit tests in Eclipse</h4>
  241. JUnit tests may be run under eclipse by selecting any JUnit source file
  242. and creating a run configuration for it.
  243. To run all the JUnit tests, use Ant to "build"
  244. <a href="../tests/junitModules.xml">../tests/junitModules.xml</a>.
  245. This file uses the eclipse module bin directories as its classpath,
  246. so it will not work for someone not compiling with Eclipse.
  247. <h4>Running JUnit tests from the command-line without Eclipse</h4>
  248. The AspectJ project committers do not do this, but it should work fine.
  249. The trick is to build the modules with their associated test code
  250. (which happens by default)
  251. and put the resulting jars on the classpath with the JUnit harness.
  252. <h4>Running JUnit tests from Ant without Eclipse</h4>
  253. This entails editing
  254. <a href="../tests/junitModules.xml">../tests/junitModules.xml</a>
  255. to use a classpath containing the built module jars as described above.
  256. [todo: update junitModules.xml with non-eclipse variant]
  257. <h4>Using the test harness to run compiler tests</h4>
  258. The <code>build-testing-drivers</code> target builds a single jar with
  259. the AspectJ binaries and a test harness as the main class.
  260. It reads test suite files like
  261. <a href="../tests/ajcTests.xml">../tests/ajcTests.xml</a>;
  262. use the -help flag to see available options.
  263. For more information, see
  264. <a href="../tests/readme-tests-module.html">
  265. ../tests/readme-tests-module.html</a>.
  266. <p/>
  267. <hr/>
  268. <h3><a name="releases"></a>Releases</h3>
  269. <h4>Release builds</h4>
  270. Committers do official release builds to create the distribution
  271. released in binary form from the web site.
  272. Release builds differ only in running
  273. from a clean, up-to-date tree and with correct build version values
  274. in <a href="build-properties.xml">build-properties.xml</a>, which
  275. will update <code>org.aspectj.bridge.Version</code>.
  276. Do not run using the <code>build.config</code> value
  277. <code>useEclipseCompiles</code>,
  278. because this will include testing classes in the release libraries.
  279. See <a href="#version">Version synchronization</a> below
  280. for more details on how the version is updated.
  281. <h4>Release preconditions and testing</h4>
  282. <p/>
  283. Normally, we do releases only after fixing all high-priority
  284. (P1 and P2) bugs in the bug database
  285. (<a href="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;priority=P1&amp;priority=P2">
  286. All open AspectJ bugs with P1 and P2</a>).
  287. For bug fixes, associated tests in
  288. <code>tests/ajcTestsFailing.xml</code> are fixed and moved to
  289. <code>tests/ajcTests.xml</code>.
  290. <p/>Before a release, run the release tests as described in
  291. <a href="../tests/readme-release-tests.html">
  292. ../tests/readme-release-tests.html</a>
  293. (deprecated? using:
  294. <a href="../build/release-checklist.txt">
  295. ../build/release-checklist.txt</a>).
  296. <h4>Release completion</h4>
  297. When the release build is accepted,
  298. tag the tree with the release version
  299. so others can do diffs or create patches
  300. based on the release code. E.g., from the command line:
  301. <pre>
  302. cd org.aspectj/
  303. cvs tag -R -c v1_1_0
  304. </pre>
  305. <p/>
  306. Pushing the release out to the web involves manually updating
  307. <code>aspectj-home/</code> with the release files
  308. (and documentation, if it is not a preview release),
  309. verifying the downloads and pages,
  310. and sending any release notifications.
  311. Save the release installer, test results, and any notes
  312. about deferred bugs or tests in
  313. <code>org.aspectj/releases/aspectj-{version}/</code>.
  314. <p/>
  315. <hr/>
  316. <a name="antInvariants"/>
  317. <h3>New modules, Java 5, and Ant-only build problems</h3>
  318. <p>
  319. As described more fully in
  320. <a href="readme-build-module.html">readme-build-module.html</a>,
  321. the build system introspects on module and the .classpath file
  322. to determine how to build. Further, it enforces stricter build
  323. invariants than the Eclipse projects do; when your code works
  324. in Eclipse but fails in the Ant, it's your responsibility to fix it
  325. by following the build invariants below.
  326. </p>
  327. <p>
  328. How the build system introspects, and the build invariants that
  329. are enforced by the Ant build:
  330. </p>
  331. <ul>
  332. <li>A given module is identified by its directory name.
  333. </li>
  334. <li>Most modules are Eclipse Java projects; some are AspectJ projects.
  335. Eclipse is not required to build.
  336. </li>
  337. <li>The file <code>{module.name}/.classpath</code> is read to determine
  338. the source directories and required projects and libraries.
  339. </li>
  340. <li>Normal Java source files are in <code>src</code> and <code>testsrc</code>
  341. directories.
  342. </li>
  343. <li>Java 5 source files are in <code>java5-src</code> and <code>java5-testsrc</code>
  344. directories.
  345. </li>
  346. <li>Neither <code>testsrc</code> directory is used in production builds.
  347. </li>
  348. <li>
  349. This only requires what's in the
  350. <a href="../lib">../lib</a> directory and the usual Java VM's.
  351. That means modules can only depend on each other and the libraries
  352. in <a href="../lib">../lib</a>.
  353. </li>
  354. <li>Modules are built into jar files. <code>{module.name}.jar</code>
  355. includes only the module classes, and <code>{module.name}-all.jar</code>
  356. includes the module classes plus any antecendant modules and any
  357. required libraries not skipped (see below).
  358. </li>
  359. <li>A file <code>{module.name}/{module.name}.mf.txt</code>, if available,
  360. will be used as the jar file manifest, after replacing certain
  361. variables in the <code>.mf.txt</code> file.
  362. </li>
  363. <li>All required libraries are included in the production jars, except
  364. for testing libraries and those "skipped" in
  365. <a href="src/org/aspectj/internal/tools/build/Builder.properties">
  366. Builder.properties</a>
  367. (Ant, JUnit, etc.).
  368. </li>
  369. <li>Test classes are excluded from the compile process for production builds.
  370. These result in the same jar files; there is no way to
  371. tell externally whether the test classes were stripped from a jar.
  372. </li>
  373. <li>ONLY resources specified as <code>resource.pattern</code> in
  374. <a href="src/org/aspectj/internal/tools/build/Builder.properties">
  375. Builder.properties</a>
  376. are included with assembled jars.
  377. </li>
  378. <li>No <code>testing-*</code> module is used in production builds,
  379. directly or indirectly.
  380. </li>
  381. <li>It is an error for any code to depend on any <code>testsrc</code> code,
  382. whether in the same or another module.
  383. </li>
  384. <li>AspectJ projects are built in Ant using
  385. <a href="../lib/aspectj">../lib/aspectj</a>.
  386. </li>
  387. <li>Java 5 code is not supported in AspectJ (yet).
  388. </li>
  389. <li>Java 5 code is built in Ant only if JAVA_HOME points to Java 5 (or later).
  390. </li>
  391. <li>No normal code can depend on any Java 5 code.
  392. The build system checks by building everything using the
  393. lowest VM supported by the tools.
  394. </li>
  395. </ul>
  396. <p>That means there are a number of legal Eclipse projects and code
  397. arrangements which are not valid AspectJ modules.
  398. When you add modules, libraries, or dependencies, you must build
  399. with Ant to verify these invariants are not broken.
  400. </p>
  401. <h3>Build problems</h3>
  402. Some build problems and fixes encountered in the past:
  403. <ul>
  404. <li>If the build works in Eclipse, but fails in Ant,
  405. do not assume the build scripts are broken.
  406. See <a href="#antInvariants">Invariants enforced only in Ant</a>.
  407. </li>
  408. <li>If your compiles fail because Ant cannot find <code>javac</code>,
  409. put the JDK bin directory on your PATH and/or define
  410. the JAVA_HOME environment variable.
  411. Ant requires the path to the <code>javac</code> executable
  412. when the <code>BuildModule</code> taskdef runs. I think it either
  413. gets it from <code>$JAVA_HOME</code> or if the <code>bin</code>
  414. directory is on the <code>PATH</code>.
  415. </li>
  416. <li>If using an IBM JDK at version 1.4 or higher within Eclipse,
  417. then the default value of JRE_LIB will point to the jar file
  418. "core.jar." Unlike the Sun JDK, IBM does not package the full
  419. runtime into a single jar ("rt.jar"), but instead has multiple
  420. jar files. Since core.jar does not contain the graphics libraries,
  421. several of the AspectJ projects will fail to build as checked out
  422. of CVS - there are missing dependencies on AWT and swing. The
  423. solution is to add graphics.jar to the project classpaths... BUT
  424. if this is added as an ordinary (external jar), then the main
  425. ant build script will pick up the contents of graphics.jar and
  426. include it in the aspectj distribution (obvious clue, the size of
  427. the built aspectjtools.jar doubles to about 10MB). Instead, from the
  428. Java Build Path properties page of the project, select "Add Library"
  429. and add the JDK library. You now have to remove the JRE_LIB entry
  430. from the project or Eclipse complains about duplicate jar files
  431. in the path.
  432. </li>
  433. <li>More generally, if you find extra classes in the assembled jars,
  434. most likely you have added unexpected libraries to the build, e.g.,
  435. when adding libraries for the IBM JRE.
  436. To skip those, add them to the "skip.libraries" list in
  437. <a href="src/org/aspectj/internal/tools/build/Builder.properties">
  438. src/org/aspectj/internal/tools/build/Builder.properties</a>.
  439. These libraries will always be skipped for any module built this way;
  440. there is no way to include a library in one module but not another.
  441. For more information on the properties file, see
  442. <a href="readme-build-module.html">readme-build-module.html</a>.
  443. </li>
  444. </ul>
  445. </body>
  446. </html>