Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional.depend

public Class Depend

extends MatchingTask
Class Inheritance
Imports
java.io.BufferedReader, .BufferedWriter, .File, .FileReader, .FileWriter, .IOException, java.net.URL, java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashSet, .List, .Map, .Objects, .Set, java.util.function.Predicate, java.util.stream.Stream, org.apache.tools.ant.AntClassLoader, .BuildException, .DirectoryScanner, .Project, org.apache.tools.ant.taskdefs.MatchingTask, org.apache.tools.ant.taskdefs.rmic.DefaultRmicAdapter, .WLRmic, org.apache.tools.ant.types.Path, .Reference, .Resource, .ResourceCollection, org.apache.tools.ant.types.resources.FileProvider, org.apache.tools.ant.util.FileUtils, org.apache.tools.ant.util.depend.DependencyAnalyzer

Generates a dependency file for a given set of classes.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Depend.ClassFileInfo

A class (struct) user to manage information about a class

Field Summary

Modifier and TypeField and Description
private Map<String, Map<String, Depend.ClassFileInfo>>
affectedClassMap

A map which gives for every class a list of the class which it affects.

private File
cache

The directory which contains the dependency cache.

private static final String
CACHE_FILE_NAME

constants used with the cache file

private Map<String, Depend.ClassFileInfo>
classFileInfoMap

A map which gives information about a class

private static final String
CLASSNAME_PREPEND

String Used to separate classnames in the dependency file

private Map<String, Set<File>>
classpathDependencies

A map which gives the list of jars and classes from the classpath that a class depends upon

private boolean
closure

indicates that the dependency relationships should be extended beyond direct dependencies to include all classes.

private Path
dependClasspath

The classpath to look for additional dependencies

private Path
destPath

The path where compiled class files exist.

private boolean
dump

Flag which controls whether the reversed dependencies should be dumped to the log

private static final int
private Map<String, String>
outOfDateClasses

The list of classes which are out of date.

private Path
srcPath

The path where source files exist

private boolean
warnOnRmiStubs

flag to enable warning if we encounter RMI stubs

Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
fileset

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
addClassFiles(List<Depend.ClassFileInfo>
a list of ClassFileInfo objects for all the files in the directory tree
classFileList
,
File
the directory tree to be searched, recursively, for class files
dir
,
File
the root of the source tree. This is used to determine the absolute class name from the relative position in the source tree
root
)

Add the list of class files from the given directory to the class file vector, including any subdirectories.

public Path

Returns:

A path object to be configured by Ant
createClasspath
()

Adds a classpath to be used for this dependency check.

private int

Returns:

the number of class files removed
deleteAffectedFiles
(String
the name of the class whose dependent classes will be deleted
className
)

Delete all the class files of classes which depend on the given class

private int

Returns:

the number of files deleted.
deleteAllAffectedFiles
()

Delete all the class files which are out of date, by way of their dependency on a class which is out of date

private void
determineDependencies()

Determine the dependencies between classes.

private void
private Stream<File>
private void
dumpDependencies()

Dump the dependency information loaded from the classes to the Ant log

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Does the work.
private File
findSourceFile(String
the classname in slash format.
classname
,
File
if not null, a file already known to exist (saves call to .exists())
sourceFileKnownToExist
)

Find the source file for a given class

private Path
getCheckClassPath()

Get the classpath for dependency checking.

private List<Depend.ClassFileInfo>

Returns:

a vector containing the classes to analyse.
getClassFiles
()

Get the list of class files we are going to analyse.

public Path

Returns:

the current dependency classpath
getClasspath
()

Gets the classpath to be used for this dependency check.

private boolean

Returns:

whether the class affectedClass is a RMI stub
isRmiStub
(String
class being tested
affectedClass
,
String
possible origin of the RMI stub
className
)

test for being an RMI stub

private boolean
isStub(String affectedClass, String baseClass, String suffix)

private Map<String, List<String>>

Returns:

a collection of class dependencies
readCachedDependencies
(File depFile)

Read the dependencies from cache file

protected void
scanDir(File
the source directory
srcDir
,
String[]
the names of the files in the source dir which are to be checked.
files
)

Scans the directory looking for source files that are newer than their class files.

public void
setCache(File
the dependency cache file
cache
)

Sets the dependency cache file.

public void
setClasspath(Path
the classpath to be used when checking for dependencies on elements in the classpath
classpath
)

Set the classpath to be used for this dependency check.

public void
setClasspathRef(Reference
a reference to a path object to be used as the depend classpath
r
)

Adds a reference to a classpath defined elsewhere.

public void
setClosure(boolean
indicate if dependency closure is required.
closure
)

If true, transitive dependencies are followed until the closure of the dependency set if reached.

public void
setDestDir(Path
the destination areas where build files are written
destPath
)

Set the destination directory where the compiled Java files exist.

public void
setDump(boolean
set to true to dump dependency information to the log
dump
)

If true, the dependency information will be written to the debug level log.

public void
setSrcdir(Path
the source path
srcPath
)

Set the directories path to find the Java source files.

public void
setWarnOnRmiStubs(boolean
if true set dependency issues to appear at warning level.
warnOnRmiStubs
)

Flag to set to true if you want dependency issues with RMI stubs to appear at warning level.

private void
warnOutOfDateButNotDeleted(Depend.ClassFileInfo
info about the affected class
affectedClassInfo
,
String
the name of the affected .class file
affectedClass
,
String
the file that is triggering the out of dateness
className
)

warn when a class is out of date, but not deleted as its source is unknown.

private void
writeCachedDependencies(Map<String, List<String>>
the map of dependencies to be written out.
dependencyMap
)

Write the dependencies to cache file

Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
addaddAndaddContainsaddContainsRegexpaddCustomaddDateaddDependaddDepthaddDifferentaddFilenameaddMajorityaddModifiedaddNoneaddNotaddOraddPresentaddSelectoraddSizeaddTypeappendSelectorcreateExcludecreateExcludesFilecreateIncludecreateIncludesFilecreatePatternSetgetDirectoryScannergetImplicitFileSetgetSelectorshasSelectorsselectorCountselectorElementssetCaseSensitivesetDefaultexcludessetExcludessetExcludesfilesetFollowSymlinkssetIncludessetIncludesfilesetProjectXsetIgnoreXsetItems

Field Detail

affectedClassMapback to summary
private Map<String, Map<String, Depend.ClassFileInfo>> affectedClassMap

A map which gives for every class a list of the class which it affects.

cacheback to summary
private File cache

The directory which contains the dependency cache.

CACHE_FILE_NAMEback to summary
private static final String CACHE_FILE_NAME

constants used with the cache file

classFileInfoMapback to summary
private Map<String, Depend.ClassFileInfo> classFileInfoMap

A map which gives information about a class

CLASSNAME_PREPENDback to summary
private static final String CLASSNAME_PREPEND

String Used to separate classnames in the dependency file

classpathDependenciesback to summary
private Map<String, Set<File>> classpathDependencies

A map which gives the list of jars and classes from the classpath that a class depends upon

closureback to summary
private boolean closure

indicates that the dependency relationships should be extended beyond direct dependencies to include all classes. So if A directly affects B and B directly affects C, then A indirectly affects C.

dependClasspathback to summary
private Path dependClasspath

The classpath to look for additional dependencies

destPathback to summary
private Path destPath

The path where compiled class files exist.

dumpback to summary
private boolean dump

Flag which controls whether the reversed dependencies should be dumped to the log

ONE_SECONDback to summary
private static final int ONE_SECOND
outOfDateClassesback to summary
private Map<String, String> outOfDateClasses

The list of classes which are out of date.

srcPathback to summary
private Path srcPath

The path where source files exist

warnOnRmiStubsback to summary
private boolean warnOnRmiStubs

flag to enable warning if we encounter RMI stubs

Constructor Detail

Dependback to summary
public Depend()

Method Detail

addClassFilesback to summary
private void addClassFiles(List<Depend.ClassFileInfo> classFileList, File dir, File root)

Add the list of class files from the given directory to the class file vector, including any subdirectories.

Parameters
classFileList:List<Depend.ClassFileInfo>

a list of ClassFileInfo objects for all the files in the directory tree

dir:File

the directory tree to be searched, recursively, for class files

root:File

the root of the source tree. This is used to determine the absolute class name from the relative position in the source tree

createClasspathback to summary
public Path createClasspath()

Adds a classpath to be used for this dependency check.

Returns:Path

A path object to be configured by Ant

deleteAffectedFilesback to summary
private int deleteAffectedFiles(String className)

Delete all the class files of classes which depend on the given class

Parameters
className:String

the name of the class whose dependent classes will be deleted

Returns:int

the number of class files removed

deleteAllAffectedFilesback to summary
private int deleteAllAffectedFiles()

Delete all the class files which are out of date, by way of their dependency on a class which is out of date

Returns:int

the number of files deleted.

determineDependenciesback to summary
private void determineDependencies() throws IOException

Determine the dependencies between classes. Class dependencies are determined by examining the class references in a class file to other classes. This method sets up the following fields

  • affectedClassMap - the list of classes each class affects
  • classFileInfoMap - information about each class
  • classpathDependencies - the list of jars and classes from the classpath that each class depends upon.
If required, the dependencies are written to the cache.
Exceptions
IOException:
if either the dependencies cache or the class files cannot be read or written
determineOutOfDateClassesback to summary
private void determineOutOfDateClasses()
directoriesback to summary
private Stream<File> directories(ResourceCollection rc)
dumpDependenciesback to summary
private void dumpDependencies()

Dump the dependency information loaded from the classes to the Ant log

executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Does the work.

Annotations
@Override
Exceptions
BuildException:
Thrown in case of an unrecoverable error.
findSourceFileback to summary
private File findSourceFile(String classname, File sourceFileKnownToExist)

Find the source file for a given class

Parameters
classname:String

the classname in slash format.

sourceFileKnownToExist:File

if not null, a file already known to exist (saves call to .exists())

getCheckClassPathback to summary
private Path getCheckClassPath()

Get the classpath for dependency checking. This method removes the dest dirs if it is given from the dependency classpath

getClassFilesback to summary
private List<Depend.ClassFileInfo> getClassFiles()

Get the list of class files we are going to analyse.

Returns:List<Depend.ClassFileInfo>

a vector containing the classes to analyse.

getClasspathback to summary
public Path getClasspath()

Gets the classpath to be used for this dependency check.

Returns:Path

the current dependency classpath

isRmiStubback to summary
private boolean isRmiStub(String affectedClass, String className)

test for being an RMI stub

Parameters
affectedClass:String

class being tested

className:String

possible origin of the RMI stub

Returns:boolean

whether the class affectedClass is a RMI stub

isStubback to summary
private boolean isStub(String affectedClass, String baseClass, String suffix)
readCachedDependenciesback to summary
private Map<String, List<String>> readCachedDependencies(File depFile) throws IOException

Read the dependencies from cache file

Returns:Map<String, List<String>>

a collection of class dependencies

Exceptions
IOException:
if the dependency file cannot be read
scanDirback to summary
protected void scanDir(File srcDir, String[] files)

Scans the directory looking for source files that are newer than their class files. The results are returned in the class variable compileList

Parameters
srcDir:File

the source directory

files:String[]

the names of the files in the source dir which are to be checked.

setCacheback to summary
public void setCache(File cache)

Sets the dependency cache file.

Parameters
cache:File

the dependency cache file

setClasspathback to summary
public void setClasspath(Path classpath)

Set the classpath to be used for this dependency check.

Parameters
classpath:Path

the classpath to be used when checking for dependencies on elements in the classpath

setClasspathRefback to summary
public void setClasspathRef(Reference r)

Adds a reference to a classpath defined elsewhere.

Parameters
r:Reference

a reference to a path object to be used as the depend classpath

setClosureback to summary
public void setClosure(boolean closure)

If true, transitive dependencies are followed until the closure of the dependency set if reached. When not set, the depend task will only follow direct dependencies between classes.

Parameters
closure:boolean

indicate if dependency closure is required.

setDestDirback to summary
public void setDestDir(Path destPath)

Set the destination directory where the compiled Java files exist.

Parameters
destPath:Path

the destination areas where build files are written

setDumpback to summary
public void setDump(boolean dump)

If true, the dependency information will be written to the debug level log.

Parameters
dump:boolean

set to true to dump dependency information to the log

setSrcdirback to summary
public void setSrcdir(Path srcPath)

Set the directories path to find the Java source files.

Parameters
srcPath:Path

the source path

setWarnOnRmiStubsback to summary
public void setWarnOnRmiStubs(boolean warnOnRmiStubs)

Flag to set to true if you want dependency issues with RMI stubs to appear at warning level.

Parameters
warnOnRmiStubs:boolean

if true set dependency issues to appear at warning level.

Since
Ant1.7
warnOutOfDateButNotDeletedback to summary
private void warnOutOfDateButNotDeleted(Depend.ClassFileInfo affectedClassInfo, String affectedClass, String className)

warn when a class is out of date, but not deleted as its source is unknown. MSG_WARN is the normal level, but we downgrade to MSG_VERBOSE for RMI files if is false

Parameters
affectedClassInfo:Depend.ClassFileInfo

info about the affected class

affectedClass:String

the name of the affected .class file

className:String

the file that is triggering the out of dateness

writeCachedDependenciesback to summary
private void writeCachedDependencies(Map<String, List<String>> dependencyMap) throws IOException

Write the dependencies to cache file

Parameters
dependencyMap:Map<String, List<String>>

the map of dependencies to be written out.

Exceptions
IOException:
if the dependency file cannot be written out.
org.apache.tools.ant.taskdefs.optional.depend back to summary

private Class Depend.ClassFileInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.tools.ant.taskdefs.optional.depend.Depend.ClassFileInfo

A class (struct) user to manage information about a class

Field Summary

Modifier and TypeField and Description
private File
absoluteFile

The file where the class file is stored in the file system

private String
className

The Java class name of this class

private boolean
isUserWarned

if user has been warned about this file not having a source file

private File
sourceFile

The source File containing this class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

absoluteFileback to summary
private File absoluteFile

The file where the class file is stored in the file system

classNameback to summary
private String className

The Java class name of this class

isUserWarnedback to summary
private boolean isUserWarned

if user has been warned about this file not having a source file

sourceFileback to summary
private File sourceFile

The source File containing this class

Constructor Detail

ClassFileInfoback to summary
private ClassFileInfo()