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 |
| import java.util.*; |
37 |
| import javax.xml.parsers.*; |
38 |
| |
39 |
| import com.jeantessier.classreader.*; |
40 |
| import com.jeantessier.metrics.*; |
41 |
| import org.apache.tools.ant.*; |
42 |
| import org.apache.tools.ant.types.*; |
43 |
| import org.xml.sax.*; |
44 |
| |
45 |
| public class OOMetrics extends Task { |
46 |
| public static final String DEFAULT_PROJECT_NAME = "Project"; |
47 |
| public static final String DEFAULT_SORT = "name"; |
48 |
| |
49 |
| private String projectName = DEFAULT_PROJECT_NAME; |
50 |
| private File configuration; |
51 |
| private boolean csv = false; |
52 |
| private boolean txt = false; |
53 |
| private boolean xml = false; |
54 |
| private boolean validate = false; |
55 |
| private String encoding = com.jeantessier.metrics.XMLPrinter.DEFAULT_ENCODING; |
56 |
| private String dtdPrefix = com.jeantessier.metrics.XMLPrinter.DEFAULT_DTD_PREFIX; |
57 |
| private String indentText; |
58 |
| private boolean projectMetrics = false; |
59 |
| private boolean groupMetrics = false; |
60 |
| private boolean classMetrics = false; |
61 |
| private boolean methodMetrics = false; |
62 |
| private Path scopeIncludesList; |
63 |
| private Path scopeExcludesList; |
64 |
| private Path filterIncludesList; |
65 |
| private Path filterExcludesList; |
66 |
| private boolean showAllMetrics = false; |
67 |
| private boolean showEmptyMetrics = false; |
68 |
| private boolean showHiddenMeasurements = false; |
69 |
| private String sort = DEFAULT_SORT; |
70 |
| private boolean expand = false; |
71 |
| private boolean reverse = false; |
72 |
| private boolean enableCrossClassMeasurements = false; |
73 |
| private File destprefix; |
74 |
| private Path path; |
75 |
| |
76 |
0
| public String getProjectname() {
|
77 |
0
| return projectName;
|
78 |
| } |
79 |
| |
80 |
0
| public void setProjectname(String projectName) {
|
81 |
0
| this.projectName = projectName;
|
82 |
| } |
83 |
| |
84 |
0
| public File getConfiguration() {
|
85 |
0
| return configuration;
|
86 |
| } |
87 |
| |
88 |
0
| public void setConfiguration(File configuration) {
|
89 |
0
| this.configuration = configuration;
|
90 |
| } |
91 |
| |
92 |
0
| public boolean getCsv() {
|
93 |
0
| return csv;
|
94 |
| } |
95 |
| |
96 |
0
| public void setCsv(boolean csv) {
|
97 |
0
| this.csv = csv;
|
98 |
| } |
99 |
| |
100 |
0
| public boolean getTxt() {
|
101 |
0
| return txt;
|
102 |
| } |
103 |
| |
104 |
0
| public void setTxt(boolean txt) {
|
105 |
0
| this.txt = txt;
|
106 |
| } |
107 |
| |
108 |
0
| public boolean getXml() {
|
109 |
0
| return xml;
|
110 |
| } |
111 |
| |
112 |
0
| public void setXml(boolean xml) {
|
113 |
0
| this.xml = xml;
|
114 |
| } |
115 |
| |
116 |
0
| public boolean getValidate() {
|
117 |
0
| return validate;
|
118 |
| } |
119 |
| |
120 |
0
| public void setValidate(boolean validate) {
|
121 |
0
| this.validate = validate;
|
122 |
| } |
123 |
| |
124 |
0
| public String getEncoding() {
|
125 |
0
| return encoding;
|
126 |
| } |
127 |
| |
128 |
0
| public void setEncoding(String encoding) {
|
129 |
0
| this.encoding = encoding;
|
130 |
| } |
131 |
| |
132 |
0
| public String getDtdprefix() {
|
133 |
0
| return dtdPrefix;
|
134 |
| } |
135 |
| |
136 |
0
| public void setDtdprefix(String dtdPrefix) {
|
137 |
0
| this.dtdPrefix = dtdPrefix;
|
138 |
| } |
139 |
| |
140 |
0
| public String getIndenttext() {
|
141 |
0
| return indentText;
|
142 |
| } |
143 |
| |
144 |
0
| public void setIntenttext(String indentText) {
|
145 |
0
| this.indentText = indentText;
|
146 |
| } |
147 |
| |
148 |
0
| public boolean getProjectmetrics() {
|
149 |
0
| return projectMetrics;
|
150 |
| } |
151 |
| |
152 |
0
| public void setProjectmetrics(boolean projectMetrics) {
|
153 |
0
| this.projectMetrics = projectMetrics;
|
154 |
| } |
155 |
| |
156 |
0
| public boolean getGroupmetrics() {
|
157 |
0
| return groupMetrics;
|
158 |
| } |
159 |
| |
160 |
0
| public void setGroupmetrics(boolean groupMetrics) {
|
161 |
0
| this.groupMetrics = groupMetrics;
|
162 |
| } |
163 |
| |
164 |
0
| public boolean getClassmetrics() {
|
165 |
0
| return classMetrics;
|
166 |
| } |
167 |
| |
168 |
0
| public void setClassmetrics(boolean classMetrics) {
|
169 |
0
| this.classMetrics = classMetrics;
|
170 |
| } |
171 |
| |
172 |
0
| public boolean getMethodmetrics() {
|
173 |
0
| return methodMetrics;
|
174 |
| } |
175 |
| |
176 |
0
| public void setMethodmetrics(boolean methodMetrics) {
|
177 |
0
| this.methodMetrics = methodMetrics;
|
178 |
| } |
179 |
| |
180 |
0
| public void setAllmetrics(boolean allMetrics) {
|
181 |
0
| setProjectmetrics(allMetrics);
|
182 |
0
| setGroupmetrics(allMetrics);
|
183 |
0
| setClassmetrics(allMetrics);
|
184 |
0
| setMethodmetrics(allMetrics);
|
185 |
| } |
186 |
| |
187 |
0
| public Path createScopeincludeslist() {
|
188 |
0
| if (scopeIncludesList == null) {
|
189 |
0
| scopeIncludesList = new Path(getProject());
|
190 |
| } |
191 |
| |
192 |
0
| return scopeIncludesList;
|
193 |
| } |
194 |
| |
195 |
0
| public Path getScopeincludeslist() {
|
196 |
0
| return scopeIncludesList;
|
197 |
| } |
198 |
| |
199 |
0
| public Path createScopeexcludeslist() {
|
200 |
0
| if (scopeExcludesList == null) {
|
201 |
0
| scopeExcludesList = new Path(getProject());
|
202 |
| } |
203 |
| |
204 |
0
| return scopeExcludesList;
|
205 |
| } |
206 |
| |
207 |
0
| public Path getScopeexcludeslist() {
|
208 |
0
| return scopeExcludesList;
|
209 |
| } |
210 |
| |
211 |
0
| public Path createFilterincludeslist() {
|
212 |
0
| if (filterIncludesList == null) {
|
213 |
0
| filterIncludesList = new Path(getProject());
|
214 |
| } |
215 |
| |
216 |
0
| return filterIncludesList;
|
217 |
| } |
218 |
| |
219 |
0
| public Path getFilterincludeslist() {
|
220 |
0
| return filterIncludesList;
|
221 |
| } |
222 |
| |
223 |
0
| public Path createFilterexcludeslist() {
|
224 |
0
| if (filterExcludesList == null) {
|
225 |
0
| filterExcludesList = new Path(getProject());
|
226 |
| } |
227 |
| |
228 |
0
| return filterExcludesList;
|
229 |
| } |
230 |
| |
231 |
0
| public Path getFilterexcludeslist() {
|
232 |
0
| return filterExcludesList;
|
233 |
| } |
234 |
| |
235 |
0
| public boolean getShowallmetrics() {
|
236 |
0
| return showAllMetrics;
|
237 |
| } |
238 |
| |
239 |
0
| public void setShowallmetrics(boolean showAllMetrics) {
|
240 |
0
| this.showAllMetrics = showAllMetrics;
|
241 |
| } |
242 |
| |
243 |
0
| public boolean getShowemptymetrics() {
|
244 |
0
| return showEmptyMetrics;
|
245 |
| } |
246 |
| |
247 |
0
| public void setShowemptymetrics(boolean showEmptyMetrics) {
|
248 |
0
| this.showEmptyMetrics = showEmptyMetrics;
|
249 |
| } |
250 |
| |
251 |
0
| public boolean getShowhiddenmeasurements() {
|
252 |
0
| return showHiddenMeasurements;
|
253 |
| } |
254 |
| |
255 |
0
| public void setShowhiddenmeasurements(boolean showHiddenMeasurements) {
|
256 |
0
| this.showHiddenMeasurements = showHiddenMeasurements;
|
257 |
| } |
258 |
| |
259 |
0
| public String getSort() {
|
260 |
0
| return sort;
|
261 |
| } |
262 |
| |
263 |
0
| public void setSort(String sort) {
|
264 |
0
| this.sort = sort;
|
265 |
| } |
266 |
| |
267 |
0
| public boolean getExpand() {
|
268 |
0
| return expand;
|
269 |
| } |
270 |
| |
271 |
0
| public void setExpand(boolean expand) {
|
272 |
0
| this.expand = expand;
|
273 |
| } |
274 |
| |
275 |
0
| public boolean getReverse() {
|
276 |
0
| return reverse;
|
277 |
| } |
278 |
| |
279 |
0
| public void setReverse(boolean reverse) {
|
280 |
0
| this.reverse = reverse;
|
281 |
| } |
282 |
| |
283 |
0
| public boolean getEnablecrossclassmeasurements() {
|
284 |
0
| return enableCrossClassMeasurements;
|
285 |
| } |
286 |
| |
287 |
0
| public void setEnablecrossclassmeasurements(boolean enableCrossClassMeasurements) {
|
288 |
0
| this.enableCrossClassMeasurements = enableCrossClassMeasurements;
|
289 |
| } |
290 |
| |
291 |
0
| public File getDestprefix() {
|
292 |
0
| return destprefix;
|
293 |
| } |
294 |
| |
295 |
0
| public void setDestprefix(File destprefix) {
|
296 |
0
| this.destprefix = destprefix;
|
297 |
| } |
298 |
| |
299 |
0
| public Path createPath() {
|
300 |
0
| if (path == null) {
|
301 |
0
| path = new Path(getProject());
|
302 |
| } |
303 |
| |
304 |
0
| return path;
|
305 |
| } |
306 |
| |
307 |
0
| public Path getPath() {
|
308 |
0
| return path;
|
309 |
| } |
310 |
| |
311 |
0
| public void execute() throws BuildException {
|
312 |
| |
313 |
| |
314 |
0
| if (getConfiguration() == null) {
|
315 |
0
| throw new BuildException("configuration must be set!");
|
316 |
| } |
317 |
| |
318 |
0
| if (!getConfiguration().exists()) {
|
319 |
0
| throw new BuildException("configuration does not exist!");
|
320 |
| } |
321 |
| |
322 |
0
| if (!getConfiguration().isFile()) {
|
323 |
0
| throw new BuildException("configuration is not a file!");
|
324 |
| } |
325 |
| |
326 |
0
| if (getPath() == null) {
|
327 |
0
| throw new BuildException("path must be set!");
|
328 |
| } |
329 |
| |
330 |
0
| if (getDestprefix() == null) {
|
331 |
0
| throw new BuildException("destprefix must be set!");
|
332 |
| } |
333 |
| |
334 |
0
| try {
|
335 |
0
| VerboseListener verboseListener = new VerboseListener(this);
|
336 |
| |
337 |
0
| log("Reading configuration ...");
|
338 |
0
| MetricsFactory factory = new MetricsFactory(getProjectname(), new MetricsConfigurationLoader(getValidate()).load(getConfiguration().getAbsolutePath()));
|
339 |
| |
340 |
0
| com.jeantessier.metrics.MetricsGatherer gatherer = new com.jeantessier.metrics.MetricsGatherer(factory);
|
341 |
0
| if (getScopeincludeslist() != null || getScopeexcludeslist() != null) {
|
342 |
0
| gatherer.setScopeIncludes(createCollection(getScopeincludeslist(), getScopeexcludeslist()));
|
343 |
| } |
344 |
0
| if (getFilterincludeslist() != null || getFilterexcludeslist() != null) {
|
345 |
0
| gatherer.setFilterIncludes(createCollection(getFilterincludeslist(), getFilterexcludeslist()));
|
346 |
| } |
347 |
0
| gatherer.addMetricsListener(verboseListener);
|
348 |
| |
349 |
0
| if (getEnablecrossclassmeasurements()) {
|
350 |
0
| log("Reading in all classes from path " + getPath());
|
351 |
0
| ClassfileLoader loader = new AggregatingClassfileLoader();
|
352 |
0
| loader.addLoadListener(verboseListener);
|
353 |
0
| loader.load(Arrays.asList(getPath().list()));
|
354 |
| |
355 |
0
| log("Computing metrics ...");
|
356 |
0
| gatherer.visitClassfiles(loader.getAllClassfiles());
|
357 |
| } else { |
358 |
0
| ClassfileLoader loader = new TransientClassfileLoader();
|
359 |
0
| loader.addLoadListener(verboseListener);
|
360 |
0
| loader.addLoadListener(new LoadListenerVisitorAdapter(gatherer));
|
361 |
| |
362 |
0
| log("Reading classes and computing metrics as we go ...");
|
363 |
0
| loader.load(Arrays.asList(getPath().list()));
|
364 |
| } |
365 |
| |
366 |
0
| if (getShowallmetrics()) {
|
367 |
0
| for (Metrics metrics : gatherer.getMetricsFactory().getAllClassMetrics()) {
|
368 |
0
| gatherer.getMetricsFactory().includeClassMetrics(metrics);
|
369 |
| } |
370 |
| |
371 |
0
| for (Metrics metrics : gatherer.getMetricsFactory().getAllMethodMetrics()) {
|
372 |
0
| gatherer.getMetricsFactory().includeMethodMetrics(metrics);
|
373 |
| } |
374 |
| } |
375 |
| |
376 |
0
| if (getCsv()) {
|
377 |
0
| printCSVFiles(gatherer.getMetricsFactory());
|
378 |
0
| } else if (getTxt()) {
|
379 |
0
| printTextFile(gatherer.getMetricsFactory());
|
380 |
0
| } else if (getXml()) {
|
381 |
0
| printXMLFile(gatherer.getMetricsFactory());
|
382 |
| } |
383 |
| } catch (SAXException ex) { |
384 |
0
| throw new BuildException(ex);
|
385 |
| } catch (ParserConfigurationException ex) { |
386 |
0
| throw new BuildException(ex);
|
387 |
| } catch (IOException ex) { |
388 |
0
| throw new BuildException(ex);
|
389 |
| } |
390 |
| } |
391 |
| |
392 |
0
| private Collection<String> createCollection(Path includes, Path excludes) throws IOException {
|
393 |
0
| Collection<String> result = new HashSet<String>();
|
394 |
| |
395 |
0
| if (includes != null) {
|
396 |
0
| String[] filenames = includes.list();
|
397 |
0
| for (String filename : filenames) {
|
398 |
0
| BufferedReader reader = new BufferedReader(new FileReader(filename));
|
399 |
0
| String line;
|
400 |
0
| while ((line = reader.readLine()) != null) {
|
401 |
0
| result.add(line);
|
402 |
| } |
403 |
0
| reader.close();
|
404 |
| } |
405 |
| } |
406 |
| |
407 |
0
| if (excludes != null) {
|
408 |
0
| String[] filenames = excludes.list();
|
409 |
0
| for (String filename : filenames) {
|
410 |
0
| BufferedReader reader = new BufferedReader(new FileReader(filename));
|
411 |
0
| String line;
|
412 |
0
| while ((line = reader.readLine()) != null) {
|
413 |
0
| result.remove(line);
|
414 |
| } |
415 |
0
| reader.close();
|
416 |
| } |
417 |
| } |
418 |
| |
419 |
0
| return result;
|
420 |
| } |
421 |
| |
422 |
0
| private void printCSVFiles(MetricsFactory factory) throws IOException {
|
423 |
0
| MetricsComparator comparator = new MetricsComparator(getSort());
|
424 |
0
| if (getReverse()) {
|
425 |
0
| comparator.reverse();
|
426 |
| } |
427 |
| |
428 |
0
| List<Metrics> metrics;
|
429 |
0
| com.jeantessier.metrics.Printer printer;
|
430 |
| |
431 |
0
| if (getProjectmetrics()) {
|
432 |
0
| String filename = getDestprefix().getAbsolutePath() + "_project.csv";
|
433 |
0
| log("Saving metrics to " + filename);
|
434 |
| |
435 |
0
| PrintWriter out = new PrintWriter(new FileWriter(filename));
|
436 |
| |
437 |
0
| metrics = new ArrayList<Metrics>(factory.getProjectMetrics());
|
438 |
0
| Collections.sort(metrics, comparator);
|
439 |
0
| printer = new com.jeantessier.metrics.CSVPrinter(out, factory.getConfiguration().getProjectMeasurements());
|
440 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
441 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
442 |
0
| if (getIndenttext() != null) {
|
443 |
0
| printer.setIndentText(getIndenttext());
|
444 |
| } |
445 |
| |
446 |
0
| printer.visitMetrics(metrics);
|
447 |
| |
448 |
0
| out.close();
|
449 |
| } |
450 |
| |
451 |
0
| if (getGroupmetrics()) {
|
452 |
0
| String filename = getDestprefix().getAbsolutePath() + "_groups.csv";
|
453 |
0
| log("Saving metrics to " + filename);
|
454 |
| |
455 |
0
| PrintWriter out = new PrintWriter(new FileWriter(filename));
|
456 |
| |
457 |
0
| metrics = new ArrayList<Metrics>(factory.getGroupMetrics());
|
458 |
0
| Collections.sort(metrics, comparator);
|
459 |
0
| printer = new com.jeantessier.metrics.CSVPrinter(out, factory.getConfiguration().getGroupMeasurements());
|
460 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
461 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
462 |
0
| if (getIndenttext() != null) {
|
463 |
0
| printer.setIndentText(getIndenttext());
|
464 |
| } |
465 |
| |
466 |
0
| printer.visitMetrics(metrics);
|
467 |
| |
468 |
0
| out.close();
|
469 |
| } |
470 |
| |
471 |
0
| if (getClassmetrics()) {
|
472 |
0
| String filename = getDestprefix().getAbsolutePath() + "_classes.csv";
|
473 |
0
| log("Saving metrics to " + filename);
|
474 |
| |
475 |
0
| PrintWriter out = new PrintWriter(new FileWriter(filename));
|
476 |
| |
477 |
0
| metrics = new ArrayList<Metrics>(factory.getClassMetrics());
|
478 |
0
| Collections.sort(metrics, comparator);
|
479 |
0
| printer = new com.jeantessier.metrics.CSVPrinter(out, factory.getConfiguration().getClassMeasurements());
|
480 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
481 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
482 |
0
| if (getIndenttext() != null) {
|
483 |
0
| printer.setIndentText(getIndenttext());
|
484 |
| } |
485 |
| |
486 |
0
| printer.visitMetrics(metrics);
|
487 |
| |
488 |
0
| out.close();
|
489 |
| } |
490 |
| |
491 |
0
| if (getMethodmetrics()) {
|
492 |
0
| String filename = getDestprefix().getAbsolutePath() + "_methods.csv";
|
493 |
0
| log("Saving metrics to " + filename);
|
494 |
| |
495 |
0
| PrintWriter out = new PrintWriter(new FileWriter(filename));
|
496 |
| |
497 |
0
| metrics = new ArrayList<Metrics>(factory.getMethodMetrics());
|
498 |
0
| Collections.sort(metrics, comparator);
|
499 |
0
| printer = new com.jeantessier.metrics.CSVPrinter(out, factory.getConfiguration().getMethodMeasurements());
|
500 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
501 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
502 |
0
| if (getIndenttext() != null) {
|
503 |
0
| printer.setIndentText(getIndenttext());
|
504 |
| } |
505 |
| |
506 |
0
| printer.visitMetrics(metrics);
|
507 |
| |
508 |
0
| out.close();
|
509 |
| } |
510 |
| } |
511 |
| |
512 |
0
| private void printTextFile(MetricsFactory factory) throws IOException {
|
513 |
0
| MetricsComparator comparator = new MetricsComparator(getSort());
|
514 |
0
| if (getReverse()) {
|
515 |
0
| comparator.reverse();
|
516 |
| } |
517 |
| |
518 |
0
| String filename = getDestprefix().getAbsolutePath() + ".txt";
|
519 |
0
| log("Saving metrics to " + filename);
|
520 |
| |
521 |
0
| PrintWriter out = new PrintWriter(new FileWriter(filename));
|
522 |
| |
523 |
0
| List<Metrics> metrics;
|
524 |
| |
525 |
0
| if (getProjectmetrics()) {
|
526 |
0
| out.println("Project metrics");
|
527 |
0
| out.println("---------------");
|
528 |
0
| metrics = new ArrayList<Metrics>(factory.getProjectMetrics());
|
529 |
0
| Collections.sort(metrics, comparator);
|
530 |
0
| com.jeantessier.metrics.TextPrinter printer = new com.jeantessier.metrics.TextPrinter(out, factory.getConfiguration().getProjectMeasurements());
|
531 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
532 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
533 |
0
| printer.setExpandCollectionMeasurements(getExpand());
|
534 |
0
| if (getIndenttext() != null) {
|
535 |
0
| printer.setIndentText(getIndenttext());
|
536 |
| } |
537 |
| |
538 |
0
| printer.visitMetrics(metrics);
|
539 |
| |
540 |
0
| out.println();
|
541 |
| } |
542 |
| |
543 |
0
| if (getGroupmetrics()) {
|
544 |
0
| out.println("Group metrics");
|
545 |
0
| out.println("-------------");
|
546 |
0
| metrics = new ArrayList<Metrics>(factory.getGroupMetrics());
|
547 |
0
| Collections.sort(metrics, comparator);
|
548 |
0
| com.jeantessier.metrics.TextPrinter printer = new com.jeantessier.metrics.TextPrinter(out, factory.getConfiguration().getGroupMeasurements());
|
549 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
550 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
551 |
0
| printer.setExpandCollectionMeasurements(getExpand());
|
552 |
0
| if (getIndenttext() != null) {
|
553 |
0
| printer.setIndentText(getIndenttext());
|
554 |
| } |
555 |
| |
556 |
0
| printer.visitMetrics(metrics);
|
557 |
| |
558 |
0
| out.println();
|
559 |
| } |
560 |
| |
561 |
0
| if (getClassmetrics()) {
|
562 |
0
| out.println("Class metrics");
|
563 |
0
| out.println("-------------");
|
564 |
0
| metrics = new ArrayList<Metrics>(factory.getClassMetrics());
|
565 |
0
| Collections.sort(metrics, comparator);
|
566 |
0
| com.jeantessier.metrics.TextPrinter printer = new com.jeantessier.metrics.TextPrinter(out, factory.getConfiguration().getClassMeasurements());
|
567 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
568 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
569 |
0
| printer.setExpandCollectionMeasurements(getExpand());
|
570 |
0
| if (getIndenttext() != null) {
|
571 |
0
| printer.setIndentText(getIndenttext());
|
572 |
| } |
573 |
| |
574 |
0
| printer.visitMetrics(metrics);
|
575 |
| |
576 |
0
| out.println();
|
577 |
| } |
578 |
| |
579 |
0
| if (getMethodmetrics()) {
|
580 |
0
| out.println("Method metrics");
|
581 |
0
| out.println("--------------");
|
582 |
0
| metrics = new ArrayList<Metrics>(factory.getMethodMetrics());
|
583 |
0
| Collections.sort(metrics, comparator);
|
584 |
0
| com.jeantessier.metrics.TextPrinter printer = new com.jeantessier.metrics.TextPrinter(out, factory.getConfiguration().getMethodMeasurements());
|
585 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
586 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
587 |
0
| printer.setExpandCollectionMeasurements(getExpand());
|
588 |
0
| if (getIndenttext() != null) {
|
589 |
0
| printer.setIndentText(getIndenttext());
|
590 |
| } |
591 |
| |
592 |
0
| printer.visitMetrics(metrics);
|
593 |
| |
594 |
0
| out.println();
|
595 |
| } |
596 |
| |
597 |
0
| out.close();
|
598 |
| } |
599 |
| |
600 |
0
| private void printXMLFile(MetricsFactory factory) throws IOException {
|
601 |
0
| MetricsComparator comparator = new MetricsComparator(getSort());
|
602 |
0
| if (getReverse()) {
|
603 |
0
| comparator.reverse();
|
604 |
| } |
605 |
| |
606 |
0
| String filename = getDestprefix().getAbsolutePath() + ".xml";
|
607 |
0
| log("Saving metrics to " + filename);
|
608 |
| |
609 |
0
| PrintWriter out = new PrintWriter(new FileWriter(filename));
|
610 |
| |
611 |
0
| List<Metrics> metrics = new ArrayList<Metrics>(factory.getProjectMetrics());
|
612 |
0
| Collections.sort(metrics, comparator);
|
613 |
0
| com.jeantessier.metrics.Printer printer = new com.jeantessier.metrics.XMLPrinter(out, factory.getConfiguration(), getEncoding(), getDtdprefix());
|
614 |
0
| printer.setShowEmptyMetrics(getShowemptymetrics());
|
615 |
0
| printer.setShowHiddenMeasurements(getShowhiddenmeasurements());
|
616 |
0
| if (getIndenttext() != null) {
|
617 |
0
| printer.setIndentText(getIndenttext());
|
618 |
| } |
619 |
| |
620 |
0
| printer.visitMetrics(metrics);
|
621 |
| |
622 |
0
| out.close();
|
623 |
| } |
624 |
| } |