1
1
/**
2
- * Swift SonarQube Plugin - Objective-C module - Enables analysis of Swift and Objective-C projects into SonarQube.
2
+ * commons - Enables analysis of Swift and Objective-C projects into SonarQube.
3
3
* Copyright © 2015 Backelite (${email})
4
4
*
5
5
* This program is free software: you can redistribute it and/or modify
15
15
* You should have received a copy of the GNU Lesser General Public License
16
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
- package com .backelite .sonarqube .objectivec .surefire ;
18
+ package com .backelite .sonarqube .commons .surefire ;
19
19
20
- import com .backelite .sonarqube .commons .surefire .SurefireStaxHandler ;
21
- import com .backelite .sonarqube .commons .surefire .UnitTestClassReport ;
22
- import com .backelite .sonarqube .commons .surefire .UnitTestIndex ;
23
- import com .backelite .sonarqube .commons .surefire .UnitTestResult ;
24
- import com .google .common .collect .ImmutableList ;
25
20
import org .slf4j .Logger ;
26
21
import org .slf4j .LoggerFactory ;
27
22
import org .sonar .api .batch .SensorContext ;
28
23
import org .sonar .api .batch .fs .FileSystem ;
29
- import org .sonar .api .batch .fs .InputFile ;
30
24
import org .sonar .api .component .ResourcePerspectives ;
31
25
import org .sonar .api .measures .CoreMetrics ;
32
26
import org .sonar .api .measures .Metric ;
33
- import org .sonar .api .resources .Project ;
34
27
import org .sonar .api .resources .Resource ;
35
28
import org .sonar .api .test .MutableTestPlan ;
36
29
import org .sonar .api .test .TestCase ;
37
30
import org .sonar .api .utils .ParsingUtils ;
38
31
import org .sonar .api .utils .StaxParser ;
32
+
39
33
import javax .annotation .Nullable ;
40
34
import javax .xml .stream .XMLStreamException ;
41
35
import java .io .File ;
42
36
import java .io .FilenameFilter ;
43
- import java .util .List ;
44
37
import java .util .Map ;
45
38
46
39
/**
47
- * Created by gillesgrousset on 06/01/15 .
40
+ * Created by gillesgrousset on 28/08/2018 .
48
41
*/
49
- public class SurefireParser {
42
+ public abstract class BaseSurefireParser {
50
43
51
- private static final Logger LOGGER = LoggerFactory .getLogger (SurefireParser .class );
44
+ protected static final Logger LOGGER = LoggerFactory .getLogger (BaseSurefireParser .class );
52
45
53
- private final Project project ;
54
- private final FileSystem fileSystem ;
55
- private final ResourcePerspectives perspectives ;
56
- private final SensorContext context ;
46
+ protected final FileSystem fileSystem ;
47
+ protected final SensorContext context ;
48
+ protected final ResourcePerspectives perspectives ;
57
49
58
- public SurefireParser (Project project , FileSystem fileSystem , ResourcePerspectives resourcePerspectives , SensorContext context ) {
59
- this .project = project ;
50
+ protected BaseSurefireParser (FileSystem fileSystem , ResourcePerspectives perspectives , SensorContext context ) {
60
51
this .fileSystem = fileSystem ;
61
- this .perspectives = resourcePerspectives ;
52
+ this .perspectives = perspectives ;
62
53
this .context = context ;
63
54
}
64
55
@@ -75,19 +66,15 @@ public void collect(File reportsDir) {
75
66
}
76
67
77
68
private File [] getReports (File dir ) {
69
+
78
70
if (dir == null || !dir .isDirectory () || !dir .exists ()) {
79
71
return new File [0 ];
80
72
}
81
73
82
- File [] list = dir .listFiles (new FilenameFilter () {
83
- public boolean accept (File dir , String name ) {
84
- return name .startsWith ("TEST" ) && name .endsWith (".xml" );
85
- }
86
- });
87
-
88
74
return dir .listFiles (new FilenameFilter () {
89
75
public boolean accept (File dir , String name ) {
90
- return name .startsWith ("TEST" ) && name .endsWith (".xml" );
76
+ // .junit is for fastlane support
77
+ return (name .startsWith ("TEST" ) && name .endsWith (".xml" )) || (name .endsWith (".junit" ));
91
78
}
92
79
});
93
80
}
@@ -164,34 +151,7 @@ protected void saveResults(Resource testFile, UnitTestClassReport report) {
164
151
}
165
152
166
153
@ Nullable
167
- public Resource getUnitTestResource (String classname ) {
168
-
169
- String fileName = classname .replace ('.' , '/' ) + ".m" ;
170
-
171
- InputFile inputFile = fileSystem .inputFile (fileSystem .predicates ().hasPath (fileName ));
172
-
173
- /*
174
- * Most xcodebuild JUnit parsers don't include the path to the class in the class field, so search for it if it
175
- * wasn't found in the root.
176
- */
177
- if (inputFile == null ) {
178
- List <InputFile > files = ImmutableList .copyOf (fileSystem .inputFiles (fileSystem .predicates ().and (
179
- fileSystem .predicates ().hasType (InputFile .Type .TEST ),
180
- fileSystem .predicates ().matchesPathPattern ("**/" + fileName .replace ("_" , "+" )))));
181
-
182
- if (files .isEmpty ()) {
183
- LOGGER .info ("Unable to locate test source file {}" , fileName );
184
- } else {
185
- /*
186
- * Lazily get the first file, since we wouldn't be able to determine the correct one from just the
187
- * test class name in the event that there are multiple matches.
188
- */
189
- inputFile = files .get (0 );
190
- }
191
- }
192
-
193
- return inputFile == null ? null : context .getResource (inputFile );
194
- }
154
+ public abstract Resource getUnitTestResource (String classname );
195
155
196
156
private void saveMeasure (Resource resource , Metric metric , double value ) {
197
157
if (!Double .isNaN (value )) {
0 commit comments