Skip to content

Commit b58396e

Browse files
author
Gilles Grousset
committed
Surefire sensor fix
1 parent 0d7ed80 commit b58396e

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/SwiftSurefireParser.java

+11-18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.sonar.plugins.swift.surefire.data.UnitTestIndex;
3838
import org.sonar.plugins.swift.surefire.data.UnitTestResult;
3939

40+
import javax.annotation.Nullable;
4041
import javax.xml.stream.XMLStreamException;
4142
import java.io.File;
4243
import java.io.FilenameFilter;
@@ -52,14 +53,15 @@ public final class SwiftSurefireParser {
5253
private final SensorContext context;
5354
private final ResourcePerspectives perspectives;
5455

55-
public SwiftSurefireParser(FileSystem fileSystem, ResourcePerspectives perspectives,
56-
SensorContext context) {
56+
public SwiftSurefireParser(FileSystem fileSystem, ResourcePerspectives perspectives, SensorContext context) {
5757
this.fileSystem = fileSystem;
5858
this.perspectives = perspectives;
5959
this.context = context;
6060
}
6161

6262
public void collect(File reportsDir) {
63+
64+
6365
File[] xmlFiles = getReports(reportsDir);
6466

6567
if (xmlFiles.length == 0) {
@@ -70,14 +72,15 @@ public void collect(File reportsDir) {
7072
}
7173

7274
private File[] getReports(File dir) {
73-
if (!dir.isDirectory() || !dir.exists()) {
75+
76+
if (dir == null || !dir.isDirectory() || !dir.exists()) {
7477
return new File[0];
7578
}
7679

7780
return dir.listFiles(new FilenameFilter() {
78-
@Override
7981
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"));
8184
}
8285
});
8386
}
@@ -89,7 +92,6 @@ private void insertZeroWhenNoReports() {
8992
private void parseFiles(File[] reports) {
9093
UnitTestIndex index = new UnitTestIndex();
9194
parseFiles(reports, index);
92-
sanitize(index);
9395
save(index);
9496
}
9597

@@ -105,18 +107,9 @@ private static void parseFiles(File[] reports, UnitTestIndex index) {
105107
}
106108
}
107109

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-
118110
private void save(UnitTestIndex index) {
119111
long negativeTimeTestNumber = 0;
112+
120113
for (Map.Entry<String, UnitTestClassReport> entry : index.getIndexByClassname().entrySet()) {
121114
UnitTestClassReport report = entry.getValue();
122115
if (report.getTests() > 0) {
@@ -163,8 +156,8 @@ protected void saveResults(Resource testFile, UnitTestClassReport report) {
163156
}
164157
}
165158

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";
168161

169162
InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasPath(fileName));
170163

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/SwiftSurefireSensor.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ public SwiftSurefireSensor(FileSystem fileSystem, PathResolver pathResolver, Res
5353

5454
@Override
5555
public boolean shouldExecuteOnProject(Project project) {
56-
return StringUtils.isNotEmpty(settings.getString(REPORTS_PATH_KEY));
56+
return StringUtils.isNotEmpty(this.reportPath());
5757
}
5858

5959
@Override
6060
public void analyse(Project project, SensorContext context) {
61-
String path = settings.getString(REPORTS_PATH_KEY);
61+
62+
String path = this.reportPath();
6263
File reportsDir = pathResolver.relativeFile(fileSystem.baseDir(), path);
6364

65+
LOGGER.info("Processing test reports in {}", reportsDir);
66+
6467
if (!reportsDir.isDirectory()) {
6568
LOGGER.warn("JUnit report directory not found at {}", reportsDir);
6669
return;

0 commit comments

Comments
 (0)