Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit 78982b7

Browse files
author
Timothy G. Rundle
committed
Merge commit '794c8f4ef76ee559a1af5f34cbbbc5943ca65503' into 0.4.4-volvo
* commit '794c8f4ef76ee559a1af5f34cbbbc5943ca65503': fix for cast exception licensing format update version update thanks @timothy-volvoIdean#207 version change thanks tim imports imports merged pull request code from main fix a space issue for lizardReport revert directory stream to original and keep sensors consistent # Conflicts: # commons/pom.xml # commons/src/main/java/com/backelite/sonarqube/commons/surefire/SurefireSensor.java # objclang/pom.xml # objclang/src/main/java/com/backelite/sonarqube/objectivec/ObjectiveCSquidSensor.java # objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/oclint/OCLintParser.java # pom.xml # sonar-swift-plugin/pom.xml # sonar-swift-plugin/src/main/java/com/backelite/sonarqube/swift/complexity/LizardReportParser.java # sonar-swift-plugin/src/test/resources/lizard-report.xml # swiftlang/pom.xml # swiftlang/src/main/java/com/backelite/sonarqube/swift/SwiftSquidSensor.java # swiftlang/src/main/resources/org/sonar/plugins/swiftlint/profile-swiftlint.xml # swiftlang/src/main/resources/org/sonar/plugins/swiftlint/rules.json
2 parents b727416 + 794c8f4 commit 78982b7

File tree

14 files changed

+507
-131
lines changed

14 files changed

+507
-131
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ In SonarQube under Quality Profiles the used Linter can be specified by selectin
3030
| Complexity |YES |Uses [Lizard](https://github.com/terryyin/lizard)| Uses [Lizard](https://github.com/terryyin/lizard)|
3131
| Design |NO | | |
3232
| Documentation |YES | | |
33-
| Duplications |YES | | |
33+
| Duplications |Only on Sonarqube < 7.3 | | |
3434
| 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)|
3535
| Size |YES | | |
3636
| Tests |YES | Uses xcodebuild + xcpretty [xcpretty](https://github.com/supermarin/xcpretty) | Not Supported |

objclang/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@
5656
<groupId>ant</groupId>
5757
<artifactId>ant</artifactId>
5858
</dependency>
59-
<dependency>
60-
<groupId>com.google.guava</groupId>
61-
<artifactId>guava</artifactId>
62-
</dependency>
6359
<dependency>
6460
<groupId>com.googlecode.json-simple</groupId>
6561
<artifactId>json-simple</artifactId>

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class ObjectiveCSquidSensor implements Sensor {
6666
public ObjectiveCSquidSensor(SensorContext context, PathResolver pathResolver, CheckFactory checkFactory) {
6767
this.context = context;
6868
this.pathResolver = pathResolver;
69-
this.checks = checkFactory.<SquidCheck<ObjectiveCGrammar>>create(CheckList.REPOSITORY_KEY).addAnnotatedChecks((Iterable<Class>)CheckList.getChecks());
69+
this.checks = checkFactory.<SquidCheck<ObjectiveCGrammar>>create(CheckList.REPOSITORY_KEY).addAnnotatedChecks((Iterable<Class>) CheckList.getChecks());
7070
}
7171

7272
private ObjectiveCConfiguration createConfiguration() {
@@ -85,7 +85,6 @@ private void save(Collection<SourceCode> squidSourceFiles) {
8585
}
8686

8787
private void saveMeasures(InputFile inputFile, SourceFile squidFile) {
88-
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.FILES, squidFile.getInt(ObjectiveCMetric.FILES));
8988
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.LINES, squidFile.getInt(ObjectiveCMetric.LINES));
9089
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.NCLOC, squidFile.getInt(ObjectiveCMetric.LINES_OF_CODE));
9190
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.STATEMENTS, squidFile.getInt(ObjectiveCMetric.STATEMENTS));
@@ -137,7 +136,7 @@ public void execute(SensorContext context) {
137136
FilePredicate isMain = context.fileSystem().predicates().hasType(InputFile.Type.MAIN);
138137
FilePredicate and = context.fileSystem().predicates().and(hasObjC, isMain);
139138
List<File> files = new ArrayList<>();
140-
for(InputFile inf : context.fileSystem().inputFiles(and)){
139+
for (InputFile inf : context.fileSystem().inputFiles(and)) {
141140
files.add(inf.file());
142141
}
143142

objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/fauxpas/FauxPasSensor.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
import org.apache.tools.ant.DirectoryScanner;
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
25-
import org.sonar.api.batch.fs.FileSystem;
2625
import org.sonar.api.batch.fs.InputFile;
2726
import org.sonar.api.batch.sensor.Sensor;
2827
import org.sonar.api.batch.sensor.SensorContext;
2928
import org.sonar.api.batch.sensor.SensorDescriptor;
30-
import org.sonar.api.component.ResourcePerspectives;
31-
import org.sonar.api.config.Settings;
3229

3330
import java.io.File;
3431

pom.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,16 @@
8888

8989
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
9090

91-
<sonarQubeMinVersion>6.7</sonarQubeMinVersion>
91+
<sonarQubeMinVersion>7.0</sonarQubeMinVersion>
9292

9393
<assertj.version>3.5.2</assertj.version>
94-
<guava.version>17.0</guava.version>
9594
<junit.version>4.10</junit.version>
9695
<logback.version>1.0.13</logback.version>
9796
<mockito.version>1.9.0</mockito.version>
9897
<slf4j.version>1.7.21</slf4j.version>
99-
<sonar.version>7.3</sonar.version>
100-
<sonar-orchestrator.version>3.22.0.1791</sonar-orchestrator.version>
101-
<sonarlint.version>4.0.0.2052</sonarlint.version>
98+
<sonar.version>7.7</sonar.version>
99+
<sonar-orchestrator.version>3.24.0.1993</sonar-orchestrator.version>
100+
<sonarlint.version>4.1.0.2218</sonarlint.version>
102101
<sslr.version>1.23</sslr.version>
103102
<sslr-squid-bridge.version>2.6.1</sslr-squid-bridge.version>
104103
<ant.version>1.6</ant.version>
@@ -158,11 +157,6 @@
158157
<version>${ant.version}</version>
159158
</dependency>
160159

161-
<dependency>
162-
<groupId>com.google.guava</groupId>
163-
<artifactId>guava</artifactId>
164-
<version>${guava.version}</version>
165-
</dependency>
166160
<dependency>
167161
<groupId>com.googlecode.json-simple</groupId>
168162
<artifactId>json-simple</artifactId>

sonar-swift-plugin/src/main/java/com/backelite/sonarqube/swift/complexity/LizardReportParser.java

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import org.slf4j.Logger;
2121
import org.slf4j.LoggerFactory;
2222
import org.sonar.api.batch.fs.FilePredicate;
23+
import org.sonar.api.batch.fs.InputComponent;
2324
import org.sonar.api.batch.fs.InputFile;
24-
import org.sonar.api.batch.fs.InputModule;
25+
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
2526
import org.sonar.api.batch.sensor.SensorContext;
2627
import org.sonar.api.measures.CoreMetrics;
2728
import org.w3c.dom.Document;
@@ -115,23 +116,63 @@ private void parseMeasure(String type, NodeList itemList) {
115116

116117
NodeList values = itemElement.getElementsByTagName(VALUE);
117118
if (FILE_MEASURE.equalsIgnoreCase(type)) {
118-
addComplexityFileMeasures(name, values);
119+
InputFile inputFile = getFile(name);
120+
addComplexityFileMeasures(inputFile, values);
119121
} else if (FUNCTION_MEASURE.equalsIgnoreCase(type)) {
120-
addComplexityFunctionMeasures(new SwiftFunction(name), values);
122+
addComplexityFunctionMeasures(new SwiftFunction(0,name), values);
121123
}
122124
}
123125
}
124126
}
125127

126-
private void addComplexityFileMeasures(String fileName, NodeList values) {
127-
LOGGER.debug("File measures for {}",fileName);
128+
private InputFile getFile(String fileName){
128129
FilePredicate fp = context.fileSystem().predicates().hasRelativePath(fileName);
129130
if (!context.fileSystem().hasFiles(fp)) {
130131
LOGGER.warn("file not included in sonar {}", fileName);
131-
return;
132+
return null;
132133
}
133-
InputFile component = context.fileSystem().inputFile(fp);
134+
return context.fileSystem().inputFile(fp);
135+
}
136+
137+
static class SwiftFunction extends DefaultInputComponent implements InputComponent {
138+
private String name;
139+
private String key;
140+
private String file;
141+
private int lineNumber;
142+
SwiftFunction(int scannerId, String name) {
143+
super(scannerId);
144+
String[] vals = name.split(" at ");
145+
if (vals.length >= 2) {
146+
this.name = vals[0].replaceAll("\\W","");
147+
148+
if (vals[1].contains(":")) {
149+
String[] sp = vals[1].split(":");
150+
this.file = sp[0].substring(0,sp[0].lastIndexOf("."));
151+
this.lineNumber = Integer.parseInt(sp[1]);
152+
} else {
153+
this.file = vals[1];
154+
this.lineNumber = 0;
155+
}
156+
157+
this.key = String.format("%s.%s:%d", this.file, this.name, this.lineNumber);
158+
} else {
159+
this.key = name;
160+
}
161+
}
162+
@Override
163+
public String key() {
164+
return key;
165+
}
166+
@Override
167+
public boolean isFile() {
168+
return false;
169+
}
170+
}
171+
172+
private void addComplexityFileMeasures(InputFile component, NodeList values) {
173+
LOGGER.debug("File measures for {}",component.toString());
134174
int complexity = Integer.parseInt(values.item(cyclomaticComplexityIndex).getTextContent());
175+
135176
context.<Integer>newMeasure()
136177
.on(component)
137178
.forMetric(CoreMetrics.COMPLEXITY)
@@ -153,8 +194,8 @@ private void addComplexityFileMeasures(String fileName, NodeList values) {
153194
.save();
154195
}
155196

156-
private void addComplexityFunctionMeasures(SwiftFunction component, NodeList values) {
157-
LOGGER.debug("Function measures for {}",component.key);
197+
private void addComplexityFunctionMeasures(InputComponent component, NodeList values) {
198+
LOGGER.debug("Function measures for {}",component.key());
158199
int complexity = Integer.parseInt(values.item(cyclomaticComplexityIndex).getTextContent());
159200
context.<Integer>newMeasure()
160201
.on(component)
@@ -169,53 +210,4 @@ private void addComplexityFunctionMeasures(SwiftFunction component, NodeList val
169210
.withValue(numberOfLines)
170211
.save();
171212
}
172-
173-
private static class SwiftFunction implements InputModule {
174-
private String name;
175-
private String key;
176-
private String file;
177-
private int lineNumber;
178-
179-
public SwiftFunction(String name) {
180-
String[] vals = name.split(" at ");
181-
if (vals.length >= 2) {
182-
this.name = vals[0].replaceAll("\\W","");
183-
184-
if (vals[1].contains(":")) {
185-
String[] sp = vals[1].split(":");
186-
this.file = sp[0].substring(0,sp[0].lastIndexOf("."));
187-
this.lineNumber = Integer.parseInt(sp[1]);
188-
} else {
189-
this.file = vals[1];
190-
this.lineNumber = 0;
191-
}
192-
193-
this.key = String.format("%s.%s:%d", this.file, this.name, this.lineNumber);
194-
} else {
195-
this.key = name;
196-
}
197-
}
198-
199-
@Override
200-
public String key() {
201-
return key;
202-
}
203-
204-
public String getName() {
205-
return name;
206-
}
207-
208-
public String getFile() {
209-
return file;
210-
}
211-
212-
public int getLineNumber() {
213-
return lineNumber;
214-
}
215-
216-
@Override
217-
public boolean isFile() {
218-
return false;
219-
}
220-
}
221213
}

sonar-swift-plugin/src/main/shell/run-sonar-swift.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ if [[ "$workspaceFile" != "" ]] ; then
283283
else
284284
buildCmdPrefix="-project $projectFile"
285285
fi
286-
buildCmd=($XCODEBUILD_CMD clean build $buildCmdPrefix -scheme $appScheme)
286+
buildCmd=($XCODEBUILD_CMD clean build $buildCmdPrefix -scheme "$appScheme")
287287
if [[ ! -z "$destinationSimulator" ]]; then
288288
buildCmd+=(-destination "$destinationSimulator" -destination-timeout 360 COMPILER_INDEX_STORE_ENABLE=NO)
289289
fi
@@ -445,7 +445,7 @@ if [ "$fauxpas" = "on" ] && [ "$hasObjC" = "yes" ]; then
445445
if [ "$projectCount" = "1" ]
446446
then
447447

448-
fauxpas -o json check $projectFile --workspace $workspaceFile --scheme $appScheme > sonar-reports/fauxpas.json
448+
fauxpas -o json check $projectFile --workspace $workspaceFile --scheme "$appScheme" > sonar-reports/fauxpas.json
449449

450450

451451
else
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* backelite-sonar-swift-plugin - 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.swift.complexity;
19+
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
import org.mockito.ArgumentCaptor;
23+
import org.mockito.Captor;
24+
import org.mockito.Mock;
25+
import org.mockito.runners.MockitoJUnitRunner;
26+
import org.sonar.api.batch.fs.*;
27+
import org.sonar.api.batch.measure.Metric;
28+
import org.sonar.api.batch.sensor.SensorContext;
29+
import org.sonar.api.batch.sensor.measure.NewMeasure;
30+
31+
import java.io.File;
32+
import java.util.Arrays;
33+
34+
import static org.junit.Assert.assertEquals;
35+
import static org.mockito.Mockito.when;
36+
37+
@RunWith(MockitoJUnitRunner.class)
38+
public class LizardReportParserTest {
39+
40+
@Mock
41+
SensorContext sensorContext;
42+
43+
@Mock
44+
FileSystem fileSystem;
45+
46+
@Mock
47+
FilePredicates filePredicates;
48+
49+
@Mock
50+
FilePredicate filePredicate;
51+
52+
@Mock
53+
InputFile inputFile;
54+
55+
@Mock
56+
NewMeasure<Integer> newMeasure;
57+
58+
@Captor
59+
ArgumentCaptor<String> hasRelativePathCaptor;
60+
61+
@Captor
62+
ArgumentCaptor<InputComponent> onCaptor;
63+
64+
@Captor
65+
ArgumentCaptor<Metric<Integer>> forMetricCaptor;
66+
67+
@Captor
68+
ArgumentCaptor<Integer> withValueCaptor;
69+
70+
71+
@Test
72+
public void parseSimpleFile() {
73+
74+
LizardReportParser parser = new LizardReportParser(sensorContext);
75+
File xmlFile = new File("src/test/resources/lizard-report.xml");
76+
77+
when(sensorContext.<Integer>newMeasure()).thenReturn(newMeasure);
78+
when(newMeasure.on(onCaptor.capture())).thenReturn(newMeasure);
79+
when(newMeasure.forMetric(forMetricCaptor.capture())).thenReturn(newMeasure);
80+
when(newMeasure.withValue(withValueCaptor.capture())).thenReturn(newMeasure);
81+
82+
when(sensorContext.fileSystem()).thenReturn(fileSystem);
83+
when(fileSystem.predicates()).thenReturn(filePredicates);
84+
when(filePredicates.hasRelativePath(hasRelativePathCaptor.capture())).thenReturn(filePredicate);
85+
when(fileSystem.hasFiles(filePredicate)).thenReturn(true);
86+
when(fileSystem.inputFile(filePredicate)).thenReturn(inputFile);
87+
88+
parser.parseReport(xmlFile);
89+
90+
assertEquals(5, onCaptor.getAllValues().size());
91+
assertEquals(5, forMetricCaptor.getAllValues().size());
92+
93+
assertEquals(Arrays.asList(1, 4, 8, 5, 46), withValueCaptor.getAllValues());
94+
assertEquals(Arrays.asList("./Folder With Space/File With Space.swift"), hasRelativePathCaptor.getAllValues());
95+
}
96+
97+
}

0 commit comments

Comments
 (0)