22
22
import java .io .File ;
23
23
import java .util .ArrayList ;
24
24
import java .util .Collections ;
25
+ import java .util .HashSet ;
25
26
import java .util .List ;
26
27
import java .util .Map ;
28
+ import java .util .Set ;
27
29
import java .util .stream .Collectors ;
28
30
import javax .annotation .Nullable ;
29
31
import javax .xml .stream .XMLStreamException ;
@@ -42,6 +44,7 @@ public class CoberturaParser {
42
44
43
45
private static final Logger LOG = Loggers .get (CoberturaParser .class );
44
46
47
+ private final Set <String > errors = new HashSet <>();
45
48
private int unresolvedFilenameCount ;
46
49
47
50
public void parseReport (File xmlFile , SensorContext context , final Map <InputFile , NewCoverage > coverageData ) throws XMLStreamException {
@@ -68,11 +71,13 @@ public void parseReport(File xmlFile, SensorContext context, final Map<InputFile
68
71
});
69
72
parser .parse (xmlFile );
70
73
if (unresolvedFilenameCount > 1 ) {
71
- LOG .error ("Cannot resolve {} file paths, ignoring coverage measures for those files" , unresolvedFilenameCount );
74
+ String message = String .format ("Cannot resolve %d file paths, ignoring coverage measures for those files" , unresolvedFilenameCount );
75
+ LOG .error (message );
76
+ errors .add (message );
72
77
}
73
78
}
74
79
75
- private static List <File > extractBaseDirectories (SMInputCursor sources , File defaultBaseDirectory ) throws XMLStreamException {
80
+ private List <File > extractBaseDirectories (SMInputCursor sources , File defaultBaseDirectory ) throws XMLStreamException {
76
81
List <File > baseDirectories = new ArrayList <>();
77
82
SMInputCursor source = sources .childElementCursor ("source" );
78
83
while (source .getNext () != null ) {
@@ -82,7 +87,9 @@ private static List<File> extractBaseDirectories(SMInputCursor sources, File def
82
87
if (baseDirectory .isDirectory ()) {
83
88
baseDirectories .add (baseDirectory );
84
89
} else {
85
- LOG .warn ("Invalid directory path in 'source' element: {}" , path );
90
+ String formattedMessage = String .format ("Invalid directory path in 'source' element: %s" , path );
91
+ LOG .warn (formattedMessage );
92
+ errors .add (formattedMessage );
86
93
}
87
94
}
88
95
}
@@ -112,7 +119,7 @@ private InputFile resolve(SensorContext context, List<File> baseDirectories, Str
112
119
File file = new File (filename );
113
120
if (file .isAbsolute ()) {
114
121
if (!file .exists ()) {
115
- logUnresolvedFile ("Cannot resolve the file path '{} ' of the coverage report, the file does not exist in all < source> ." , filename );
122
+ logUnresolvedFile ("Cannot resolve the file path '%s ' of the coverage report, the file does not exist in all ' source' ." , filename );
116
123
}
117
124
absolutePath = file .getAbsolutePath ();
118
125
} else {
@@ -121,11 +128,11 @@ private InputFile resolve(SensorContext context, List<File> baseDirectories, Str
121
128
.filter (File ::exists )
122
129
.collect (Collectors .toList ());
123
130
if (fileList .isEmpty ()) {
124
- logUnresolvedFile ("Cannot resolve the file path '{} ' of the coverage report, the file does not exist in all < source> ." , filename );
131
+ logUnresolvedFile ("Cannot resolve the file path '%s ' of the coverage report, the file does not exist in all ' source' ." , filename );
125
132
return null ;
126
133
}
127
134
if (fileList .size () > 1 ) {
128
- logUnresolvedFile ("Cannot resolve the file path '{} ' of the coverage report, ambiguity, the file exists in several < source> ." , filename );
135
+ logUnresolvedFile ("Cannot resolve the file path '%s ' of the coverage report, ambiguity, the file exists in several ' source' ." , filename );
129
136
return null ;
130
137
}
131
138
absolutePath = fileList .get (0 ).getAbsolutePath ();
@@ -136,7 +143,9 @@ private InputFile resolve(SensorContext context, List<File> baseDirectories, Str
136
143
private void logUnresolvedFile (String message , String filename ) {
137
144
unresolvedFilenameCount ++;
138
145
if (unresolvedFilenameCount == 1 ) {
139
- LOG .error (message , filename );
146
+ String formattedMessage = String .format (message , filename );
147
+ LOG .error (formattedMessage );
148
+ errors .add (formattedMessage );
140
149
}
141
150
}
142
151
@@ -154,4 +163,8 @@ private static void collectFileData(SMInputCursor classCursor, NewCoverage cover
154
163
}
155
164
}
156
165
}
166
+
167
+ public Set <String > errors () {
168
+ return errors ;
169
+ }
157
170
}
0 commit comments