source: release-kits/lirk3/resources/gs3-release-maker/ant/docs/manual/OptionalTasks/depend.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

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