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 package org.eluder.coveralls.maven.plugin.logging;
26
27 import java.io.IOException;
28
29 import org.apache.maven.plugin.logging.Log;
30 import org.eluder.coveralls.maven.plugin.ProcessingException;
31 import org.eluder.coveralls.maven.plugin.domain.Branch;
32 import org.eluder.coveralls.maven.plugin.domain.Source;
33 import org.eluder.coveralls.maven.plugin.source.ChainingSourceCallback;
34 import org.eluder.coveralls.maven.plugin.source.SourceCallback;
35
36
37
38
39 public class CoverageTracingLogger extends ChainingSourceCallback implements Logger {
40
41
42 private long files;
43
44
45 private long lines;
46
47
48 private long relevant;
49
50
51 private long covered;
52
53
54 private long branches;
55
56
57 private long coveredBranches;
58
59
60
61
62
63
64
65 public CoverageTracingLogger(final SourceCallback chained) {
66 super(chained);
67 }
68
69
70
71
72
73
74 public long getFiles() {
75 return this.files;
76 }
77
78
79
80
81
82
83 public final long getLines() {
84 return this.lines;
85 }
86
87
88
89
90
91
92 public final long getRelevant() {
93 return this.relevant;
94 }
95
96
97
98
99
100
101 public final long getCovered() {
102 return this.covered;
103 }
104
105
106
107
108
109
110 public final long getMissed() {
111 return this.relevant - this.covered;
112 }
113
114
115
116
117
118
119 public final long getBranches() {
120 return this.branches;
121 }
122
123
124
125
126
127
128 public final long getCoveredBranches() {
129 return this.coveredBranches;
130 }
131
132
133
134
135
136
137 public final long getMissedBranches() {
138 return this.branches - this.coveredBranches;
139 }
140
141 @Override
142 public Position getPosition() {
143 return Position.AFTER;
144 }
145
146 @Override
147 public void log(final Log log) {
148 log.info("Gathered code coverage metrics for " + this.getFiles() + " source files with " + this.getLines()
149 + " lines of code:");
150 log.info("- " + this.getRelevant() + " relevant lines");
151 log.info("- " + this.getCovered() + " covered lines");
152 log.info("- " + this.getMissed() + " missed lines");
153 log.info("- " + this.getBranches() + " branches");
154 log.info("- " + this.getCoveredBranches() + " covered branches");
155 log.info("- " + this.getMissedBranches() + " missed branches");
156 }
157
158 @Override
159 protected void onSourceInternal(final Source source) throws ProcessingException, IOException {
160 this.files++;
161 this.lines += source.getCoverage().length;
162 for (final Integer coverage : source.getCoverage()) {
163 if (coverage != null) {
164 this.relevant++;
165 if (coverage > 0) {
166 this.covered++;
167 }
168 }
169 }
170
171 this.branches += source.getBranchesList().size();
172 for (final Branch b : source.getBranchesList()) {
173 if (b.getHits() > 0) {
174 this.coveredBranches++;
175 }
176 }
177 }
178 }