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 |
|
---|
13 | A task to manage Java class file dependencies.
|
---|
14 |
|
---|
15 | <h3>Description</h3>
|
---|
16 |
|
---|
17 | <p>
|
---|
18 | The depend task works by determining which classes are out of date with
|
---|
19 | respect to their source and then removing the class files of any other
|
---|
20 | classes which depend on the out-of-date classes.
|
---|
21 | </p>
|
---|
22 |
|
---|
23 | <p> To determine the class dependencies, the depend task analyses the class
|
---|
24 | files of all class files passed to it. Depend does not parse your source code in
|
---|
25 | any way but relies upon the class references encoded into the class files by the
|
---|
26 | compiler. This is generally faster than parsing the Java source.</p>
|
---|
27 |
|
---|
28 | <p>
|
---|
29 | To learn more about how this information is obtained from the class files,
|
---|
30 | please refer to <a href="http://java.sun.com/docs/books/vmspec/">the Java
|
---|
31 | Virtual Machine Specification</a>
|
---|
32 | </p>
|
---|
33 |
|
---|
34 | <p> Since a class' dependencies only change when the class itself changes, the
|
---|
35 | depend task is able to cache dependency information. Only those class files
|
---|
36 | which have changed will have their dependency information re-analysed. Note that
|
---|
37 | if you change a class' dependencies by changing the source, it will be
|
---|
38 | recompiled anyway. You can examine the dependency files created to understand
|
---|
39 | the dependencies of your classes. Please do not rely, however, on the format of
|
---|
40 | the information, as it may change in a later release. </p>
|
---|
41 |
|
---|
42 | <p> Once depend discovers all of the class dependencies, it "inverts"
|
---|
43 | this relation to determine, for each class, which other classes are dependent
|
---|
44 | upon it. This "affects" list is used to discover which classes are
|
---|
45 | invalidated by the out of date class. The class files of the invalidated
|
---|
46 | classes are removed, triggering the compilation of the affected classes. </p>
|
---|
47 |
|
---|
48 | <p> The depend task supports an attribute, "closure" which controls
|
---|
49 | whether depend will only consider direct class-class relationships or whether it
|
---|
50 | will also consider transitive, indirect relationships. For example, say there
|
---|
51 | are three classes, A, which depends on B, which in-turn depend on C. Now say
|
---|
52 | that class C is out of date. Without closure, only class B would be removed by
|
---|
53 | depend. With closure set, class A would also be removed. Normally direct
|
---|
54 | relationships are sufficient - it is unusual for a class to depend on another
|
---|
55 | without having a direct relationship. With closure set, you will notice that
|
---|
56 | depend typically removes far more class files. </p>
|
---|
57 |
|
---|
58 | <p>The classpath attribute for <code><depend></code> is optional. If it is present,
|
---|
59 | depend will check class dependencies against classes and jars on this classpath.
|
---|
60 | Any classes which depend on an element from this classpath and which are older
|
---|
61 | than that element will be deleted. A typical example where you would use this
|
---|
62 | facility would be where you are building a utility jar and want to make sure
|
---|
63 | classes 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,
|
---|
65 | such as the JDK runtime jar or third party jars, since doing so will just slow
|
---|
66 | down the dependency check. This means that if you do use a classpath for the
|
---|
67 | depend task it may be different from the classpath necessary to actually
|
---|
68 | compile your code.</p>
|
---|
69 |
|
---|
70 | <h3>Performance</h3>
|
---|
71 |
|
---|
72 | <p> The performance of the depend task is dependent on a
|
---|
73 | number of factors such as class relationship complexity and how many class files
|
---|
74 | are out of date. The decision about whether it is cheaper to just recompile all
|
---|
75 | classes or to use the depend task will depend on the size of your project and
|
---|
76 | how 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 |
|
---|
94 | The most obvious example of these limitations is that the task can't tell
|
---|
95 | which classes to recompile when a constant primitive data type exported
|
---|
96 | by other classes is changed. For example, a change in the definition of
|
---|
97 | something like
|
---|
98 | <pre>
|
---|
99 | public 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
|
---|
114 | will examine this to determine which classes are out of date. If you use multiple
|
---|
115 | source 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
|
---|
121 | will 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
|
---|
127 | retrieve dependency information. If this is not present, depend will not
|
---|
128 | use 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
|
---|
134 | classes which directly depend on out of date classes. If this is set to true,
|
---|
135 | depend will traverse the class dependency graph deleting all affected
|
---|
136 | classes. 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><depend></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
|
---|
156 | via a nested <code><classpath></code> element.</p>
|
---|
157 |
|
---|
158 | <p>Additionally,
|
---|
159 | this task forms an implicit
|
---|
160 | <a href="../CoreTypes/fileset.html">FileSet</a>
|
---|
161 | and supports all attributes of
|
---|
162 | <code><fileset></code> (<code>dir</code> becomes <code>srcdir</code>),
|
---|
163 | as well as the nested <code><include></code>,
|
---|
164 | <code><exclude></code>, and <code><patternset></code> elements.
|
---|
165 |
|
---|
166 | <h3>Examples</h3>
|
---|
167 | <pre><depend srcdir="${java.dir}"
|
---|
168 | destdir="${build.classes}"
|
---|
169 | cache="depcache"
|
---|
170 | closure="yes"/></pre>
|
---|
171 |
|
---|
172 | <p>removes any classes in the <code>${build.classes}</code> directory
|
---|
173 | that depend on out-of-date classes. Classes are considered out-of-date with
|
---|
174 | respect to the source in the <code>${java.dir}</code> directory, using the same
|
---|
175 | mechanism as the <code><javac></code> task. In this example, the
|
---|
176 | <code><depend></code> task caches its dependency
|
---|
177 | information in the <code>depcache</code> directory. </p>
|
---|
178 |
|
---|
179 | <pre>
|
---|
180 | <depend srcdir="${java.dir}" destdir="${build.classes}"
|
---|
181 | cache="depcache" closure="yes">
|
---|
182 | <include name="**/*.java"/>
|
---|
183 | <excludesfile name="${java.dir}/build_excludes"/>
|
---|
184 | </depend>
|
---|
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
|
---|
188 | in <code>${java.dir}/build_excludes</code>.</p>
|
---|
189 |
|
---|
190 | <hr>
|
---|
191 | <p align="center">Copyright © 2001-2002,2004 The Apache Software Foundation.
|
---|
192 | All rights Reserved.</p>
|
---|
193 |
|
---|
194 | </body>
|
---|
195 | </html>
|
---|
196 |
|
---|