java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Ant arrow How to use Depend task
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4086
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use Depend task E-mail
User Rating: / 8
PoorBest 

Depend

A task to manage Java class file dependencies.

Description

The depend task works by determining which classes are out of date with respect to their source and then removing the class files of any other classes which depend on the out-of-date classes.

To determine the class dependencies, the depend task analyses the class files of all class files passed to it. Depend does not parse your source code in any way but relies upon the class references encoded into the class files by the compiler. This is generally faster than parsing the Java source.

To learn more about how this information is obtained from the class files, please refer to the Java Virtual Machine Specification

Since a class' dependencies only change when the class itself changes, the depend task is able to cache dependency information. Only those class files which have changed will have their dependency information re-analysed. Note that if you change a class' dependencies by changing the source, it will be recompiled anyway. You can examine the dependency files created to understand the dependencies of your classes. Please do not rely, however, on the format of the information, as it may change in a later release.

Once depend discovers all of the class dependencies, it "inverts" this relation to determine, for each class, which other classes are dependent upon it. This "affects" list is used to discover which classes are invalidated by the out of date class. The class files of the invalidated classes are removed, triggering the compilation of the affected classes.

The depend task supports an attribute, "closure" which controls whether depend will only consider direct class-class relationships or whether it will also consider transitive, indirect relationships. For example, say there are three classes, A, which depends on B, which in-turn depend on C. Now say that class C is out of date. Without closure, only class B would be removed by depend. With closure set, class A would also be removed. Normally direct relationships are sufficient - it is unusual for a class to depend on another without having a direct relationship. With closure set, you will notice that depend typically removes far more class files.

The classpath attribute for <depend> is optional. If it is present, depend will check class dependencies against classes and jars on this classpath. Any classes which depend on an element from this classpath and which are older than that element will be deleted. A typical example where you would use this facility would be where you are building a utility jar and want to make sure classes which are out of date with respect to this jar are rebuilt. You should not include jars in this classpath which you do not expect to change, such as the JDK runtime jar or third party jars, since doing so will just slow down the dependency check. This means that if you do use a classpath for the depend task it may be different from the classpath necessary to actually compile your code.

Performance

The performance of the depend task is dependent on a number of factors such as class relationship complexity and how many class files are out of date. The decision about whether it is cheaper to just recompile all classes or to use the depend task will depend on the size of your project and how interrelated your classes are.

Limitations

There are some source dependencies which depend will not detect.

  • If the Java compiler optimizes away a class relationship, there can be a source dependency without a class dependency.
  • Non public classes cause two problems. Firstly depend cannot relate the class file to a source file. In the future this may be addressed using the source file attribute in the classfile. Secondly, neither depend nor the compiler tasks can detect when a non public class is missing. Inner classes are handled by the depend task.
The most obvious example of these limitations is that the task can't tell which classes to recompile when a constant primitive data type exported by other classes is changed. For example, a change in the definition of something like

public final class Constants {
  public final static boolean DEBUG=false;
}
will not be picked up by other classes.

Parameters

Attribute Description Required
srcDir This is the directory where the source exists. depend will examine this to determine which classes are out of date. If you use multiple source directories you can pass this attribute a path of source directories. Yes
destDir This is the root directory of the class files which will be analysed. If this is not present, the srcdir is used. No
cache This is a directory in which depend can store and retrieve dependency information. If this is not present, depend will not use a cache No
closure This attribute controls whether depend only removes classes which directly depend on out of date classes. If this is set to true, depend will traverse the class dependency graph deleting all affected classes. Defaults to false No
dump If true the dependency information will be written to the debug level log No
classpath The classpath containing jars and classes for which <depend> should also check dependencies No

Parameters specified as nested elements

The depend task's classpath attribute is a PATH-like structure and can also be set via a nested <classpath> element.

Additionally, this task forms an implicit FileSet and supports all attributes of <fileset> (dir becomes srcdir), as well as the nested <include>, <exclude>, and <patternset> elements.

Examples

<depend srcdir="${java.dir}"
        destdir="${build.classes}"
        cache="depcache"

        closure="yes"/>

removes any classes in the ${build.classes} directory that depend on out-of-date classes. Classes are considered out-of-date with respect to the source in the ${java.dir} directory, using the same mechanism as the <javac> task. In this example, the <depend> task caches its dependency information in the depcache directory.

<depend srcdir="${java.dir}" destdir="${build.classes}"
        cache="depcache" closure="yes">
  <include name="**/*.java"/>

  <excludesfile name="${java.dir}/build_excludes"/>
</depend>

does the same as the previous example, but explicitly includes all .java files, except those that match the list given in ${java.dir}/build_excludes.

Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.