1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.dependencyfinder.ant; |
34 |
| |
35 |
| import java.io.*; |
36 |
| |
37 |
| import javax.xml.parsers.*; |
38 |
| |
39 |
| import org.apache.tools.ant.*; |
40 |
| |
41 |
| import org.xml.sax.*; |
42 |
| |
43 |
| import com.jeantessier.dependency.*; |
44 |
| |
45 |
| public class DependencyMetrics extends GraphTask { |
46 |
| private String scopeIncludes = "//"; |
47 |
| private String scopeExcludes = ""; |
48 |
| private boolean packageScope; |
49 |
| private String packageScopeIncludes = ""; |
50 |
| private String packageScopeExcludes = ""; |
51 |
| private boolean classScope; |
52 |
| private String classScopeIncludes = ""; |
53 |
| private String classScopeExcludes = ""; |
54 |
| private boolean featureScope; |
55 |
| private String featureScopeIncludes = ""; |
56 |
| private String featureScopeExcludes = ""; |
57 |
| private String filterIncludes = "//"; |
58 |
| private String filterExcludes = ""; |
59 |
| private boolean packageFilter; |
60 |
| private String packageFilterIncludes = ""; |
61 |
| private String packageFilterExcludes = ""; |
62 |
| private boolean classFilter; |
63 |
| private String classFilterIncludes = ""; |
64 |
| private String classFilterExcludes = ""; |
65 |
| private boolean featureFilter; |
66 |
| private String featureFilterIncludes = ""; |
67 |
| private String featureFilterExcludes = ""; |
68 |
| |
69 |
| private boolean list = false; |
70 |
| private boolean chartClassesPerPackage = false; |
71 |
| private boolean chartFeaturesPerClass = false; |
72 |
| private boolean chartInboundsPerPackage = false; |
73 |
| private boolean chartOutboundsPerPackage = false; |
74 |
| private boolean chartInboundsPerClass = false; |
75 |
| private boolean chartOutboundsPerClass = false; |
76 |
| private boolean chartInboundsPerFeature = false; |
77 |
| private boolean chartOutboundsPerFeature = false; |
78 |
| |
79 |
0
| public String getScopeincludes() {
|
80 |
0
| return scopeIncludes;
|
81 |
| } |
82 |
| |
83 |
0
| public void setScopeincludes(String scopeIncludes) {
|
84 |
0
| this.scopeIncludes = scopeIncludes;
|
85 |
| } |
86 |
| |
87 |
0
| public String getScopeexcludes() {
|
88 |
0
| return scopeExcludes;
|
89 |
| } |
90 |
| |
91 |
0
| public void setScopeexcludes(String scopeExcludes) {
|
92 |
0
| this.scopeExcludes = scopeExcludes;
|
93 |
| } |
94 |
| |
95 |
0
| public boolean getPackagescope() {
|
96 |
0
| return packageScope;
|
97 |
| } |
98 |
| |
99 |
0
| public void setPackagescope(boolean packageScope) {
|
100 |
0
| this.packageScope = packageScope;
|
101 |
| } |
102 |
| |
103 |
0
| public String getPackagescopeincludes() {
|
104 |
0
| return packageScopeIncludes;
|
105 |
| } |
106 |
| |
107 |
0
| public void setPackagescopeincludes(String packageScopeIncludes) {
|
108 |
0
| this.packageScopeIncludes = packageScopeIncludes;
|
109 |
| } |
110 |
| |
111 |
0
| public String getPackagescopeexcludes() {
|
112 |
0
| return packageScopeExcludes;
|
113 |
| } |
114 |
| |
115 |
0
| public void setPackagescopeexcludes(String packageScopeExcludes) {
|
116 |
0
| this.packageScopeExcludes = packageScopeExcludes;
|
117 |
| } |
118 |
| |
119 |
0
| public boolean getClassscope() {
|
120 |
0
| return classScope;
|
121 |
| } |
122 |
| |
123 |
0
| public void setClassscope(boolean classScope) {
|
124 |
0
| this.classScope = classScope;
|
125 |
| } |
126 |
| |
127 |
0
| public String getClassscopeincludes() {
|
128 |
0
| return classScopeIncludes;
|
129 |
| } |
130 |
| |
131 |
0
| public void setClassscopeincludes(String classScopeIncludes) {
|
132 |
0
| this.classScopeIncludes = classScopeIncludes;
|
133 |
| } |
134 |
| |
135 |
0
| public String getClassscopeexcludes() {
|
136 |
0
| return classScopeExcludes;
|
137 |
| } |
138 |
| |
139 |
0
| public void setClassscopeexcludes(String classScopeExcludes) {
|
140 |
0
| this.classScopeExcludes = classScopeExcludes;
|
141 |
| } |
142 |
| |
143 |
0
| public boolean getFeaturescope() {
|
144 |
0
| return featureScope;
|
145 |
| } |
146 |
| |
147 |
0
| public void setFeaturescope(boolean featureScope) {
|
148 |
0
| this.featureScope = featureScope;
|
149 |
| } |
150 |
| |
151 |
0
| public String getFeaturescopeincludes() {
|
152 |
0
| return featureScopeIncludes;
|
153 |
| } |
154 |
| |
155 |
0
| public void setFeaturescopeincludes(String featureScopeIncludes) {
|
156 |
0
| this.featureScopeIncludes = featureScopeIncludes;
|
157 |
| } |
158 |
| |
159 |
0
| public String getFeaturescopeexcludes() {
|
160 |
0
| return featureScopeExcludes;
|
161 |
| } |
162 |
| |
163 |
0
| public void setFeaturescopeexcludes(String featureScopeExcludes) {
|
164 |
0
| this.featureScopeExcludes = featureScopeExcludes;
|
165 |
| } |
166 |
| |
167 |
0
| public String getFilterincludes() {
|
168 |
0
| return filterIncludes;
|
169 |
| } |
170 |
| |
171 |
0
| public void setFilterincludes(String filterIncludes) {
|
172 |
0
| this.filterIncludes = filterIncludes;
|
173 |
| } |
174 |
| |
175 |
0
| public String getFilterexcludes() {
|
176 |
0
| return filterExcludes;
|
177 |
| } |
178 |
| |
179 |
0
| public void setFilterexcludes(String filterExcludes) {
|
180 |
0
| this.filterExcludes = filterExcludes;
|
181 |
| } |
182 |
| |
183 |
0
| public boolean getPackagefilter() {
|
184 |
0
| return packageFilter;
|
185 |
| } |
186 |
| |
187 |
0
| public void setPackagefilter(boolean packageFilter) {
|
188 |
0
| this.packageFilter = packageFilter;
|
189 |
| } |
190 |
| |
191 |
0
| public String getPackagefilterincludes() {
|
192 |
0
| return packageFilterIncludes;
|
193 |
| } |
194 |
| |
195 |
0
| public void setPackagefilterincludes(String packageFilterIncludes) {
|
196 |
0
| this.packageFilterIncludes = packageFilterIncludes;
|
197 |
| } |
198 |
| |
199 |
0
| public String getPackagefilterexcludes() {
|
200 |
0
| return packageFilterExcludes;
|
201 |
| } |
202 |
| |
203 |
0
| public void setPackagefilterexcludes(String packageFilterExcludes) {
|
204 |
0
| this.packageFilterExcludes = packageFilterExcludes;
|
205 |
| } |
206 |
| |
207 |
0
| public boolean getClassfilter() {
|
208 |
0
| return classFilter;
|
209 |
| } |
210 |
| |
211 |
0
| public void setClassfilter(boolean classFilter) {
|
212 |
0
| this.classFilter = classFilter;
|
213 |
| } |
214 |
| |
215 |
0
| public String getClassfilterincludes() {
|
216 |
0
| return classFilterIncludes;
|
217 |
| } |
218 |
| |
219 |
0
| public void setClassfilterincludes(String classFilterIncludes) {
|
220 |
0
| this.classFilterIncludes = classFilterIncludes;
|
221 |
| } |
222 |
| |
223 |
0
| public String getClassfilterexcludes() {
|
224 |
0
| return classFilterExcludes;
|
225 |
| } |
226 |
| |
227 |
0
| public void setClassfilterexcludes(String classFilterExcludes) {
|
228 |
0
| this.classFilterExcludes = classFilterExcludes;
|
229 |
| } |
230 |
| |
231 |
0
| public boolean getFeaturefilter() {
|
232 |
0
| return featureFilter;
|
233 |
| } |
234 |
| |
235 |
0
| public void setFeaturefilter(boolean featureFilter) {
|
236 |
0
| this.featureFilter = featureFilter;
|
237 |
| } |
238 |
| |
239 |
0
| public String getFeaturefilterincludes() {
|
240 |
0
| return featureFilterIncludes;
|
241 |
| } |
242 |
| |
243 |
0
| public void setFeaturefilterincludes(String featureFilterIncludes) {
|
244 |
0
| this.featureFilterIncludes = featureFilterIncludes;
|
245 |
| } |
246 |
| |
247 |
0
| public String getFeaturefilterexcludes() {
|
248 |
0
| return featureFilterExcludes;
|
249 |
| } |
250 |
| |
251 |
0
| public void setFeaturefilterexcludes(String featureFilterExcludes) {
|
252 |
0
| this.featureFilterExcludes = featureFilterExcludes;
|
253 |
| } |
254 |
| |
255 |
0
| public void setP2p(boolean value) {
|
256 |
0
| setPackagescope(value);
|
257 |
0
| setPackagefilter(value);
|
258 |
| } |
259 |
| |
260 |
0
| public void setC2p(boolean value) {
|
261 |
0
| setClassscope(value);
|
262 |
0
| setPackagefilter(value);
|
263 |
| } |
264 |
| |
265 |
0
| public void setC2c(boolean value) {
|
266 |
0
| setClassscope(value);
|
267 |
0
| setClassfilter(value);
|
268 |
| } |
269 |
| |
270 |
0
| public void setF2f(boolean value) {
|
271 |
0
| setFeaturescope(value);
|
272 |
0
| setFeaturefilter(value);
|
273 |
| } |
274 |
| |
275 |
0
| public void setIncludes(String value) {
|
276 |
0
| setScopeincludes(value);
|
277 |
0
| setFilterincludes(value);
|
278 |
| } |
279 |
| |
280 |
0
| public void setExcludes(String value) {
|
281 |
0
| setScopeexcludes(value);
|
282 |
0
| setFilterexcludes(value);
|
283 |
| } |
284 |
| |
285 |
0
| public boolean getList() {
|
286 |
0
| return list;
|
287 |
| } |
288 |
| |
289 |
0
| public void setList(boolean list) {
|
290 |
0
| this.list = list;
|
291 |
| } |
292 |
| |
293 |
0
| public boolean getChartclassesperpackage() {
|
294 |
0
| return chartClassesPerPackage;
|
295 |
| } |
296 |
| |
297 |
0
| public void setChartclassesperpackage(boolean chartClassesPerPackage) {
|
298 |
0
| this.chartClassesPerPackage = chartClassesPerPackage;
|
299 |
| } |
300 |
| |
301 |
0
| public boolean getChartfeaturesperclass() {
|
302 |
0
| return chartFeaturesPerClass;
|
303 |
| } |
304 |
| |
305 |
0
| public void setChartfeaturesperclass(boolean chartFeaturesPerClass) {
|
306 |
0
| this.chartFeaturesPerClass = chartFeaturesPerClass;
|
307 |
| } |
308 |
| |
309 |
0
| public boolean getChartinboundsperpackage() {
|
310 |
0
| return chartInboundsPerPackage;
|
311 |
| } |
312 |
| |
313 |
0
| public void setChartinboundsperpackage(boolean chartInboundsPerPackage) {
|
314 |
0
| this.chartInboundsPerPackage = chartInboundsPerPackage;
|
315 |
| } |
316 |
| |
317 |
0
| public boolean getChartoutboundsperpackage() {
|
318 |
0
| return chartOutboundsPerPackage;
|
319 |
| } |
320 |
| |
321 |
0
| public void setChartoutboundsperpackage(boolean chartOutboundsPerPackage) {
|
322 |
0
| this.chartOutboundsPerPackage = chartOutboundsPerPackage;
|
323 |
| } |
324 |
| |
325 |
0
| public boolean getChartinboundsperclass() {
|
326 |
0
| return chartInboundsPerClass;
|
327 |
| } |
328 |
| |
329 |
0
| public void setChartinboundsperclass(boolean chartInboundsPerClass) {
|
330 |
0
| this.chartInboundsPerClass = chartInboundsPerClass;
|
331 |
| } |
332 |
| |
333 |
0
| public boolean getChartoutboundsperclass() {
|
334 |
0
| return chartOutboundsPerClass;
|
335 |
| } |
336 |
| |
337 |
0
| public void setChartoutboundsperclass(boolean chartOutboundsPerClass) {
|
338 |
0
| this.chartOutboundsPerClass = chartOutboundsPerClass;
|
339 |
| } |
340 |
| |
341 |
0
| public boolean getChartinboundsperfeature() {
|
342 |
0
| return chartInboundsPerFeature;
|
343 |
| } |
344 |
| |
345 |
0
| public void setChartinboundsperfeature(boolean chartInboundsPerFeature) {
|
346 |
0
| this.chartInboundsPerFeature = chartInboundsPerFeature;
|
347 |
| } |
348 |
| |
349 |
0
| public boolean getChartoutboundsperfeature() {
|
350 |
0
| return chartOutboundsPerFeature;
|
351 |
| } |
352 |
| |
353 |
0
| public void setChartoutboundsperfeature(boolean chartOutboundsPerFeature) {
|
354 |
0
| this.chartOutboundsPerFeature = chartOutboundsPerFeature;
|
355 |
| } |
356 |
| |
357 |
0
| public void setChartinbounds(boolean chartInbounds) {
|
358 |
0
| setChartinboundsperpackage(chartInbounds);
|
359 |
0
| setChartinboundsperclass(chartInbounds);
|
360 |
0
| setChartinboundsperfeature(chartInbounds);
|
361 |
| } |
362 |
| |
363 |
0
| public void setChartoutbounds(boolean chartOutbounds) {
|
364 |
0
| setChartoutboundsperpackage(chartOutbounds);
|
365 |
0
| setChartoutboundsperclass(chartOutbounds);
|
366 |
0
| setChartoutboundsperfeature(chartOutbounds);
|
367 |
| } |
368 |
| |
369 |
0
| public void setChartpackages(boolean chartPackages) {
|
370 |
0
| setChartclassesperpackage(chartPackages);
|
371 |
0
| setChartinboundsperpackage(chartPackages);
|
372 |
0
| setChartoutboundsperpackage(chartPackages);
|
373 |
| } |
374 |
| |
375 |
0
| public void setChartclasses(boolean chartClasses) {
|
376 |
0
| setChartfeaturesperclass(chartClasses);
|
377 |
0
| setChartinboundsperclass(chartClasses);
|
378 |
0
| setChartoutboundsperclass(chartClasses);
|
379 |
| } |
380 |
| |
381 |
0
| public void setChartfeatures(boolean chartFeatures) {
|
382 |
0
| setChartinboundsperfeature(chartFeatures);
|
383 |
0
| setChartoutboundsperfeature(chartFeatures);
|
384 |
| } |
385 |
| |
386 |
0
| public void setChartall(boolean chartAll) {
|
387 |
0
| setChartclassesperpackage(chartAll);
|
388 |
0
| setChartfeaturesperclass(chartAll);
|
389 |
0
| setChartinboundsperpackage(chartAll);
|
390 |
0
| setChartoutboundsperpackage(chartAll);
|
391 |
0
| setChartinboundsperclass(chartAll);
|
392 |
0
| setChartoutboundsperclass(chartAll);
|
393 |
0
| setChartinboundsperfeature(chartAll);
|
394 |
0
| setChartoutboundsperfeature(chartAll);
|
395 |
| } |
396 |
| |
397 |
0
| public void execute() throws BuildException {
|
398 |
| |
399 |
0
| validateParameters();
|
400 |
| |
401 |
0
| VerboseListener verboseListener = new VerboseListener(this);
|
402 |
| |
403 |
0
| try {
|
404 |
0
| NodeFactory factory = new NodeFactory();
|
405 |
| |
406 |
0
| for (String filename : getSrc().list()) {
|
407 |
0
| log("Reading graph from " + filename);
|
408 |
| |
409 |
0
| if (filename.endsWith(".xml")) {
|
410 |
0
| NodeLoader loader = new NodeLoader(factory, getValidate());
|
411 |
0
| loader.addDependencyListener(verboseListener);
|
412 |
0
| loader.load(filename);
|
413 |
| } |
414 |
| } |
415 |
| |
416 |
0
| log("Saving metrics report to " + getDestfile().getAbsolutePath());
|
417 |
| |
418 |
0
| PrintWriter out = new PrintWriter(new FileWriter(getDestfile()));
|
419 |
| |
420 |
0
| MetricsReport reporter = new MetricsReport(out);
|
421 |
| |
422 |
0
| reporter.setListingElements(getList());
|
423 |
0
| reporter.setChartingClassesPerPackage(getChartclassesperpackage());
|
424 |
0
| reporter.setChartingFeaturesPerClass(getChartfeaturesperclass());
|
425 |
0
| reporter.setChartingInboundsPerPackage(getChartinboundsperpackage());
|
426 |
0
| reporter.setChartingOutboundsPerPackage(getChartoutboundsperpackage());
|
427 |
0
| reporter.setChartingInboundsPerClass(getChartinboundsperclass());
|
428 |
0
| reporter.setChartingOutboundsPerClass(getChartoutboundsperclass());
|
429 |
0
| reporter.setChartingInboundsPerFeature(getChartinboundsperfeature());
|
430 |
0
| reporter.setChartingOutboundsPerFeature(getChartoutboundsperfeature());
|
431 |
| |
432 |
0
| MetricsGatherer metrics = new MetricsGatherer(getStrategy());
|
433 |
0
| metrics.traverseNodes(factory.getPackages().values());
|
434 |
0
| reporter.process(metrics);
|
435 |
| |
436 |
0
| out.close();
|
437 |
| } catch (SAXException ex) { |
438 |
0
| throw new BuildException(ex);
|
439 |
| } catch (ParserConfigurationException ex) { |
440 |
0
| throw new BuildException(ex);
|
441 |
| } catch (IOException ex) { |
442 |
0
| throw new BuildException(ex);
|
443 |
| } |
444 |
| } |
445 |
| |
446 |
0
| private SelectionCriteria getScopeCriteria() throws BuildException {
|
447 |
0
| RegularExpressionSelectionCriteria result = new RegularExpressionSelectionCriteria();
|
448 |
| |
449 |
0
| if (getPackagescope() || getClassscope() || getFeaturescope()) {
|
450 |
0
| result.setMatchingPackages(getPackagescope());
|
451 |
0
| result.setMatchingClasses(getClassscope());
|
452 |
0
| result.setMatchingFeatures(getFeaturescope());
|
453 |
| } |
454 |
| |
455 |
0
| result.setGlobalIncludes(getScopeincludes());
|
456 |
0
| result.setGlobalExcludes(getScopeexcludes());
|
457 |
0
| result.setPackageIncludes(getPackagescopeincludes());
|
458 |
0
| result.setPackageExcludes(getPackagescopeexcludes());
|
459 |
0
| result.setClassIncludes(getClassscopeincludes());
|
460 |
0
| result.setClassExcludes(getClassscopeexcludes());
|
461 |
0
| result.setFeatureIncludes(getFeaturescopeincludes());
|
462 |
0
| result.setFeatureExcludes(getFeaturescopeexcludes());
|
463 |
| |
464 |
0
| return result;
|
465 |
| } |
466 |
| |
467 |
0
| private SelectionCriteria getFilterCriteria() throws BuildException {
|
468 |
0
| RegularExpressionSelectionCriteria result = new RegularExpressionSelectionCriteria();
|
469 |
| |
470 |
0
| if (getPackagefilter() || getClassfilter() || getFeaturefilter()) {
|
471 |
0
| result.setMatchingPackages(getPackagefilter());
|
472 |
0
| result.setMatchingClasses(getClassfilter());
|
473 |
0
| result.setMatchingFeatures(getFeaturefilter());
|
474 |
| } |
475 |
| |
476 |
0
| result.setGlobalIncludes(getFilterincludes());
|
477 |
0
| result.setGlobalExcludes(getFilterexcludes());
|
478 |
0
| result.setPackageIncludes(getPackagefilterincludes());
|
479 |
0
| result.setPackageExcludes(getPackagefilterexcludes());
|
480 |
0
| result.setClassIncludes(getClassfilterincludes());
|
481 |
0
| result.setClassExcludes(getClassfilterexcludes());
|
482 |
0
| result.setFeatureIncludes(getFeaturefilterincludes());
|
483 |
0
| result.setFeatureExcludes(getFeaturefilterexcludes());
|
484 |
| |
485 |
0
| return result;
|
486 |
| } |
487 |
| |
488 |
0
| private TraversalStrategy getStrategy() throws BuildException {
|
489 |
0
| return new SelectiveTraversalStrategy(getScopeCriteria(), getFilterCriteria());
|
490 |
| } |
491 |
| } |