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

desc.html 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- Content Stylesheet for Site -->
  3. <!-- start the processing -->
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  7. <meta name="author" value="Conor MacNeill">
  8. <title>The Jakarta Site - Mutant Design Notes</title>
  9. </head>
  10. <body bgcolor="#ffffff" text="#000000" link="#525D76">
  11. <table border="0" width="100%" cellspacing="0">
  12. <!-- TOP IMAGE -->
  13. <tr>
  14. <td colspan="2">
  15. <a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" align="left" border="0"/></a>
  16. </td>
  17. </tr>
  18. </table>
  19. <table border="0" width="100%" cellspacing="4">
  20. <tr><td colspan="2">
  21. <hr noshade="" size="1"/>
  22. </td></tr>
  23. <tr>
  24. <!-- LEFT SIDE NAVIGATION -->
  25. <td valign="top" nowrap="true">
  26. <p><strong>Apache Ant</strong></p>
  27. <ul>
  28. <li> <a href="./index.html">Front Page</a>
  29. </li>
  30. <li> <a href="./antnews.html">News</a>
  31. </li>
  32. <li> <a href="./manual/index.html">Documentation</a>
  33. </li>
  34. <li> <a href="./external.html">External Tools and Tasks</a>
  35. </li>
  36. <li> <a href="./resources.html">Resources</a>
  37. </li>
  38. <li> <a href="./faq.html">Ant FAQ</a>
  39. </li>
  40. <li> <a href="./problems.html">Having Problems?</a>
  41. </li>
  42. </ul>
  43. <p><strong>Download</strong></p>
  44. <ul>
  45. <li> <a href="http://jakarta.apache.org/site/binindex.html">Binaries</a>
  46. </li>
  47. <li> <a href="http://jakarta.apache.org/site/sourceindex.html">Source Code</a>
  48. </li>
  49. </ul>
  50. <p><strong>Jakarta</strong></p>
  51. <ul>
  52. <li> <a href="http://jakarta.apache.org/site/news.html">News & Status</a>
  53. </li>
  54. <li> <a href="http://jakarta.apache.org/site/mission.html">Mission</a>
  55. </li>
  56. <li> <a href="http://jakarta.apache.org/site/guidelines.html">Guidelines Notes</a>
  57. </li>
  58. <li> <a href="http://jakarta.apache.org/site/faqs.html">FAQs</a>
  59. </li>
  60. </ul>
  61. <p><strong>Get Involved</strong></p>
  62. <ul>
  63. <li> <a href="http://jakarta.apache.org/site/getinvolved.html">Overview</a>
  64. </li>
  65. <li> <a href="http://jakarta.apache.org/site/cvsindex.html">CVS Repositories</a>
  66. </li>
  67. <li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a>
  68. </li>
  69. <li> <a href="http://jakarta.apache.org/site/library.html">Reference Library</a>
  70. </li>
  71. <li> <a href="http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Ant">Bug Database</a>
  72. </li>
  73. <li> <a href="http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Ant&bug_severity=Enhancement">Enhancement Requests</a>
  74. </li>
  75. </ul>
  76. </td>
  77. <td align="left" valign="top">
  78. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  79. <tr><td bgcolor="#525D76">
  80. <font color="#ffffff" face="arial,helvetica,sanserif">
  81. <a name="Mutant Design Notes"><strong>Mutant Design Notes</strong></a>
  82. </font>
  83. </td></tr>
  84. <tr><td>
  85. <blockquote>
  86. <p>
  87. This is a brief, albeit rambling description of Mutant.
  88. Mutant has many experimental ideas which may or may not prove useful.
  89. I'll try to describe what is there and let anyone who is interested
  90. comment. Mutant is still immature. You'll notice that there is, at this
  91. time, just one task, a hacked version of the echo task, which I have
  92. been using to test out ideas. Most tasks would end up being pretty
  93. similar to their Ant 1.x version.
  94. </p>
  95. <p>
  96. OK, let me start with some of the motivating requirements. There are of
  97. coure many Ant2 requirements but I want to focus on these two for now.
  98. Mutant does also address many of the other Ant2 requirements.
  99. </p>
  100. <p>
  101. I'll use the terms Ant and mutant somewhat interchangeably - just
  102. habit, not an assumption of any sort.
  103. </p>
  104. <p>
  105. One of the things which is pretty difficult in Ant 1.x is the
  106. management of classpaths and classloaders. For example, today the
  107. antlr task requires the antlr classes in the classpath used to start
  108. ant. I'm talking here about the classpath built up in the ant.bat/ant
  109. script launchers. At the same time, the checkstyle task
  110. which uses antlr won't run if the antlr classes are in the classpath
  111. because then those classes cannot "see" the classes in the taskdef's
  112. classpath.
  113. </p>
  114. <p>
  115. Another requirement I have is extensibility. In Ant 1.x this is
  116. difficult because whenever a new type is created, each task which
  117. needs to support this type must be changed to provide the new addXXX
  118. method. The ejbjar task is on example of this problem with its concept of vendor
  119. specific tools. The zip/jar task, with its support for different types
  120. of fileset, is another. The addition of the classfileset to Ant requires
  121. a change to the zip task.
  122. </p>
  123. </blockquote>
  124. </td></tr>
  125. </table>
  126. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  127. <tr><td bgcolor="#525D76">
  128. <font color="#ffffff" face="arial,helvetica,sanserif">
  129. <a name="Mutant Initialization"><strong>Mutant Initialization</strong></a>
  130. </font>
  131. </td></tr>
  132. <tr><td>
  133. <blockquote>
  134. <p>
  135. Mutant defines a classloader hierarchy somewhat similar to that used
  136. in Tomcat 4. Tasks join into this hierarchy at a particular point to
  137. ensure they have visibility of the necessary interface classes and no
  138. visibility of the Ant core itself. There is nothing particularly novel
  139. about this approach, but tasks are able to request certain additional resources
  140. as we will see later.
  141. </p>
  142. <p>
  143. Mutant starts with two jars. One is the start.jar which contains just
  144. one class, Main.java which establishes the initial configuration and
  145. then runs the appropriate front end command line class. If a different
  146. front end was desired, a different launch class, in its own jar, would
  147. be used. This would perhaps configure the classloader hierarchy somewhat
  148. differently and start the approriate GUI front end class.
  149. </p>
  150. <p>
  151. The second jar, init.jar, provides a number of initialisation utilities. These
  152. are used by Main.java to setup Ant and would also be used by any other front end
  153. to configure Ant. The important class here is the
  154. InitConfig which communicates the state of Ant at startup into the the core of
  155. Ant when it starts up. Main determines the location of ANT_HOME based on the
  156. location of the start classes and then populates the InitConfig with both
  157. classloaders and information about the location of various jars and config
  158. files.
  159. </p>
  160. <p>
  161. At the top of the classloader hierarchy
  162. are the bootstrap and system classloaders. I won't really
  163. distinguish between these in mutant. Combined they provide the JDK
  164. classes, plus the classes from the init and start jars. One objective is
  165. to keep the footprint of the init and start jars small so they do not
  166. require any external classes, which may then become visible lower in the
  167. hierarchy. Main does not explicitly create these loaders, of course, but
  168. just adds a reference to the init config as system class loader
  169. </p>
  170. <p>
  171. The next jar is for the common area. This provides interface definitions
  172. and utility classes for use by both the core and by tasks/types etc. It
  173. is loaded from ANT_HOME/lib/common/*.jar. Typically this is just
  174. lib/common/common.jar but any other jars in here are loaded. This
  175. pattern is used in the construction of all of the classloaders.
  176. </p>
  177. <p>
  178. Next up is the core loader. It includes the lib/antcore/antcore.jar plus
  179. any others including the XML parser jars. Mutant's core does not assume that
  180. the project model will come from an XML description but XML facilities
  181. are needed in the core for reading in Ant library defs and config files.
  182. The parser jar locations are also stored in the init config. This lets
  183. the jars be added to any Ant library that wants to use Ant's XML parser
  184. rather than providing its own. Similarly tools.jar's location is
  185. determined automatically and added to the config for use by tasks which
  186. request it. I'll go into more detail when discussing the antlib processing.
  187. </p>
  188. <p>
  189. The final jar that is loaded is the jar for the frontend - cli.jar. This
  190. is not passed in init config since these classes are not visible to the
  191. core and are not needed by it. So the hierarchy is
  192. <pre>
  193. jdk classes
  194. |
  195. start/init
  196. |
  197. common
  198. |
  199. antcore
  200. |
  201. cli
  202. </pre>
  203. </p>
  204. <p>
  205. Task classloaders generally will come in at common, hiding the core classes, front
  206. end and XML parser classes from tasks.
  207. </p>
  208. <p>
  209. Once Main has setup the initConfig, it creates the front end commandline
  210. class and launches mutant proper, passing it the command line args and
  211. the init config.
  212. </p>
  213. <p>
  214. A GUI would typically replace start.jar and the cli.jar with its own
  215. versions which manage model construction from GUI processes rather than
  216. from XML files. It may be possible to move some of Main.java's
  217. processing into init.jar if it is useful to other front ends. I haven't
  218. looked at that balance.
  219. </p>
  220. </blockquote>
  221. </td></tr>
  222. </table>
  223. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  224. <tr><td bgcolor="#525D76">
  225. <font color="#ffffff" face="arial,helvetica,sanserif">
  226. <a name="Mutant Frontend"><strong>Mutant Frontend</strong></a>
  227. </font>
  228. </td></tr>
  229. <tr><td>
  230. <blockquote>
  231. <p>
  232. The front end is responsible for coordinating execution of Ant. It
  233. manages command line arguments, builds a model of the Project to be
  234. evaluated and coordinates the execution services of the core. cli.jar
  235. contains not only the front-end code but also the XML parsing code for
  236. building a project model from an XML description. Other front ends may
  237. choose to build project models in different ways. Commandline is pretty
  238. similar to Ant 1.x's Main.java - it handles arguments, building loggers,
  239. listeners, defines, etc - actually I haven't fully implemented
  240. command line defines in
  241. mutant yet but it would be similar to Ant 1.x.
  242. </p>
  243. <p>
  244. Commandline then moves to building a project model from the XML
  245. representation. I have just expanded the approach in Ant 1's
  246. ProjectHelper for XML parsing, moving away from a stack of inner classes.
  247. The classes in the front end XML parsing use some XML utility base
  248. classes from the core.
  249. </p>
  250. <p>
  251. The XML parsing handles two elements at parse time. One is the &lt;ref&gt;
  252. element which is used for project references - that is relationships
  253. between project files. The referenced project is parsed as well. The
  254. second is the &lt;include&gt; element which includes either another complete
  255. project or a project &lt;fragment&gt; directly into the project. All the other
  256. elements are used to build a project model which is later processed in
  257. the core.
  258. </p>
  259. <p>
  260. The project model itself is organized like this
  261. </p>
  262. <p>
  263. <ul>
  264. <li>A project contains</li>
  265. <ul>
  266. <li>named references to other projects</li>
  267. <li>targets</li>
  268. <li>build elements (tasks, type instances)</li>
  269. </ul>
  270. <li>A target contains</li>
  271. <ul>
  272. <li>build elements (tasks, type instances)</li>
  273. </ul>
  274. <li>A build element contains</li>
  275. <ul>
  276. <li>build elements (nested elements)</li>
  277. </ul>
  278. </ul>
  279. </p>
  280. <p>
  281. So, for now the project model contains top level tasks and type
  282. instances. I'm still thinking about those and property scoping
  283. especially in the face of project refs and property overrides. Anyway,
  284. the running of these tasks is currently disabled.
  285. </p>
  286. <p>
  287. Once the model is built, the commandline creates an execution manager
  288. instance, passing it the initConfig built by Main.jar. It adds build
  289. listeners and then starts the build using the services of the
  290. ExecutionManager.
  291. </p>
  292. </blockquote>
  293. </td></tr>
  294. </table>
  295. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  296. <tr><td bgcolor="#525D76">
  297. <font color="#ffffff" face="arial,helvetica,sanserif">
  298. <a name="Ant Libraries"><strong>Ant Libraries</strong></a>
  299. </font>
  300. </td></tr>
  301. <tr><td>
  302. <blockquote>
  303. <p>
  304. Before we get into execution proper, I'll deal with the structure of an
  305. ant library and how it works. An antlibrary is a jar file with a library
  306. descriptor located in META-INF/antlib.xml. This defines what
  307. typedefs/taskdefs/converters the library makes available to Ant. The
  308. classes or at least some of the classes for the library will normally be
  309. available in the jar. The descriptor looks like this (I'll provide two
  310. examples here)
  311. </p>
  312. <p>
  313. <pre>
  314. &lt;antlib libid="ant.io"
  315. home="http://jakarta.apache.org/ant"
  316. isolated="true"&gt;
  317. &lt;typedef name="thread" classname="java.lang.Thread"/&gt;
  318. &lt;taskdef name="echo" classname="org.apache.ant.taskdef.io.Echo"/&gt;
  319. &lt;converter classname="org.apache.ant.taskdef.io.FileConverter"/&gt;
  320. &lt;/antlib&gt;
  321. &lt;antlib libid="ant.file"
  322. home="http://jakarta.apache.org/ant"
  323. reqxml="true" reqtools="true" extends="ant.io"
  324. isolated="true"&gt;
  325. &lt;taskdef name="copy" classname="org.apache.ant.file.copy"/&gt;
  326. &lt;/antlib&gt;
  327. </pre>
  328. </p>
  329. <p>
  330. the "libid" attribute is used to globally identify a library. It is used
  331. in Ant to pick which tasks you want to make available to a build file.
  332. As the number of tasks available goes up, this is used to prevent name
  333. collisions, etc. The name is constructed similarly to a Java package name -
  334. i.e Reverse DNS order.
  335. </p>
  336. <p>
  337. The "home" attribute is a bit of fluff unused by mutant to allow tools
  338. to manage libraries and update them etc. More thought could go into
  339. this.
  340. </p>
  341. <p>
  342. "reqxml" allows a library to say that it wants to use Ant's XML parser
  343. classes. Note that these will be coming from the library's classloader
  344. so they will not, in fact, be the same runtime classes as used in Ant's core,
  345. but it saves tasks packaging their own XML parsers.
  346. </p>
  347. <p>
  348. "reqtools" allows a library to specify that it uses classes from Sun's
  349. tools.jar file. Again, if tools.jar is available it will be added to the
  350. list of classes in the library's classloader
  351. </p>
  352. <p>
  353. "extends" allows for a single "inheritance" style relationship between
  354. libraries. I'm not sure how useful this may be yet but it seems
  355. important for accessing common custom types. It basically translates
  356. into the class loader for this library using the one identified in
  357. extends as its parent.
  358. </p>
  359. <p>
  360. "isolate" specifies that each task created from this libary comes from
  361. its own classloader. This can be used with tasks derived from Java
  362. applications which have static initialisers. This used to be an issue
  363. with the Anakia task, for example. Similarly it could be used to ensure that
  364. tool.jar classes are unloaded to stop memory leaks. Again this is
  365. experimental so may not prove ultimately useful.
  366. </p>
  367. <p>
  368. The &lt;typedef&gt; in the example creates a &lt;thread&gt; type. That is just a bit of fun which
  369. I'll use in an example later. It does show the typedefing of a type from
  370. outside the ant library however.
  371. </p>
  372. <p>
  373. &lt;taskdef&gt; is pretty obvious. It identifies a taskname with a class from
  374. the library. The import task, which I have not yet implemented will
  375. allow this name to be aliased - something like
  376. </p>
  377. <p>
  378. &lt;import libid="ant.file" task="echo" alias="antecho"/&gt;
  379. </p>
  380. <p>
  381. Tasks are not made available automatically. The build file must state
  382. which tasks it wants to use using an &lt;import&gt; task. This is similar to
  383. Java's import statement. Similarly classes whose ids start with "ant."
  384. are fully imported at the start of execution.
  385. </p>
  386. </blockquote>
  387. </td></tr>
  388. </table>
  389. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  390. <tr><td bgcolor="#525D76">
  391. <font color="#ffffff" face="arial,helvetica,sanserif">
  392. <a name="Mutant Configuration"><strong>Mutant Configuration</strong></a>
  393. </font>
  394. </td></tr>
  395. <tr><td>
  396. <blockquote>
  397. <p>
  398. When mutant starts execution, it reads in a config file. Actually it
  399. attempts to read two files, one from $ANT_HOME/conf/antconfig.xml and
  400. another from $HOME/.ant/antconfig.xml. Others could be added even
  401. specified in the command line. These config files are used to provide
  402. two things - libpaths and task dirs.
  403. </p>
  404. <p>
  405. Taskdirs are locations to search for additional ant libraries. As people
  406. bundle Ant tasks and types with their products, it will not be practical
  407. to bundle all this into ANT_HOME/lib. These additional dirs are scanned
  408. for ant libraries. All .zip/.jar/.tsk files which contain the
  409. META-INF/antlib.xml file will be processed.
  410. </p>
  411. <p>
  412. Sometimes, of course, the tasks and the libraries upon which they depend
  413. are not produced by the same people. It is not feasible to go in and
  414. edit manifests to connect the ant library with its required support
  415. jars, so the libpath element in the config file is used to specify
  416. additional paths to be added to a library's classloader. An example
  417. config would be
  418. </p>
  419. <p>
  420. <pre>
  421. &lt;antconfig&gt;
  422. &lt;libpath libid="ant.file" path="fubar"/&gt;
  423. &lt;libpath libid="ant.file" url="http://fubar"/&gt;
  424. &lt;/antconfig&gt;
  425. </pre>
  426. </p>
  427. <p>
  428. Obviously other information can be added to the config - standard
  429. property values, compiler prefs, etc. I haven't done that yet. User
  430. level config override system level configs.
  431. </p>
  432. <p>
  433. So, when a ant library creates a classloader, it will take a number of
  434. URLS. One is the task library itself, the XML parser classes if
  435. requested, the tools.jar if requested, and any additional libraries
  436. specified in the &lt;antconfig&gt;. The parent loader is the common loader
  437. from the initconfig. unless this library is an extending library.
  438. </p>
  439. </blockquote>
  440. </td></tr>
  441. </table>
  442. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  443. <tr><td bgcolor="#525D76">
  444. <font color="#ffffff" face="arial,helvetica,sanserif">
  445. <a name="Mutant Execution"><strong>Mutant Execution</strong></a>
  446. </font>
  447. </td></tr>
  448. <tr><td>
  449. <blockquote>
  450. <p>
  451. Execution of a build is provided by the core through two key classes.
  452. One if the ExecutionManager and the other is the ExecutionFrame. An
  453. execution frame is created for each project in the project model
  454. hierarchy. It represents the execution state of the project - data
  455. values, imported tasks, typedefs, taskdefs, etc.
  456. </p>
  457. <p>
  458. The ExecutionManager begins by reading configs, searching for ant
  459. libraries, configuring and appending any additional paths, etc. It then
  460. creates a root ExecutionFrame which represents the root project. when a
  461. build is commenced, the project model is validated and then passed to
  462. the ExecutionFrame.
  463. </p>
  464. <p>
  465. the ExecutionFrame is the main execution class. When it is created it
  466. imports all ant libraries with ids that start with ant.*. All others are
  467. available but must be explicitly imported with &lt;import&gt; tasks. When the
  468. project is passed in, ExecutionFrames are created for any referenced
  469. projects. This builds an ExecutionFrame hierarchy which parallels the
  470. project hierarchy. Each &lt;ref&gt; uses a name to identify the referenced
  471. project. All property and target references use these reference names to
  472. identify the particular frame that hold the data. As an example, look at
  473. this build file
  474. </p>
  475. <p>
  476. <pre>
  477. &lt;project default="test" basedir=".." doc:Hello="true"&gt;
  478. &lt;ref project="test.ant" name="reftest"/&gt;
  479. &lt;target name="test" depends="reftest:test2"&gt;
  480. &lt;echo message="hello"/&gt;
  481. &lt;/target&gt;
  482. &lt;/project&gt;
  483. </pre>
  484. </p>
  485. <p>
  486. Notice the depends reference to the test2 target in the test.ant project
  487. file. I am still using the ":" as a separator for refs. It doesn't
  488. collide with XML namespaces so that should be OK.
  489. </p>
  490. <p>
  491. Execution proceeds by determining the targets in the various frames
  492. which need to be executed. The appropriate frame is requested to execute
  493. the target's tasks and type instances. The imports for the frame are
  494. consulted to determine what is the approrpiate library and class from
  495. that library. A classloader is fetched, the class is instantiated,
  496. introspected and then configured from the corresponding part of the
  497. project model. Ant 1.x's IntrospectionHelper has been split into two -
  498. the ClassIntrospector and the Reflector. When the task is being
  499. configured, the context classloader is set. Similarly it is set when the
  500. task is being executed. Types are handled similarly. When a type in
  501. instantiated or a task executed, and they support the appropriate
  502. interface, they will be passed a context through which they can access
  503. the services of the core. Currently the context is an interface although
  504. I have wondered if an abstract class may be better to handle expansion
  505. of the services available over time.
  506. </p>
  507. </blockquote>
  508. </td></tr>
  509. </table>
  510. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  511. <tr><td bgcolor="#525D76">
  512. <font color="#ffffff" face="arial,helvetica,sanserif">
  513. <a name="Introspection and Polymorphism"><strong>Introspection and Polymorphism</strong></a>
  514. </font>
  515. </td></tr>
  516. <tr><td>
  517. <blockquote>
  518. <p>
  519. Introspection is not a lot different from Ant 1.x. After some thought I
  520. have dropped the createXXX method to allow for polymorphic type support, discussed
  521. below. setXXX methods, coupled with an approriate string to
  522. type converter are used for attributes. addXXX methods are used for
  523. nested elements. All of the value setting has been moved to a Reflector
  524. object. Object creation for addXXX methods is no longer provided in the
  525. reflector class, just the storage of the value. This allows support for
  526. add methods defined in terms of interfaces. For example, the hacked Echo
  527. task I am using has this definition
  528. </p>
  529. <p>
  530. <pre>
  531. /**
  532. * testing
  533. *
  534. * @param runnable testing
  535. */
  536. public void addRun(Runnable runnable) {
  537. log("Adding runnable of type "
  538. + runnable.getClass().getName(), MessageLevel.MSG_WARN);
  539. }
  540. </pre>
  541. </p>
  542. <p>
  543. So when mutant encounteres a nested element it does the following checks
  544. </p>
  545. <p>
  546. Is the value specified by reference?
  547. </p>
  548. <p>
  549. &lt;run ant:refid="test"/&gt;
  550. </p>
  551. <p>
  552. Is it specified by as a polymorphic type?
  553. </p>
  554. <p>
  555. &lt;run ant:type="thread"/&gt;
  556. </p>
  557. <p>
  558. or is it just a normal run o' the mill nested element, which is
  559. instantiated by a zero arg constructor.
  560. </p>
  561. <p>
  562. Note the use of the ant namespace for the metadata. In essence the
  563. nested element name &lt;run&gt; identifies the add method to be used, while
  564. the refId or type elements specify the actual instance or type to be
  565. used. The ant:type identifies an Ant datatype to be instantiated. If
  566. neither is specified, the type that is expected by the identified
  567. method, addRun in this case, is used to create an instance. In this case
  568. that would fail.
  569. </p>
  570. <p>
  571. Polymorphism, coupled with typedefs is one way, and a good way IMHO, of
  572. solving the extensibility of tasks such as ejbjar.
  573. </p>
  574. <p>
  575. OK, that is about the size of it. Let me finish with two complete build
  576. files and the result of running mutant on them.
  577. </p>
  578. <h3>build.ant</h3>
  579. <p>
  580. <pre>
  581. &lt;project default="test" basedir=".." doc:Hello="true"&gt;
  582. &lt;ref project="test.ant" name="reftest"/&gt;
  583. &lt;target name="test" depends="reftest:test2"&gt;
  584. &lt;echo message="hello"/&gt;
  585. &lt;/target&gt;
  586. &lt;/project&gt;
  587. </pre>
  588. </p>
  589. <h3>test.ant</h3>
  590. <p>
  591. <pre>
  592. &lt;project default="test" basedir="." doc:Hello="true"&gt;
  593. &lt;target name="test2"&gt;
  594. &lt;thread ant:id="testit"/&gt;
  595. &lt;echo message="hello2"&gt;
  596. &lt;run ant:refid="testit"&gt;
  597. &lt;/run&gt;
  598. &lt;/echo&gt;
  599. &lt;echo message="hello3"&gt;
  600. &lt;run ant:type="thread"&gt;
  601. &lt;/run&gt;
  602. &lt;/echo&gt;
  603. &lt;/target&gt;
  604. &lt;/project&gt;
  605. </pre>
  606. </p>
  607. <p>
  608. If I run mutant via a simple script which has just one line
  609. </p>
  610. <p>
  611. java -jar /home/conor/dev/mutant/dist/lib/start.jar $*
  612. </p>
  613. <p>
  614. I get this
  615. </p>
  616. <p>
  617. <pre>
  618. test2:
  619. [echo] Adding runnable of type java.lang.Thread
  620. [echo] hello2
  621. [echo] Adding runnable of type java.lang.Thread
  622. [echo] hello3
  623. test:
  624. [echo] hello
  625. BUILD SUCCESSFUL
  626. Total time: 0 seconds
  627. </pre>
  628. </p>
  629. <p>
  630. Lets change the &lt;run&gt; definition to
  631. </p>
  632. <p>
  633. &lt;run/&gt; in test.ant and the result becomes
  634. </p>
  635. <p>
  636. <pre>
  637. test2:
  638. [echo] Adding runnable of type java.lang.Thread
  639. [echo] hello2
  640. BUILD FAILED
  641. /home/conor/dev/mutant/test/test.ant:10:
  642. No element can be created for nested element &lt;run&gt;.
  643. Please provide a value by reference or specify the value type
  644. </pre>
  645. </p>
  646. </blockquote>
  647. </td></tr>
  648. </table>
  649. </td>
  650. </tr>
  651. <!-- FOOTER -->
  652. <tr><td colspan="2">
  653. <hr noshade="" size="1"/>
  654. </td></tr>
  655. <tr><td colspan="2">
  656. <div align="center"><font color="#525D76" size="-1"><em>
  657. Copyright &#169; 2000-2002, Apache Software Foundation
  658. </em></font></div>
  659. </td></tr>
  660. </table>
  661. </body>
  662. </html>
  663. <!-- end the processing -->