1. /*
  2. * Copyright 2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.util.depend;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.util.Enumeration;
  21. import org.apache.tools.ant.types.Path;
  22. /**
  23. * A dependency analyzer analyzes dependencies between Java classes to
  24. * determine the minimal set of classes which are required by a set of
  25. * "root" classes. Different implementations of this interface can
  26. * use different strategies and libraries to determine the required set. For
  27. * example, some analyzers will use class files while others might use
  28. * source files. Analyzer specific configuration is catered for through a
  29. * generic configure method
  30. *
  31. */
  32. public interface DependencyAnalyzer {
  33. /**
  34. * Add a source path to the source path used by this analyzer. The
  35. * elements in the given path contain the source files for the classes
  36. * being analyzed. Not all analyzers will use this information.
  37. *
  38. * @param sourcePath The Path instance specifying the source path
  39. * elements.
  40. */
  41. void addSourcePath(Path sourcePath);
  42. /**
  43. * Add a classpath to the classpath being used by the analyzer. The
  44. * classpath contains the binary classfiles for the classes being
  45. * analyzed The elements may either be the directories or jar files.Not
  46. * all analyzers will use this information.
  47. *
  48. * @param classpath the Path instance specifying the classpath elements
  49. */
  50. void addClassPath(Path classpath);
  51. /**
  52. * Add a root class. The root classes are used to drive the
  53. * determination of dependency information. The analyzer will start at
  54. * the root classes and add dependencies from there.
  55. *
  56. * @param classname the name of the class in Java dot notation.
  57. */
  58. void addRootClass(String classname);
  59. /**
  60. * Get the list of files in the file system upon which the root classes
  61. * depend. The files will be either the classfiles or jar files upon
  62. * which the root classes depend.
  63. *
  64. * @return an enumeration of File instances.
  65. */
  66. Enumeration getFileDependencies();
  67. /**
  68. * Get the list of classes upon which root classes depend. This is a
  69. * list of Java classnames in dot notation.
  70. *
  71. * @return an enumeration of Strings, each being the name of a Java
  72. * class in dot notation.
  73. */
  74. Enumeration getClassDependencies();
  75. /**
  76. * Reset the dependency list. This will reset the determined
  77. * dependencies and the also list of root classes.
  78. */
  79. void reset();
  80. /**
  81. * Configure an aspect of the analyzer. The set of aspects that are
  82. * supported is specific to each analyzer instance.
  83. *
  84. * @param name the name of the aspect being configured
  85. * @param info the configuration information.
  86. */
  87. void config(String name, Object info);
  88. /**
  89. * Set the closure flag. If this flag is true the analyzer will traverse
  90. * all class relationships until it has collected the entire set of
  91. * direct and indirect dependencies
  92. *
  93. * @param closure true if dependencies should be traversed to determine
  94. * indirect dependencies.
  95. */
  96. void setClosure(boolean closure);
  97. /**
  98. * Get the file that contains the class definition
  99. *
  100. * @param classname the name of the required class
  101. * @return the file instance, zip or class, containing the
  102. * class or null if the class could not be found.
  103. * @exception IOException if the files in the classpath cannot be read.
  104. */
  105. File getClassContainer(String classname) throws IOException;
  106. /**
  107. * Get the file that contains the class source.
  108. *
  109. * @param classname the name of the required class
  110. * @return the file instance, zip or java, containing the
  111. * source or null if the source for the class could not be found.
  112. * @exception IOException if the files in the sourcepath cannot be read.
  113. */
  114. File getSourceContainer(String classname) throws IOException;
  115. }