1 18 package org.apache.tools.ant.types.optional.depend; 19 20 import java.io.File ; 21 import java.util.Enumeration ; 22 import java.util.Hashtable ; 23 import java.util.Vector ; 24 import org.apache.tools.ant.BuildException; 25 import org.apache.tools.ant.DirectoryScanner; 26 import org.apache.tools.ant.types.Path; 27 import org.apache.tools.ant.util.depend.DependencyAnalyzer; 28 29 30 33 public class DependScanner extends DirectoryScanner { 34 37 public static final String DEFAULT_ANALYZER_CLASS 38 = "org.apache.tools.ant.util.depend.bcel.FullAnalyzer"; 39 40 43 private Vector rootClasses; 44 45 48 private Vector included; 49 50 55 private DirectoryScanner parentScanner; 56 57 64 public DependScanner(DirectoryScanner parentScanner) { 65 this.parentScanner = parentScanner; 66 } 67 68 73 public synchronized void setRootClasses(Vector rootClasses) { 74 this.rootClasses = rootClasses; 75 } 76 77 82 public String [] getIncludedFiles() { 83 String [] files = new String [getIncludedFilesCount()]; 84 for (int i = 0; i < files.length; i++) { 85 files[i] = (String ) included.elementAt(i); 86 } 87 return files; 88 } 89 90 91 public synchronized int getIncludedFilesCount() { 92 if (included == null) { 93 throw new IllegalStateException (); 94 } 95 return included.size(); 96 } 97 98 103 public synchronized void scan() throws IllegalStateException { 104 included = new Vector (); 105 String analyzerClassName = DEFAULT_ANALYZER_CLASS; 106 DependencyAnalyzer analyzer = null; 107 try { 108 Class analyzerClass = Class.forName(analyzerClassName); 109 analyzer = (DependencyAnalyzer) analyzerClass.newInstance(); 110 } catch (Exception e) { 111 throw new BuildException("Unable to load dependency analyzer: " 112 + analyzerClassName, e); 113 } 114 analyzer.addClassPath(new Path(null, basedir.getPath())); 115 116 for (Enumeration e = rootClasses.elements(); e.hasMoreElements();) { 117 String rootClass = (String ) e.nextElement(); 118 analyzer.addRootClass(rootClass); 119 } 120 Enumeration e = analyzer.getClassDependencies(); 121 122 String [] parentFiles = parentScanner.getIncludedFiles(); 123 Hashtable parentSet = new Hashtable (); 124 for (int i = 0; i < parentFiles.length; ++i) { 125 parentSet.put(parentFiles[i], parentFiles[i]); 126 } 127 while (e.hasMoreElements()) { 128 String classname = (String ) e.nextElement(); 129 String filename = classname.replace('.', File.separatorChar); 130 filename = filename + ".class"; 131 File depFile = new File (basedir, filename); 132 if (depFile.exists() && parentSet.containsKey(filename)) { 133 included.addElement(filename); 135 } 136 } 137 } 138 139 142 public void addDefaultExcludes() { 143 } 144 145 148 149 public String [] getExcludedDirectories() { 150 return null; 151 } 152 153 156 157 public String [] getExcludedFiles() { 158 return null; 159 } 160 161 164 165 public String [] getIncludedDirectories() { 166 return new String [0]; 167 } 168 169 172 173 public int getIncludedDirsCount() { 174 return 0; 175 } 176 177 180 181 public String [] getNotIncludedDirectories() { 182 return null; 183 } 184 185 188 189 public String [] getNotIncludedFiles() { 190 return null; 191 } 192 193 196 197 public void setExcludes(String [] excludes) { 198 } 199 200 203 204 public void setIncludes(String [] includes) { 205 } 206 207 210 211 public void setCaseSensitive(boolean isCaseSensitive) { 212 } 213 } 214 | Popular Tags |