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 org.xml.sax.*; 42 43 import com.jeantessier.dependency.*; 44 45 public class DependencyClosure extends GraphTask { 46 private String startIncludes = "//"; 47 private String startExcludes = ""; 48 private String packageStartIncludes = ""; 49 private String packageStartExcludes = ""; 50 private String classStartIncludes = ""; 51 private String classStartExcludes = ""; 52 private String featureStartIncludes = ""; 53 private String featureStartExcludes = ""; 54 private String stopIncludes = ""; 55 private String stopExcludes = ""; 56 private String packageStopIncludes = ""; 57 private String packageStopExcludes = ""; 58 private String classStopIncludes = ""; 59 private String classStopExcludes = ""; 60 private String featureStopIncludes = ""; 61 private String featureStopExcludes = ""; 62 63 private String maximumInboundDepth = ""; 64 private String maximumOutboundDepth = ""; 65 private boolean xml = false; 66 private String encoding = XMLPrinter.DEFAULT_ENCODING; 67 private String dtdPrefix = XMLPrinter.DEFAULT_DTD_PREFIX; 68 private String indentText; 69 70 public String getStartincludes() { 71 return startIncludes; 72 } 73 74 public void setStartincludes(String startIncludes) { 75 this.startIncludes = startIncludes; 76 } 77 78 public String getStartexcludes() { 79 return startExcludes; 80 } 81 82 public void setStartexcludes(String startExcludes) { 83 this.startExcludes = startExcludes; 84 } 85 86 public String getPackagestartincludes() { 87 return packageStartIncludes; 88 } 89 90 public void setPackagestartincludes(String packageStartIncludes) { 91 this.packageStartIncludes = packageStartIncludes; 92 } 93 94 public String getPackagestartexcludes() { 95 return packageStartExcludes; 96 } 97 98 public void setPackagestartexcludes(String packageStartExcludes) { 99 this.packageStartExcludes = packageStartExcludes; 100 } 101 102 public String getClassstartincludes() { 103 return classStartIncludes; 104 } 105 106 public void setClassstartincludes(String classStartIncludes) { 107 this.classStartIncludes = classStartIncludes; 108 } 109 110 public String getClassstartexcludes() { 111 return classStartExcludes; 112 } 113 114 public void setClassstartexcludes(String classStartExcludes) { 115 this.classStartExcludes = classStartExcludes; 116 } 117 118 public String getFeaturestartincludes() { 119 return featureStartIncludes; 120 } 121 122 public void setFeaturestartincludes(String featureStartIncludes) { 123 this.featureStartIncludes = featureStartIncludes; 124 } 125 126 public String getFeaturestartexcludes() { 127 return featureStartExcludes; 128 } 129 130 public void setFeaturestartexcludes(String featureStartExcludes) { 131 this.featureStartExcludes = featureStartExcludes; 132 } 133 134 public String getStopincludes() { 135 return stopIncludes; 136 } 137 138 public void setStopincludes(String stopIncludes) { 139 this.stopIncludes = stopIncludes; 140 } 141 142 public String getStopexcludes() { 143 return stopExcludes; 144 } 145 146 public void setStopexcludes(String stopExcludes) { 147 this.stopExcludes = stopExcludes; 148 } 149 150 public String getPackagestopincludes() { 151 return packageStopIncludes; 152 } 153 154 public void setPackagestopincludes(String packageStopIncludes) { 155 this.packageStopIncludes = packageStopIncludes; 156 } 157 158 public String getPackagestopexcludes() { 159 return packageStopExcludes; 160 } 161 162 public void setPackagestopexcludes(String packageStopExcludes) { 163 this.packageStopExcludes = packageStopExcludes; 164 } 165 166 public String getClassstopincludes() { 167 return classStopIncludes; 168 } 169 170 public void setClassstopincludes(String classStopIncludes) { 171 this.classStopIncludes = classStopIncludes; 172 } 173 174 public String getClassstopexcludes() { 175 return classStopExcludes; 176 } 177 178 public void setClassstopexcludes(String classStopExcludes) { 179 this.classStopExcludes = classStopExcludes; 180 } 181 182 public String getFeaturestopincludes() { 183 return featureStopIncludes; 184 } 185 186 public void setFeaturestopincludes(String featureStopIncludes) { 187 this.featureStopIncludes = featureStopIncludes; 188 } 189 190 public String getFeaturestopexcludes() { 191 return featureStopExcludes; 192 } 193 194 public void setFeaturestopexcludes(String featureStopExcludes) { 195 this.featureStopExcludes = featureStopExcludes; 196 } 197 198 public String getMaximuminbounddepth() { 199 return maximumInboundDepth; 200 } 201 202 public void setMaximuminbounddepth(String maximumInboundDepth) { 203 this.maximumInboundDepth = maximumInboundDepth; 204 } 205 206 public String getMaximumoutbounddepth() { 207 return maximumOutboundDepth; 208 } 209 210 public void setMaximumoutbounddepth(String maximumOutboundDepth) { 211 this.maximumOutboundDepth = maximumOutboundDepth; 212 } 213 214 public boolean getXml() { 215 return xml; 216 } 217 218 public void setXml(boolean xml) { 219 this.xml = xml; 220 } 221 222 public String getEncoding() { 223 return encoding; 224 } 225 226 public void setEncoding(String encoding) { 227 this.encoding = encoding; 228 } 229 230 public String getDtdprefix() { 231 return dtdPrefix; 232 } 233 234 public void setDtdprefix(String dtdPrefix) { 235 this.dtdPrefix = dtdPrefix; 236 } 237 238 public String getIndenttext() { 239 return indentText; 240 } 241 242 public void setIntenttext(String indentText) { 243 this.indentText = indentText; 244 } 245 246 public void execute() throws BuildException { 247 validateParameters(); 249 250 VerboseListener verboseListener = new VerboseListener(this); 251 252 try { 253 NodeFactory factory = new NodeFactory(); 254 255 String [] filenames = getSrc().list(); 256 for (int i=0; i<filenames.length; i++) { 257 log("Reading graph from " + filenames[i]); 258 259 if (filenames[i].endsWith(".xml")) { 260 NodeLoader loader = new NodeLoader(factory, getValidate()); 261 loader.addDependencyListener(verboseListener); 262 loader.load(filenames[i]); 263 } 264 } 265 266 TransitiveClosure selector = new TransitiveClosure(getStartCriteria(), getStopCriteria()); 267 268 try { 269 if (getMaximuminbounddepth() != null) { 270 selector.setMaximumInboundDepth(Long.parseLong(getMaximuminbounddepth())); 271 } 272 } catch (NumberFormatException ex) { 273 selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 274 } 275 276 try { 277 if (getMaximumoutbounddepth() != null) { 278 selector.setMaximumOutboundDepth(Long.parseLong(getMaximumoutbounddepth())); 279 } 280 } catch (NumberFormatException ex) { 281 selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 282 } 283 284 selector.traverseNodes(factory.getPackages().values()); 285 286 log("Saving dependency graph to " + getDestfile().getAbsolutePath()); 287 288 PrintWriter out = new PrintWriter(new FileWriter(getDestfile())); 289 290 Printer printer; 291 if (getXml()) { 292 printer = new XMLPrinter(out, getEncoding(), getDtdprefix()); 293 } else { 294 printer = new TextPrinter(out); 295 } 296 297 if (getIndenttext() != null) { 298 printer.setIndentText(getIndenttext()); 299 } 300 301 printer.traverseNodes(selector.getFactory().getPackages().values()); 302 303 out.close(); 304 } catch (SAXException ex) { 305 throw new BuildException(ex); 306 } catch (IOException ex) { 307 throw new BuildException(ex); 308 } 309 } 310 311 private SelectionCriteria getStartCriteria() throws BuildException { 312 RegularExpressionSelectionCriteria result = new RegularExpressionSelectionCriteria(); 313 314 result.setGlobalIncludes(getStartincludes()); 315 result.setGlobalExcludes(getStartexcludes()); 316 result.setPackageIncludes(getPackagestartincludes()); 317 result.setPackageExcludes(getPackagestartexcludes()); 318 result.setClassIncludes(getClassstartincludes()); 319 result.setClassExcludes(getClassstartexcludes()); 320 result.setFeatureIncludes(getFeaturestartincludes()); 321 result.setFeatureExcludes(getFeaturestartexcludes()); 322 323 return result; 324 } 325 326 private SelectionCriteria getStopCriteria() throws BuildException { 327 RegularExpressionSelectionCriteria result = new RegularExpressionSelectionCriteria(); 328 329 result.setGlobalIncludes(getStopincludes()); 330 result.setGlobalExcludes(getStopexcludes()); 331 result.setPackageIncludes(getPackagestopincludes()); 332 result.setPackageExcludes(getPackagestopexcludes()); 333 result.setClassIncludes(getClassstopincludes()); 334 result.setClassExcludes(getClassstopexcludes()); 335 result.setFeatureIncludes(getFeaturestopincludes()); 336 result.setFeatureExcludes(getFeaturestopexcludes()); 337 338 return result; 339 } 340 } 341 | Popular Tags |