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

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