Skip to content

Commit 0d72f43

Browse files
author
Gilles Grousset
committed
Merge branch 'feat/objc-merge' into develop
2 parents 6f2d5c9 + c24b8e0 commit 0d72f43

File tree

122 files changed

+12076
-3224
lines changed

Some content is hidden

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

122 files changed

+12076
-3224
lines changed

README.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ In SonarQube under Quality Profiles the used Linter can be specified by selectin
2525

2626
### Features
2727

28-
| Feature | Supported | MacOS | Unix |
29-
|---------------|----------|:-----------:|:-----------:|
30-
| Complexity |YES |Uses [Lizard](https://github.com/terryyin/lizard)| Uses [Lizard](https://github.com/terryyin/lizard)|
31-
| Design |NO | | |
32-
| Documentation |YES | | |
33-
| Duplications |YES | | |
34-
| Issues |YES | Uses [SwiftLint](https://github.com/realm/SwiftLint) and/or [Tailor](https://github.com/sleekbyte/tailor)| Uses [Tailor](https://github.com/sleekbyte/tailor)|
35-
| Size |YES | ||
28+
| Feature | Supported | MacOS | Unix |
29+
|---------------|-----------|:-----------:|:-----------:|
30+
| Complexity |YES |Uses [Lizard](https://github.com/terryyin/lizard)| Uses [Lizard](https://github.com/terryyin/lizard)|
31+
| Design |NO | | |
32+
| Documentation |YES | | |
33+
| Duplications |YES | | |
34+
| Issues |YES | Uses [SwiftLint](https://github.com/realm/SwiftLint) and/or [Tailor](https://github.com/sleekbyte/tailor) for Swift. [OCLint](http://oclint-docs.readthedocs.io/en/stable/) and [Faux Pas](http://fauxpasapp.com/) for Objective-C| Uses [Tailor](https://github.com/sleekbyte/tailor)|
35+
| Size |YES | | |
3636
| Tests |YES | Uses xcodebuild + xcpretty [xcpretty](https://github.com/supermarin/xcpretty) | Not Supported |
37-
| Code coverage |YES | Uses [slather](https://github.com/venmo/slather) | Not Supported|
37+
| Code coverage |YES | Uses [slather](https://github.com/venmo/slather) | Not Supported|
38+
39+
### Faux Pas support
40+
41+
[Faux Pas](http://fauxpasapp.com/) is a wonderful tool to analyse iOS or Mac applications Objective-C source code, however it is not free. A 30 trial version is available [here](http://fauxpasapp.com/try/).
42+
43+
The plugin runs fine even if Faux Pas is not installed (Faux Pas analysis will be skipped).
3844

3945

4046
### Download
@@ -56,6 +62,8 @@ Otherwise, run the ```run-sonar-swift.sh``` script from your Xcode project root
5662
- [Tailor](https://github.com/sleekbyte/tailor) ([HomeBrew](http://brew.sh) installed and ```brew install tailor```). Version 0.11.1 or above.
5763
- [slather](https://github.com/SlatherOrg/slather) (```gem install slather```). Version 2.1.0 or above (2.4 since Xcode 8.3).
5864
- [lizard](https://github.com/terryyin/lizard) ([PIP](https://pip.pypa.io/en/stable/installing/) installed and ```sudo pip install lizard```)
65+
- [OCLint](http://oclint-docs.readthedocs.io/en/stable/) installed. Version 0.11.0 recommended (0.13.0 since Xcode 9).
66+
- [Faux Pas](http://fauxpasapp.com/) command line tools installed (optional)
5967

6068
### Installation of xcpretty with JUnit reports fix
6169

build-and-deploy.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
#
3-
# Swift SonarQube Plugin - Enables analysis of Swift projects into SonarQube.
3+
# Swift SonarQube Plugin - Enables analysis of Swift and Objective-C projects into SonarQube.
44
# Copyright © 2015 Backelite (${email})
55
#
66
# This program is free software: you can redistribute it and/or modify
@@ -36,7 +36,7 @@ fi
3636
# Deploy new version of plugin in Sonar dir
3737
rm sonar-swift-plugin/target/*sources.jar
3838
rm $SONARQUBE_HOME/extensions/plugins/backelite-sonar-swift*
39-
cp sonar-swift-plugin/target/*.jar $SONARQUBE_HOME/extensions/plugins
39+
cp sonar-swift-plugin/target/backelite*.jar $SONARQUBE_HOME/extensions/plugins
4040
rm $SONARQUBE_HOME/extensions/plugins/*sources.jar
4141

4242
# Stop/start Sonar

commons/pom.xml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
commons - Enables analysis of Swift and Objective-C projects into SonarQube.
5+
Copyright © 2015 Backelite (${email})
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU Lesser General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
-->
21+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xmlns="http://maven.apache.org/POM/4.0.0"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<parent>
25+
<artifactId>backelite-swift</artifactId>
26+
<groupId>com.backelite.sonarqube</groupId>
27+
<version>0.3.8</version>
28+
</parent>
29+
<modelVersion>4.0.0</modelVersion>
30+
31+
<groupId>com.backelite.sonarqube</groupId>
32+
<artifactId>commons</artifactId>
33+
34+
<dependencies>
35+
36+
<dependency>
37+
<groupId>org.sonarsource.sslr</groupId>
38+
<artifactId>sslr-core</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
42+
<artifactId>sslr-squid-bridge</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>commons-lang</groupId>
46+
<artifactId>commons-lang</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>commons-io</groupId>
50+
<artifactId>commons-io</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>ch.qos.logback</groupId>
54+
<artifactId>logback-classic</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.google.guava</groupId>
58+
<artifactId>guava</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.google.code.gson</groupId>
62+
<artifactId>gson</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>ant</groupId>
66+
<artifactId>ant</artifactId>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>com.googlecode.json-simple</groupId>
71+
<artifactId>json-simple</artifactId>
72+
</dependency>
73+
74+
<!-- Test dependencies -->
75+
<dependency>
76+
<groupId>junit</groupId>
77+
<artifactId>junit</artifactId>
78+
<scope>compile</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.mockito</groupId>
82+
<artifactId>mockito-all</artifactId>
83+
<scope>compile</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.assertj</groupId>
87+
<artifactId>assertj-core</artifactId>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.sonarsource.sonarqube</groupId>
91+
<artifactId>sonar-testing-harness</artifactId>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.sonarsource.sslr</groupId>
95+
<artifactId>sslr-testing-harness</artifactId>
96+
<scope>compile</scope>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.sonarsource.sonarlint.core</groupId>
100+
<artifactId>sonarlint-core</artifactId>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.sonarsource.orchestrator</groupId>
104+
<artifactId>sonar-orchestrator</artifactId>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.sonarsource.sonarqube</groupId>
108+
<artifactId>sonar-plugin-api</artifactId>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.slf4j</groupId>
112+
<artifactId>slf4j-api</artifactId>
113+
</dependency>
114+
115+
</dependencies>
116+
117+
118+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* commons - Enables analysis of Swift and Objective-C projects into SonarQube.
3+
* Copyright © 2015 Backelite (${email})
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.backelite.sonarqube.commons;
19+
20+
/**
21+
* Created by gillesgrousset on 23/08/2018.
22+
*/
23+
public final class Constants {
24+
25+
// Common constants
26+
public static final String FALSE = "false";
27+
28+
public static final String PROPERTY_PREFIX = "sonar.swift";
29+
30+
public static final String TEST_FRAMEWORK_KEY = PROPERTY_PREFIX + ".testframework";
31+
public static final String TEST_FRAMEWORK_DEFAULT = "ghunit";
32+
33+
}

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/SwiftSurefireParser.java renamed to commons/src/main/java/com/backelite/sonarqube/commons/surefire/BaseSurefireParser.java

+25-57
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* backelite-sonar-swift-plugin - Enables analysis of Swift projects into SonarQube.
2+
* commons - Enables analysis of Swift and Objective-C projects into SonarQube.
33
* Copyright © 2015 Backelite (${email})
44
*
55
* This program is free software: you can redistribute it and/or modify
@@ -15,15 +15,12 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package org.sonar.plugins.swift.surefire;
18+
package com.backelite.sonarqube.commons.surefire;
1919

20-
import com.google.common.collect.ImmutableList;
21-
import org.apache.commons.lang.StringUtils;
2220
import org.slf4j.Logger;
2321
import org.slf4j.LoggerFactory;
2422
import org.sonar.api.batch.SensorContext;
2523
import org.sonar.api.batch.fs.FileSystem;
26-
import org.sonar.api.batch.fs.InputFile;
2724
import org.sonar.api.component.ResourcePerspectives;
2825
import org.sonar.api.measures.CoreMetrics;
2926
import org.sonar.api.measures.Metric;
@@ -32,33 +29,42 @@
3229
import org.sonar.api.test.TestCase;
3330
import org.sonar.api.utils.ParsingUtils;
3431
import org.sonar.api.utils.StaxParser;
35-
import org.sonar.plugins.swift.surefire.data.SurefireStaxHandler;
36-
import org.sonar.plugins.swift.surefire.data.UnitTestClassReport;
37-
import org.sonar.plugins.swift.surefire.data.UnitTestIndex;
38-
import org.sonar.plugins.swift.surefire.data.UnitTestResult;
3932

4033
import javax.annotation.Nullable;
4134
import javax.xml.stream.XMLStreamException;
4235
import java.io.File;
4336
import java.io.FilenameFilter;
44-
import java.util.List;
4537
import java.util.Map;
4638

39+
/**
40+
* Created by gillesgrousset on 28/08/2018.
41+
*/
42+
public abstract class BaseSurefireParser {
4743

48-
public final class SwiftSurefireParser {
49-
50-
private static final Logger LOGGER = LoggerFactory.getLogger(SwiftSurefireParser.class);
44+
protected static final Logger LOGGER = LoggerFactory.getLogger(BaseSurefireParser.class);
5145

52-
private final FileSystem fileSystem;
53-
private final SensorContext context;
54-
private final ResourcePerspectives perspectives;
46+
protected final FileSystem fileSystem;
47+
protected final SensorContext context;
48+
protected final ResourcePerspectives perspectives;
5549

56-
public SwiftSurefireParser(FileSystem fileSystem, ResourcePerspectives perspectives, SensorContext context) {
50+
protected BaseSurefireParser(FileSystem fileSystem, ResourcePerspectives perspectives, SensorContext context) {
5751
this.fileSystem = fileSystem;
5852
this.perspectives = perspectives;
5953
this.context = context;
6054
}
6155

56+
private static void parseFiles(File[] reports, UnitTestIndex index) {
57+
SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
58+
StaxParser parser = new StaxParser(staxParser, false);
59+
for (File report : reports) {
60+
try {
61+
parser.parse(report);
62+
} catch (XMLStreamException e) {
63+
throw new IllegalStateException("Fail to parse the Surefire report: " + report, e);
64+
}
65+
}
66+
}
67+
6268
public void collect(File reportsDir) {
6369

6470

@@ -95,18 +101,6 @@ private void parseFiles(File[] reports) {
95101
save(index);
96102
}
97103

98-
private static void parseFiles(File[] reports, UnitTestIndex index) {
99-
SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
100-
StaxParser parser = new StaxParser(staxParser, false);
101-
for (File report : reports) {
102-
try {
103-
parser.parse(report);
104-
} catch (XMLStreamException e) {
105-
throw new IllegalStateException("Fail to parse the Surefire report: " + report, e);
106-
}
107-
}
108-
}
109-
110104
private void save(UnitTestIndex index) {
111105
long negativeTimeTestNumber = 0;
112106

@@ -156,34 +150,8 @@ protected void saveResults(Resource testFile, UnitTestClassReport report) {
156150
}
157151
}
158152

159-
@Nullable public Resource getUnitTestResource(String classname) {
160-
String fileName = classname.replace('.', '/') + ".swift";
161-
String wildcardFileName = classname.replace(".", "/**/") + ".swift";
162-
163-
InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasPath(fileName));
164-
165-
/*
166-
* Most xcodebuild JUnit parsers don't include the path to the class in the class field, so search for it if it
167-
* wasn't found in the root.
168-
*/
169-
if (inputFile == null) {
170-
List<InputFile> files = ImmutableList.copyOf(fileSystem.inputFiles(fileSystem.predicates().and(
171-
fileSystem.predicates().hasType(InputFile.Type.TEST),
172-
fileSystem.predicates().matchesPathPattern("**/" + wildcardFileName))));
173-
174-
if (files.isEmpty()) {
175-
LOGGER.info("Unable to locate test source file {}", wildcardFileName);
176-
} else {
177-
/*
178-
* Lazily get the first file, since we wouldn't be able to determine the correct one from just the
179-
* test class name in the event that there are multiple matches.
180-
*/
181-
inputFile = files.get(0);
182-
}
183-
}
184-
185-
return inputFile == null ? null : context.getResource(inputFile);
186-
}
153+
@Nullable
154+
public abstract Resource getUnitTestResource(String classname);
187155

188156
private void saveMeasure(Resource resource, Metric metric, double value) {
189157
if (!Double.isNaN(value)) {

0 commit comments

Comments
 (0)