Skip to content

Commit acaefb2

Browse files
committed
upgrade to 7.3
1 parent fc7400d commit acaefb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+666
-1626
lines changed

commons/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@
7171
<artifactId>json-simple</artifactId>
7272
</dependency>
7373

74+
<dependency>
75+
<groupId>com.fasterxml</groupId>
76+
<artifactId>aalto-xml</artifactId>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.fasterxml.staxmate</groupId>
80+
<artifactId>staxmate</artifactId>
81+
</dependency>
82+
<dependency>
83+
<groupId>com.fasterxml.woodstox</groupId>
84+
<artifactId>woodstox-core</artifactId>
85+
</dependency>
86+
7487
<!-- Test dependencies -->
7588
<dependency>
7689
<groupId>junit</groupId>

commons/src/main/java/com/backelite/sonarqube/commons/surefire/SurefireParser.java

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -20,114 +20,79 @@
2020
import com.backelite.sonarqube.commons.MeasureUtil;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
23-
import org.sonar.api.batch.fs.FileSystem;
2423
import org.sonar.api.batch.fs.InputComponent;
25-
import org.sonar.api.batch.fs.InputFile;
2624
import org.sonar.api.batch.sensor.SensorContext;
27-
import org.sonar.api.component.ResourcePerspectives;
2825
import org.sonar.api.measures.CoreMetrics;
29-
import org.sonar.api.test.MutableTestPlan;
30-
import org.sonar.api.test.TestCase;
31-
import org.sonar.api.utils.StaxParser;
3226

33-
import javax.annotation.Nullable;
3427
import javax.xml.stream.XMLStreamException;
3528
import java.io.File;
36-
import java.io.FilenameFilter;
37-
import java.util.Map;
29+
import java.io.IOException;
30+
import java.nio.file.Files;
31+
import java.nio.file.Path;
32+
import java.nio.file.Paths;
33+
import java.util.ArrayList;
34+
import java.util.List;
3835

3936
/**
4037
* Created by gillesgrousset on 28/08/2018.
4138
*/
4239
public class SurefireParser {
43-
4440
protected static final Logger LOGGER = LoggerFactory.getLogger(SurefireParser.class);
4541

46-
protected final FileSystem fileSystem;
4742
protected final SensorContext context;
48-
protected final ResourcePerspectives perspectives;
4943

50-
protected SurefireParser(FileSystem fileSystem, ResourcePerspectives perspectives, SensorContext context) {
51-
this.fileSystem = fileSystem;
52-
this.perspectives = perspectives;
44+
protected SurefireParser(SensorContext context) {
5345
this.context = context;
5446
}
5547

56-
private void parseFiles(File[] reports, UnitTestIndex index) {
48+
private void parseFiles(List<File> reports) {
49+
UnitTestIndex index = new UnitTestIndex();
5750
SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
58-
StaxParser parser = new StaxParser(staxParser, false);
51+
StaxParser parser = new StaxParser(staxParser);
5952
for (File report : reports) {
6053
try {
6154
parser.parse(report);
6255
} catch (XMLStreamException e) {
6356
throw new IllegalStateException("Fail to parse the Surefire report: " + report, e);
6457
}
6558
}
66-
59+
save(index);
6760
}
6861

6962
public void collect(File reportsDir) {
70-
71-
72-
File[] xmlFiles = getReports(reportsDir);
73-
74-
if (xmlFiles.length > 0) {
75-
parseFiles(xmlFiles);
63+
List<File> files = new ArrayList<>();
64+
if(reportsDir != null && reportsDir.isDirectory()){
65+
try {
66+
for (Path p : Files.newDirectoryStream(Paths.get(reportsDir.toURI()), name -> (name.startsWith("TEST") && name.endsWith(".xml")) || name.endsWith(".junit"))) {
67+
files.add(p.toFile());
68+
}
69+
} catch (IOException ex){
70+
LOGGER.error( "Error while finding test files.", ex);
71+
}
7672
}
77-
}
78-
79-
private File[] getReports(File dir) {
8073

81-
if (dir == null || !dir.isDirectory() || !dir.exists()) {
82-
return new File[0];
74+
if (!files.isEmpty()) {
75+
parseFiles(files);
8376
}
84-
85-
return dir.listFiles(new FilenameFilter() {
86-
public boolean accept(File dir, String name) {
87-
// .junit is for fastlane support
88-
return (name.startsWith("TEST") && name.endsWith(".xml")) || (name.endsWith(".junit"));
89-
}
90-
});
91-
}
92-
93-
94-
private void parseFiles(File[] reports) {
95-
UnitTestIndex index = new UnitTestIndex();
96-
parseFiles(reports, index);
97-
save(index);
9877
}
9978

10079
private void save(UnitTestIndex index) {
101-
102-
10380
long negativeTimeTestNumber = 0;
10481
int testsCount = 0;
10582
int testsSkipped = 0;
10683
int testsErrors = 0;
10784
int testsFailures = 0;
10885
long testsTime = 0;
10986

110-
for (Map.Entry<String, UnitTestClassReport> entry : index.getIndexByClassname().entrySet()) {
111-
112-
UnitTestClassReport report = entry.getValue();
113-
87+
for (UnitTestClassReport report : index.getIndexByClassname().values()) {
11488
testsCount += report.getTests() - report.getSkipped();
11589
testsSkipped += report.getSkipped();
11690
testsErrors += report.getErrors();
11791
testsFailures += report.getFailures();
11892

11993
if (report.getTests() > 0) {
120-
12194
negativeTimeTestNumber += report.getNegativeTimeTestNumber();
122-
InputFile inputFile = getUnitTestResource(entry.getKey());
123-
if (inputFile != null) {
124-
saveResults(inputFile, report);
125-
} else {
126-
LOGGER.warn("Resource not found: {}", entry.getKey());
127-
}
128-
12995
}
130-
13196
}
13297

13398

@@ -144,26 +109,4 @@ private void save(UnitTestIndex index) {
144109
MeasureUtil.saveMeasure(context, module, CoreMetrics.TEST_EXECUTION_TIME, testsTime);
145110
}
146111
}
147-
148-
149-
protected void saveResults(InputFile testFile, UnitTestClassReport report) {
150-
for (UnitTestResult unitTestResult : report.getResults()) {
151-
MutableTestPlan testPlan = perspectives.as(MutableTestPlan.class, testFile);
152-
if (testPlan != null) {
153-
testPlan.addTestCase(unitTestResult.getName())
154-
.setDurationInMs(Math.max(unitTestResult.getDurationMilliseconds(), 0))
155-
.setStatus(TestCase.Status.of(unitTestResult.getStatus()))
156-
.setMessage(unitTestResult.getMessage())
157-
.setType(TestCase.TYPE_UNIT)
158-
.setStackTrace(unitTestResult.getStackTrace());
159-
}
160-
}
161-
}
162-
163-
@Nullable
164-
public InputFile getUnitTestResource(String classname) {
165-
return TestFileFinders.getInstance().getUnitTestResource(fileSystem, classname);
166-
}
167-
168-
169112
}

commons/src/main/java/com/backelite/sonarqube/commons/surefire/SurefireSensor.java

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,56 +35,41 @@
3535
* Created by gillesgrousset on 28/08/2018.
3636
*/
3737
public class SurefireSensor implements Sensor {
38+
private static final Logger LOGGER = LoggerFactory.getLogger(SurefireSensor.class);
39+
public static final String REPORT_PATH_KEY = Constants.PROPERTY_PREFIX + ".surefire.junit.reportsPath";
40+
public static final String DEFAULT_REPORT_PATH = "sonar-reports/";
3841

39-
public static final String REPORTS_PATH_KEY = Constants.PROPERTY_PREFIX + ".surefire.junit.reportsPath";
40-
public static final String DEFAULT_REPORTS_PATH = "sonar-reports/";
42+
private final SensorContext context;
4143

42-
private static final Logger LOGGER = LoggerFactory.getLogger(SurefireSensor.class);
43-
private final FileSystem fileSystem;
44-
private final PathResolver pathResolver;
45-
private final ResourcePerspectives resourcePerspectives;
46-
private final Settings settings;
44+
public SurefireSensor(SensorContext context) {
45+
this.context = context;
46+
}
4747

48-
public SurefireSensor(FileSystem fileSystem, PathResolver pathResolver, ResourcePerspectives resourcePerspectives, Settings settings) {
49-
this.fileSystem = fileSystem;
50-
this.pathResolver = pathResolver;
51-
this.resourcePerspectives = resourcePerspectives;
52-
this.settings = settings;
48+
protected String reportPath() {
49+
return context.config()
50+
.get(REPORT_PATH_KEY)
51+
.orElse(DEFAULT_REPORT_PATH);
5352
}
5453

5554
@Override
5655
public void describe(SensorDescriptor descriptor) {
5756
descriptor
58-
.name("Surefire")
59-
.onlyOnFileType(InputFile.Type.MAIN);
57+
.name("Surefire")
58+
.onlyOnLanguages("swift","objc")
59+
.onlyOnFileType(InputFile.Type.MAIN);
6060
}
6161

6262
@Override
6363
public void execute(SensorContext context) {
64-
65-
String path = this.reportPath();
66-
File reportsDir = pathResolver.relativeFile(fileSystem.baseDir(), path);
67-
68-
LOGGER.info("Processing test reports in {}", reportsDir);
64+
String reportFileName = context.fileSystem().baseDir().getAbsolutePath() + "/"+ reportPath();
65+
File reportsDir = new File(reportFileName);
6966

7067
if (!reportsDir.isDirectory()) {
7168
LOGGER.warn("JUnit report directory not found at {}", reportsDir);
7269
return;
7370
}
74-
75-
collect(context, reportsDir);
76-
}
77-
78-
protected void collect(SensorContext context, File reportsDir) {
79-
LOGGER.info("parsing {}", reportsDir);
80-
new SurefireParser(fileSystem, resourcePerspectives, context).collect(reportsDir);
81-
}
82-
83-
protected String reportPath() {
84-
String reportPath = settings.getString(REPORTS_PATH_KEY);
85-
if (reportPath == null) {
86-
reportPath = DEFAULT_REPORTS_PATH;
87-
}
88-
return reportPath;
71+
LOGGER.info("Processing test reports in {}", reportsDir);
72+
SurefireParser surefireParser = new SurefireParser(context);
73+
surefireParser.collect(reportsDir);
8974
}
9075
}

commons/src/main/java/com/backelite/sonarqube/commons/surefire/SurefireStaxHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
import org.codehaus.staxmate.in.SMHierarchicCursor;
2424
import org.codehaus.staxmate.in.SMInputCursor;
2525
import org.sonar.api.utils.ParsingUtils;
26-
import org.sonar.api.utils.StaxParser.XmlStreamHandler;
2726

2827
import javax.xml.stream.XMLStreamException;
2928
import java.text.ParseException;
3029
import java.util.Locale;
3130

32-
public class SurefireStaxHandler implements XmlStreamHandler {
31+
public class SurefireStaxHandler implements StaxParser.XmlStreamHandler {
3332

3433
private final UnitTestIndex index;
3534

objclang/src/main/java/com/backelite/sonarqube/objectivec/ObjectiveCConstants.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,5 @@
1919

2020

2121
public final class ObjectiveCConstants {
22-
2322
public static final String FILE_SUFFIXES = "h,m,mm";
24-
25-
2623
}

0 commit comments

Comments
 (0)