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.

depend.html 8.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Depend Task</title>
  5. </head>
  6. <body>
  7. <h2>Depend</h2>
  8. A task to manage Java class file dependencies.
  9. <h3>Description</h3>
  10. <p>
  11. The depend task works by determining which classes are out of date with
  12. respect to their source and then removing the class files of any other
  13. classes which depend on the out-of-date classes.
  14. </p>
  15. <p> To determine the class dependencies, the depend task analyses the class
  16. files of all class files passed to it. Depend does not parse your source code in
  17. any way but relies upon the class references encoded into the class files by the
  18. compiler. This is generally faster than parsing the Java source.</p>
  19. <p>
  20. To learn more about how this information is obtained from the class files,
  21. please refer to <a href="http://java.sun.com/docs/books/vmspec/">the Java
  22. Virtual Machine Specification</a>
  23. </p>
  24. <p> Since a class' dependencies only change when the class itself changes, the
  25. depend task is able to cache dependency information. Only those class files
  26. which have changed will have their dependency information re-analysed. Note that
  27. if you change a class' dependencies by changing the source, it will be
  28. recompiled anyway. You can examine the dependency files created to understand
  29. the dependencies of your classes. Please do not rely, however, on the format of
  30. the information, as it may change in a later release. </p>
  31. <p> Once depend discovers all of the class dependencies, it &quot;inverts&quot;
  32. this relation to determine, for each class, which other classes are dependent
  33. upon it. This &quot;affects&quot; list is used to discover which classes are
  34. invalidated by the out of date class. The class files of the invalidated
  35. classes are removed, triggering the compilation of the affected classes. </p>
  36. <p> The depend task supports an attribute, &quot;closure&quot; which controls
  37. whether depend will only consider direct class-class relationships or whether it
  38. will also consider transitive, indirect relationships. For example, say there
  39. are three classes, A, which depends on B, which in-turn depend on C. Now say
  40. that class C is out of date. Without closure, only class B would be removed by
  41. depend. With closure set, class A would also be removed. Normally direct
  42. relationships are sufficient - it is unusual for a class to depend on another
  43. without having a direct relationship. With closure set, you will notice that
  44. depend typically removes far more class files. </p>
  45. <p>The classpath attribute for <code>&lt;depend&gt;</code> is optional. If it is present,
  46. depend will check class dependencies against classes and jars on this classpath.
  47. Any classes which depend on an element from this classpath and which are older
  48. than that element will be deleted. A typical example where you would use this
  49. facility would be where you are building a utility jar and want to make sure
  50. classes which are out of date with respect to this jar are rebuilt. You should
  51. <b>not</b> include jars in this classpath which you do not expect to change,
  52. such as the JDK runtime jar or third party jars, since doing so will just slow
  53. down the dependency check. This means that if you do use a classpath for the
  54. depend task it may be different from the classpath necessary to actually
  55. compile your code.</p>
  56. <h3>Performance</h3>
  57. <p> The performance of the depend task is dependent on a
  58. number of factors such as class relationship complexity and how many class files
  59. are out of date. The decision about whether it is cheaper to just recompile all
  60. classes or to use the depend task will depend on the size of your project and
  61. how interrelated your classes are. </p>
  62. <h3>Limitations</h3>
  63. <p> There are some source dependencies which depend will not detect. </p>
  64. <ul>
  65. <li>If the Java compiler optimizes away a class relationship,
  66. there can be a source dependency without a class dependency. </li>
  67. <li>Non public classes cause two problems. Firstly depend cannot relate
  68. the class file to a source file. In the future this may be addressed
  69. using the source file attribute in the classfile. Secondly, neither
  70. depend nor the compiler tasks can detect when a non public class is
  71. missing. Inner classes are handled by the depend task.</li>
  72. </ul>
  73. The most obvious example of these limitations is that the task can't tell
  74. which classes to recompile when a constant primitive data type exported
  75. by other classes is changed. For example, a change in the definition of
  76. something like
  77. <pre>
  78. public final class Constants {
  79. public final static boolean DEBUG=false;
  80. }
  81. </pre> will not be picked up by other classes.
  82. <h3>Parameters</h3>
  83. <table border="1" cellpadding="2" cellspacing="0">
  84. <tr>
  85. <td valign="top"><b>Attribute</b></td>
  86. <td valign="top"><b>Description</b></td>
  87. <td align="center" valign="top"><b>Required</b></td>
  88. </tr>
  89. <tr>
  90. <td valign="top">srcDir</td>
  91. <td valign="top">This is the directory where the source exists. depend
  92. will examine this to determine which classes are out of date. If you use multiple
  93. source directories you can pass this attribute a path of source directories.</td>
  94. <td valign="top" align="center">Yes</td>
  95. </tr>
  96. <tr>
  97. <td valign="top">destDir</td>
  98. <td valign="top">This is the root directory of the class files which
  99. will be analysed. If this is not present, the srcdir is used.</td>
  100. <td valign="top" align="center">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">cache</td>
  104. <td valign="top">This is a directory in which depend can store and
  105. retrieve dependency information. If this is not present, depend will not
  106. use a cache </td>
  107. <td valign="top" align="center">No</td>
  108. </tr>
  109. <tr>
  110. <td valign="top">closure</td>
  111. <td valign="top">This attribute controls whether depend only removes
  112. classes which directly depend on out of date classes. If this is set to true,
  113. depend will traverse the class dependency graph deleting all affected
  114. classes. Defaults to false</td>
  115. <td valign="top" align="center">No</td>
  116. </tr>
  117. <tr>
  118. <td valign="top">dump</td>
  119. <td valign="top">If true the dependency information will be written to the debug level log
  120. </td>
  121. <td valign="top" align="center">No</td>
  122. </tr>
  123. <tr>
  124. <td valign="top">classpath</td>
  125. <td valign="top">The classpath containg jars and classes for which <code>&lt;depend&gt;</code> should also
  126. check dependencies</td>
  127. <td valign="top" align="center">No</td>
  128. </tr>
  129. </table>
  130. <h3>Parameters specified as nested elements</h3>
  131. <p>The <code>depend</code> task's <code>classpath</code> attribute is a
  132. <a href="../using.html#path">PATH-like structure</a> and can also be set
  133. via a nested <code>&lt;classpath&gt;</code> element.</p>
  134. <p>Additionally,
  135. this task forms an implicit
  136. <a href="../CoreTypes/fileset.html">FileSet</a>
  137. and supports all attributes of
  138. <code>&lt;fileset&gt;</code> (<code>dir</code> becomes <code>srcdir</code>),
  139. as well as the nested <code>&lt;include&gt;</code>,
  140. <code>&lt;exclude&gt;</code>, and <code>&lt;patternset&gt;</code> elements.
  141. <h3>Examples</h3>
  142. <pre>&lt;depend srcdir=&quot;${java.dir}&quot;
  143. destdir=&quot;${build.classes}&quot;
  144. cache=&quot;depcache&quot;
  145. closure=&quot;yes&quot;/&gt;</pre>
  146. <p>removes any classes in the <code>${build.classes}</code> directory
  147. that depend on out-of-date classes. Classes are considered out-of-date with
  148. respect to the source in the <code>${java.dir}</code> directory, using the same
  149. mechanism as the <code>&lt;javac&gt;</code> task. In this example, the
  150. <code>&lt;depend&gt;</code> task caches its dependency
  151. information in the <code>depcache</code> directory. </p>
  152. <pre>
  153. &lt;depend srcdir=&quot;${java.dir}&quot; destdir=&quot;${build.classes}&quot;
  154. cache=&quot;depcache&quot; closure=&quot;yes&quot;&gt;
  155. &lt;include name=&quot;**/*.java&quot;/&gt;
  156. &lt;excludesfile name=&quot;${java.dir}/build_excludes&quot;/&gt;
  157. &lt;/depend&gt;
  158. </pre>
  159. <p>does the same as the previous example, but explicitly includes all
  160. <code>.java</code> files, except those that match the list given
  161. in <code>${java.dir}/build_excludes</code>.</p>
  162. <hr>
  163. <p align="center">Copyright &copy; 2001-2002 Apache Software Foundation.
  164. All rights Reserved.</p>
  165. </body>
  166. </html>