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.

original-specification.html 16 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "strict.dtd">
  16. <HTML>
  17. <HEAD>
  18. <TITLE>Ant Specification, version 0.5</TITLE>
  19. </HEAD>
  20. <BODY>
  21. <H1>Ant Specification</H1>
  22. <P>Version 0.5 (2000/04/20)</P>
  23. <P>This document specifies the behavior of Ant. At this time, this is a
  24. working document with no implementation. It is hoped that this specification
  25. will lead to a simplier and more consistent implementation of Ant.</P>
  26. <P>This document is not intended to be used as an end user manual or user
  27. guide to Ant. To adequatly explain the concepts herein in a way appropriate to
  28. such a use would potentially complicate this document.</P>
  29. <H2>Design Goals</H2>
  30. <P>The following are the overall design goals of Ant:</P>
  31. <UL>
  32. <LI>Simplicity</LI>
  33. <LI>Understandability</LI>
  34. <LI>Extensibility</LI>
  35. </UL>
  36. <H3>Simplicity</H3>
  37. <P>Ant must be simple to use. Of course, as the definition of simple varies
  38. according to the audience of the program. For Ant, since it is a build tool
  39. aimed at programmers, the goal is to be simple to use for a competent
  40. programmer.</P>
  41. <H3>Understandability</H3>
  42. <P>Ant must be clearly understandible for a first time as well as a veteran
  43. user. This means that a new user should be able to use Ant comfortably the
  44. first time and understand how to modify a build file by looking at it. And it
  45. should not require much experience with Ant to understand how it works and how
  46. to configure it for particular situtations.</P>
  47. <H3>Extensibility</H3>
  48. <P>Ant must be easy to extend. The API used to extend Ant must be easy to
  49. use and the way in which these extensions are located and used by the core
  50. runtime should be clear.</P>
  51. <H2>Conceptual Overview</H2>
  52. <P>This is a conceptual overview of the components used by Ant. Full APIs
  53. will be defined later.</P>
  54. <H3>Project</H3>
  55. <P>The base unit of work in Ant is the <STRONG>Project</STRONG>. A Project
  56. is defined by an editable text file and is represented by an object of type
  57. <CODE>org.apache.ant.Project</CODE> at runtime.</P>
  58. <P>A Project is a collection of <STRONG>Properties</STRONG> and
  59. <STRONG>Targets</STRONG>.</P>
  60. <H3>Properties</H3>
  61. <P>Properties are mutable name-value pairs that are scoped to the Project
  62. and held in a table. Only one pair is allowed per name. It is anticipated that
  63. this data structure would be of type <CODE>java.util.Properties</CODE> or a type that has approximatly
  64. the same contract.</P>
  65. <P>Properties can be defined in a hierarchical manner. The order of
  66. precidence in this hiearchy is:</P>
  67. <UL>
  68. <LI>Properties defined on the command line or via a GUI tool</LI>
  69. <LI>Properties defined in the text file which defines the project.</LI>
  70. <LI>Properties defined in a file in the users <CODE>user.home</CODE> directory</LI>
  71. <LI>Properties defined in the installation directory that can be shared
  72. by multiple users.</LI>
  73. </UL>
  74. <P>Note: The current version of Ant allows the System property list to be
  75. consulted for a return value if the property list doesn't satisfy the requested
  76. property name. As all Java code has access to the system property list via the
  77. <CODE>java.lang.System</CODE> class, this functionality is considered to be confusing and to be
  78. removed.</P>
  79. <P>Note: The current version of Ant allows property substitution to be
  80. performed in the project file. This functionality is being removed.</P>
  81. <H3>Targets</H3>
  82. <P>Targets are ordered collections of <STRONG>Tasks</STRONG>, units of work
  83. to be performed if a Target is executed. </P>
  84. <P>Targets can define dependancies on other Targets within the Project. If
  85. a Target is deemed to be executed, either directly on the command line, or via
  86. a dependancy from some other Target, then all of its dependencies must first be
  87. executed. Circular depenancies are resolved by examination of the dependancy
  88. stack when a Target is evaluated. If a dependancy is already on the stack of
  89. targets to be executed, then the dependancy is considered to have been
  90. satisfied.</P>
  91. <P>After all dependancies of a Target have been satisfied, all of the Tasks
  92. contained by the target are configured and executed in sequential order. </P>
  93. <H3>Tasks</H3>
  94. <P>A Task is a unit of work. When a Task is to be executed, an instance of
  95. the class that defines the behavior of the particular task specified is
  96. instantiated and then configured. This class implements the <CODE>org.apache.ant.Task</CODE> interface.
  97. It is then executed so that it may be able to perform its function. It is
  98. important to note that this configuration occurs just before execution of the
  99. task, and after execution of any previous tasks, so that configuration
  100. information that was modified by any other Task can be properly set.</P>
  101. <P>When a Task is executed, it is provided access to the object
  102. representing the Project it is running in allowing it to examine the Property
  103. list of the project and access to various methods needed to operate.</P>
  104. <H2>Task Jar Layout</H2>
  105. <P>Tasks are defined within Java Archive files. The name of the JAR
  106. determines the name under which the task is known by in the system. For
  107. example, if a Task JAR is named mvdir.jar, the task is known to the system as
  108. <CODE>&quot;mvdir&quot;</CODE>.</P>
  109. <P><EM>Question: Should we say that tasks belong in a JAR file with the
  110. .tsk extension?</EM></P>
  111. <P>The class within the Jar file that implements the <CODE>org.apache.ant.Task</CODE> interface is
  112. specified by a manifest attribute named <CODE>Ant-Task-Class</CODE> in the Jar manifest. An example
  113. manifest would look like:</P>
  114. <PRE> Manifest-Version: 1.0
  115. Ant-Task-Class: org.apache.ant.task.javac.JavacTask</PRE>
  116. <P>When the task is used by Ant, a class loader is created that reads
  117. classes from the JAR file. This ensures that there is no chance of namespace
  118. collision in the classes of various task JAR files.</P>
  119. <H2>Installation</H2>
  120. <P>When Ant is installed on a user system, it installs a directory
  121. structure with the following form:</P>
  122. <PRE>&lt;installdir&gt;/ant (unix shell script)
  123. /ant.bat
  124. /ant.jar
  125. /ant.properties
  126. /tasks/[task jar files]
  127. /docs/[documentation]
  128. /README</PRE>
  129. <P>Note: Current Jakarta practice is to name the Unix shell script with a
  130. .sh extension. This goes against Unix conventions and is unecessary. Testing
  131. has shown that the leaving the extension off on Unix will not interfere with
  132. the working of the Windows batch file.</P>
  133. <P>Note: The ant.jar file has been moved from the lib/ directory and placed
  134. alongside the shell startup scripts (which have also been moved out of the bin/
  135. directory). This is because on windows platforms, the .jar file is an
  136. executable file of sorts.</P>
  137. <H3>Ant Properties</H3>
  138. <P>The <CODE>ant.properties</CODE> file contains a list of all the properties that should be
  139. set by default when ant is run. In addition there are a few special properties
  140. that are used directly by ant. An example of these properties in use is:</P>
  141. <PRE> system.taskdir=tasks/
  142. user.taskdir=anttasks/</PRE>
  143. <P>The <CODE>system.taskdir</CODE> property sets where the system looks for Java ARchive files
  144. containing tasks. If this property defines a relative path, then the path is
  145. taken as relative from the installation directory.</P>
  146. <P>The <CODE>user.taskdir</CODE> property defines where users can locate Java Archive files
  147. containing tasks. If this property defines a realtive path, then the path is
  148. taken as relative from the users home directory (as defined by the <CODE>user.home</CODE>
  149. system property). Task JAR files in this directory take precendence of those in
  150. the system directory.</P>
  151. <P>Note: <EM>It has been suggested to add a properties file hook to the
  152. command line to roll in props. Pending investigation.</EM></P>
  153. <H3>User Preferences</H3>
  154. <P>In addition to the Ant installation directory, an <CODE>ant.properties</CODE> file can be
  155. located in the user's home directory (as found by the system property <CODE>user.home</CODE>)
  156. which can define user preferences such as the location of a user tasks
  157. directory. Properties defined in this file take precidence over those set in
  158. the installation's <CODE>ant.properties</CODE> file. Such a file could look like:</P>
  159. <PRE> user.taskdir=anttasks/
  160. javac.debug=off</PRE>
  161. <P>Properties starting with <CODE>&quot;system.&quot;</CODE> in the user's <CODE>ant.properties</CODE> file are not
  162. allowed and must cause a warning to be thrown.</P>
  163. <H2>Project Configuration</H2>
  164. <P>Ant's Project text file is structured using XML and reflects the
  165. structure of the various components described in the Conceptual Overview.</P>
  166. <P>A sample Project file:</P>
  167. <PRE>&lt;project name=&quot;projectname&quot; defaulttarget=&quot;main&quot; taskdir=&quot;tasks/&quot;&gt;
  168. &lt;property name=&quot;javac.debug&quot; value=&quot;on&quot;/&gt;
  169. &lt;target name=&quot;main&quot;&gt;
  170. &lt;taskimpl ...&gt;
  171. ...
  172. &lt;/taskimpl&gt;
  173. &lt;/target&gt;
  174. &lt;/project&gt;</PRE>
  175. <H3>The Project Element</H3>
  176. <P>The <CODE>project</CODE> element has the following required attributes:</P>
  177. <UL>
  178. <LI><CODE><STRONG>defaulttarget</STRONG></CODE> defining the default target to be executed if no other target
  179. is specified when Ant is run</LI>
  180. </UL>
  181. <P>It also has the following optional allowed attributes:</P>
  182. <UL>
  183. <LI><CODE><CODE><STRONG>name</STRONG></CODE></CODE> defining a name for this project</LI>
  184. <LI><CODE><STRONG>taskdir</STRONG></CODE> defining a directory in which project specific tasks can be
  185. located. Tasks in this directory take precedence over those in the either the
  186. user taskdir or the installation taskdir.</LI>
  187. </UL>
  188. <P>The following elements are allowed as children of the project
  189. element:</P>
  190. <UL>
  191. <LI><CODE><STRONG>property</STRONG></CODE> defining a property scoped to the project</LI>
  192. <LI><CODE><STRONG>target</STRONG></CODE> defining a target</LI>
  193. </UL>
  194. <H3>The Property Element</H3>
  195. <P>asdf</P>
  196. <H3>The Target Element</H3>
  197. <P>asfd</P>
  198. <H2>Configuration of Tasks</H2>
  199. <P>The Task section of the configuration file is structured as such:</P>
  200. <PRE> &lt;[taskname] [attname=value] [attname=value]...]&gt;
  201. [&lt;[elementname] [attname=value] ...&gt; ... &lt;/[elementname]&gt;]
  202. &lt;/[taskname]&gt;</PRE>
  203. <P>The taskname is used to find the class of the Task. Once the class has
  204. been located and an instance of it created, all of the attributes of the Task
  205. are reflected into the task instance using bean patterns. For example, if a
  206. Task contains an attribute named &quot;directory&quot;, the method named
  207. setDirectory would be called with the attribute value cast to the appropriate
  208. type desired by the method. <EM>(What to do if the type isn't a file or a
  209. simple type, look for the class and see if it has a setString method?)</EM></P>
  210. <P>Text blocks contained by the element are added to task using an addText
  211. method. <EM>Place an example...</EM></P>
  212. <P>For each element contained in the Task definition, an addElementname
  213. method is found on the task. The parameter type of the method defines an object
  214. that will be loaded and instantiated. The attributes of the element are
  215. reflected into the object using bean methods. Any text is set using the addText
  216. method. Any elements are recursed in the same fashion.</P>
  217. <P>Search order of tasks.... project/user/system</P>
  218. <H2>Command Line</H2>
  219. <P>The command line utility provided with Ant must support the following
  220. allowable syntax:</P>
  221. <P><CODE>ant projectfile [prop=value [prop=value...]] [target]</CODE></P>
  222. <P>Internally, the command line shell scripts should call the <CODE>org.apache.ant.Main</CODE> class
  223. with the following arguments:</P>
  224. <PRE>java -Dant.home=installdir org.apache.ant.Main $*</PRE>
  225. <P>or its equivalent on the host platform. Note that the ant installation
  226. directory is a System property. The above syntax results in ant.home being
  227. placed in the System property list.</P>
  228. <P>Note: <EM>On unix, finding the directory of the script that was launched
  229. is relatively easy. However on Windows, I'm not sure the best way of handling
  230. this.</EM></P>
  231. <H2>File Naming Conventions</H2>
  232. <P>File naming in a cross platform tool is tricky. For maximum portability
  233. and understandiblity it is recommended that project files use the following
  234. conventions:</P>
  235. <UL>
  236. <LI>The '/' character is used as a directory seperator</LI>
  237. <LI>The ':' character is used as a path seperator</LI>
  238. <LI>Only relative paths are used</LI>
  239. </UL>
  240. <P>However, to allow for maximum flexibility and to allow project authors
  241. to use conventions that make sense on their native platform, Ant allows for a
  242. representation of file names which has the following rules:</P>
  243. <UL>
  244. <LI>Directories are seperated by the forward slash ('/') or backwards
  245. slash ('\') character.</LI>
  246. <LI>File names starting with either of the above directory seperators are
  247. considered to be absolute paths.</LI>
  248. <LI>On systems that support multiple file roots (e.g. Windows), a file
  249. name that starts with a single alphabetical character followed by a colon (':')
  250. followed by a directory seperator defines an absolute path where the letter
  251. corresponds with a directory root.</LI>
  252. <LI>File names starting with any other character are considered to be
  253. relative paths. In project files, all relative paths are resolved relative to
  254. the directory in which the project file is located.</LI>
  255. </UL>
  256. <P>Absolute paths are not recommended for build files as they reduce the
  257. ability to share a project between u sers or machines.</P>
  258. <P>In situtations where a set of filenames need to be specified, such as
  259. defining a classpath, both the colon (':') andsemicolon (';') are allowable
  260. characters to seperate each filename. The only case that has to be
  261. disambiguated is if a user specifies paths that contain windows style absolute
  262. paths. In this case, the colon is not treated as a path seperator if the
  263. following rules are met:</P>
  264. <UL>
  265. <LI>The character two places before the colon is either of the allowable
  266. path seperators (':' or ';') or if the colon is the second character of the
  267. string.</LI>
  268. <LI>The character immediately before the colon is a alphabetic character
  269. in the range a-z or A-Z.</LI>
  270. <LI>The character immediately after the colon is either of the allowable
  271. directory seperators ('/' or '\').</LI>
  272. </UL>
  273. <H2>Scripting Model</H2>
  274. <P>Sam, I'm leaving this to you. </P>
  275. <H2>Runtime Requirements</H2>
  276. <P>The following requirements are system requirements that Ant should have
  277. in order to run correctly. We should not bundle in any of these into the
  278. distribution of ant.</P>
  279. <UL>
  280. <LI>JDK 1.1 or greater</LI>
  281. <LI>A JAXP compliant parser on the classpath</LI>
  282. </UL>
  283. <P>Note: <EM>When running on JDK 1.2 or greater, the tools.jar isn't on the
  284. classpath by default. There's a few different ways we can take care of this.
  285. One is to put it on the classpath in the execute script (I don't like this
  286. one). Another is to find the location of tools.jar at runtime and put it on the
  287. classpath of class loaders that load in task.jars so that, at least in the
  288. scope of the Tasks, the relevant classes are there. </EM></P>
  289. <P></P>
  290. <P></P> </BODY>
  291. </HTML>