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