1 32 33 package com.jeantessier.dependencyfinder.ant; 34 35 import java.io.*; 36 import java.util.*; 37 38 import org.apache.tools.ant.*; 39 import org.apache.tools.ant.types.*; 40 41 import com.jeantessier.classreader.*; 42 import com.jeantessier.dependencyfinder.*; 43 44 public class ListSymbols extends Task { 45 private boolean classNames = false; 46 private boolean fieldNames = false; 47 private boolean methodNames = false; 48 private boolean localNames = false; 49 private File destfile; 50 private Path path; 51 52 public boolean getClassnames() { 53 return classNames; 54 } 55 56 public void setClassnames(boolean classNames) { 57 this.classNames = classNames; 58 } 59 60 public boolean getFieldnames() { 61 return fieldNames; 62 } 63 64 public void setFieldnames(boolean fieldNames) { 65 this.fieldNames = fieldNames; 66 } 67 68 public boolean getMethodnames() { 69 return methodNames; 70 } 71 72 public void setMethodnames(boolean methodNames) { 73 this.methodNames = methodNames; 74 } 75 76 public boolean getLocalnames() { 77 return localNames; 78 } 79 80 public void setLocalnames(boolean localNames) { 81 this.localNames = localNames; 82 } 83 84 public File getDestfile() { 85 return destfile; 86 } 87 88 public void setDestfile(File destfile) { 89 this.destfile = destfile; 90 } 91 92 public Path createPath() { 93 if (path == null) { 94 path = new Path(getProject()); 95 } 96 97 return path; 98 } 99 100 public Path getPath() { 101 return path; 102 } 103 104 public void execute() throws BuildException { 105 107 if (getPath() == null) { 108 throw new BuildException("path must be set!"); 109 } 110 111 if (getDestfile() == null) { 112 throw new BuildException("destfile must be set!"); 113 } 114 115 log("Reading classes from path " + getPath()); 116 117 VerboseListener verboseListener = new VerboseListener(this); 118 119 SymbolGatherer collector = new SymbolGatherer(); 120 121 if (getClassnames() || getFieldnames() || getMethodnames() || getLocalnames()) { 128 collector.setCollectingClassNames(false); 129 collector.setCollectingFieldNames(false); 130 collector.setCollectingMethodNames(false); 131 collector.setCollectingLocalNames(false); 132 } 133 134 if (getClassnames()) { 135 collector.setCollectingClassNames(true); 136 } 137 138 if (getFieldnames()) { 139 collector.setCollectingFieldNames(true); 140 } 141 142 if (getMethodnames()) { 143 collector.setCollectingMethodNames(true); 144 } 145 146 if (getLocalnames()) { 147 collector.setCollectingLocalNames(true); 148 } 149 150 ClassfileLoader loader = new TransientClassfileLoader(); 151 loader.addLoadListener(new LoadListenerVisitorAdapter(collector)); 152 loader.addLoadListener(verboseListener); 153 loader.load(Arrays.asList(getPath().list())); 154 155 log("Saving symbols to " + getDestfile().getAbsolutePath()); 156 157 try { 158 PrintWriter out = new PrintWriter(new FileWriter(getDestfile())); 159 160 Iterator i = collector.getCollection().iterator(); 161 while (i.hasNext()) { 162 out.println(i.next()); 163 } 164 165 out.close(); 166 } catch (IOException ex) { 167 throw new BuildException(ex); 168 } 169 } 170 } 171 | Popular Tags |