37
37
import org .sonar .plugins .swift .surefire .data .UnitTestIndex ;
38
38
import org .sonar .plugins .swift .surefire .data .UnitTestResult ;
39
39
40
+ import javax .annotation .Nullable ;
40
41
import javax .xml .stream .XMLStreamException ;
41
42
import java .io .File ;
42
43
import java .io .FilenameFilter ;
@@ -52,14 +53,15 @@ public final class SwiftSurefireParser {
52
53
private final SensorContext context ;
53
54
private final ResourcePerspectives perspectives ;
54
55
55
- public SwiftSurefireParser (FileSystem fileSystem , ResourcePerspectives perspectives ,
56
- SensorContext context ) {
56
+ public SwiftSurefireParser (FileSystem fileSystem , ResourcePerspectives perspectives , SensorContext context ) {
57
57
this .fileSystem = fileSystem ;
58
58
this .perspectives = perspectives ;
59
59
this .context = context ;
60
60
}
61
61
62
62
public void collect (File reportsDir ) {
63
+
64
+
63
65
File [] xmlFiles = getReports (reportsDir );
64
66
65
67
if (xmlFiles .length == 0 ) {
@@ -70,14 +72,15 @@ public void collect(File reportsDir) {
70
72
}
71
73
72
74
private File [] getReports (File dir ) {
73
- if (!dir .isDirectory () || !dir .exists ()) {
75
+
76
+ if (dir == null || !dir .isDirectory () || !dir .exists ()) {
74
77
return new File [0 ];
75
78
}
76
79
77
80
return dir .listFiles (new FilenameFilter () {
78
- @ Override
79
81
public boolean accept (File dir , String name ) {
80
- return name .startsWith ("TEST" ) && name .endsWith (".xml" );
82
+ // .junit is for Fastlane support
83
+ return (name .startsWith ("TEST" ) && name .endsWith (".xml" )) || (name .endsWith (".junit" ));
81
84
}
82
85
});
83
86
}
@@ -89,7 +92,6 @@ private void insertZeroWhenNoReports() {
89
92
private void parseFiles (File [] reports ) {
90
93
UnitTestIndex index = new UnitTestIndex ();
91
94
parseFiles (reports , index );
92
- sanitize (index );
93
95
save (index );
94
96
}
95
97
@@ -105,18 +107,9 @@ private static void parseFiles(File[] reports, UnitTestIndex index) {
105
107
}
106
108
}
107
109
108
- private static void sanitize (UnitTestIndex index ) {
109
- for (String classname : index .getClassnames ()) {
110
- if (StringUtils .contains (classname , "$" )) {
111
- // Surefire reports classes whereas sonar supports files
112
- String parentClassName = StringUtils .substringBefore (classname , "$" );
113
- index .merge (classname , parentClassName );
114
- }
115
- }
116
- }
117
-
118
110
private void save (UnitTestIndex index ) {
119
111
long negativeTimeTestNumber = 0 ;
112
+
120
113
for (Map .Entry <String , UnitTestClassReport > entry : index .getIndexByClassname ().entrySet ()) {
121
114
UnitTestClassReport report = entry .getValue ();
122
115
if (report .getTests () > 0 ) {
@@ -163,8 +156,8 @@ protected void saveResults(Resource testFile, UnitTestClassReport report) {
163
156
}
164
157
}
165
158
166
- public Resource getUnitTestResource (String classname ) {
167
- String fileName = classname .replace ('.' , '/' ) + ".m " ;
159
+ @ Nullable public Resource getUnitTestResource (String classname ) {
160
+ String fileName = classname .replace ('.' , '/' ) + ".swift " ;
168
161
169
162
InputFile inputFile = fileSystem .inputFile (fileSystem .predicates ().hasPath (fileName ));
170
163
0 commit comments