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

Commit

Permalink
Merge commit '794c8f4ef76ee559a1af5f34cbbbc5943ca65503' into 0.4.4-volvo
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Timothy G. Rundle committed May 23, 2019
2 parents b727416 + 794c8f4 commit 78982b7
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 131 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In SonarQube under Quality Profiles the used Linter can be specified by selectin
| Complexity |YES |Uses [Lizard](https://github.com/terryyin/lizard)| Uses [Lizard](https://github.com/terryyin/lizard)|
| Design |NO | | |
| Documentation |YES | | |
| Duplications |YES | | |
| Duplications |Only on Sonarqube < 7.3 | | |
| 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)|
| Size |YES | | |
| Tests |YES | Uses xcodebuild + xcpretty [xcpretty](https://github.com/supermarin/xcpretty) | Not Supported |
Expand Down
4 changes: 0 additions & 4 deletions objclang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class ObjectiveCSquidSensor implements Sensor {
public ObjectiveCSquidSensor(SensorContext context, PathResolver pathResolver, CheckFactory checkFactory) {
this.context = context;
this.pathResolver = pathResolver;
this.checks = checkFactory.<SquidCheck<ObjectiveCGrammar>>create(CheckList.REPOSITORY_KEY).addAnnotatedChecks((Iterable<Class>)CheckList.getChecks());
this.checks = checkFactory.<SquidCheck<ObjectiveCGrammar>>create(CheckList.REPOSITORY_KEY).addAnnotatedChecks((Iterable<Class>) CheckList.getChecks());
}

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

private void saveMeasures(InputFile inputFile, SourceFile squidFile) {
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.FILES, squidFile.getInt(ObjectiveCMetric.FILES));
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.LINES, squidFile.getInt(ObjectiveCMetric.LINES));
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.NCLOC, squidFile.getInt(ObjectiveCMetric.LINES_OF_CODE));
MeasureUtil.saveMeasure(context, inputFile, CoreMetrics.STATEMENTS, squidFile.getInt(ObjectiveCMetric.STATEMENTS));
Expand Down Expand Up @@ -137,7 +136,7 @@ public void execute(SensorContext context) {
FilePredicate isMain = context.fileSystem().predicates().hasType(InputFile.Type.MAIN);
FilePredicate and = context.fileSystem().predicates().and(hasObjC, isMain);
List<File> files = new ArrayList<>();
for(InputFile inf : context.fileSystem().inputFiles(and)){
for (InputFile inf : context.fileSystem().inputFiles(and)) {
files.add(inf.file());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
import org.apache.tools.ant.DirectoryScanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.config.Settings;

import java.io.File;

Expand Down
14 changes: 4 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,16 @@

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

<sonarQubeMinVersion>6.7</sonarQubeMinVersion>
<sonarQubeMinVersion>7.0</sonarQubeMinVersion>

<assertj.version>3.5.2</assertj.version>
<guava.version>17.0</guava.version>
<junit.version>4.10</junit.version>
<logback.version>1.0.13</logback.version>
<mockito.version>1.9.0</mockito.version>
<slf4j.version>1.7.21</slf4j.version>
<sonar.version>7.3</sonar.version>
<sonar-orchestrator.version>3.22.0.1791</sonar-orchestrator.version>
<sonarlint.version>4.0.0.2052</sonarlint.version>
<sonar.version>7.7</sonar.version>
<sonar-orchestrator.version>3.24.0.1993</sonar-orchestrator.version>
<sonarlint.version>4.1.0.2218</sonarlint.version>
<sslr.version>1.23</sslr.version>
<sslr-squid-bridge.version>2.6.1</sslr-squid-bridge.version>
<ant.version>1.6</ant.version>
Expand Down Expand Up @@ -158,11 +157,6 @@
<version>${ant.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.measures.CoreMetrics;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -115,23 +116,63 @@ private void parseMeasure(String type, NodeList itemList) {

NodeList values = itemElement.getElementsByTagName(VALUE);
if (FILE_MEASURE.equalsIgnoreCase(type)) {
addComplexityFileMeasures(name, values);
InputFile inputFile = getFile(name);
addComplexityFileMeasures(inputFile, values);
} else if (FUNCTION_MEASURE.equalsIgnoreCase(type)) {
addComplexityFunctionMeasures(new SwiftFunction(name), values);
addComplexityFunctionMeasures(new SwiftFunction(0,name), values);
}
}
}
}

private void addComplexityFileMeasures(String fileName, NodeList values) {
LOGGER.debug("File measures for {}",fileName);
private InputFile getFile(String fileName){
FilePredicate fp = context.fileSystem().predicates().hasRelativePath(fileName);
if (!context.fileSystem().hasFiles(fp)) {
LOGGER.warn("file not included in sonar {}", fileName);
return;
return null;
}
InputFile component = context.fileSystem().inputFile(fp);
return context.fileSystem().inputFile(fp);
}

static class SwiftFunction extends DefaultInputComponent implements InputComponent {
private String name;
private String key;
private String file;
private int lineNumber;
SwiftFunction(int scannerId, String name) {
super(scannerId);
String[] vals = name.split(" at ");
if (vals.length >= 2) {
this.name = vals[0].replaceAll("\\W","");

if (vals[1].contains(":")) {
String[] sp = vals[1].split(":");
this.file = sp[0].substring(0,sp[0].lastIndexOf("."));
this.lineNumber = Integer.parseInt(sp[1]);
} else {
this.file = vals[1];
this.lineNumber = 0;
}

this.key = String.format("%s.%s:%d", this.file, this.name, this.lineNumber);
} else {
this.key = name;
}
}
@Override
public String key() {
return key;
}
@Override
public boolean isFile() {
return false;
}
}

private void addComplexityFileMeasures(InputFile component, NodeList values) {
LOGGER.debug("File measures for {}",component.toString());
int complexity = Integer.parseInt(values.item(cyclomaticComplexityIndex).getTextContent());

context.<Integer>newMeasure()
.on(component)
.forMetric(CoreMetrics.COMPLEXITY)
Expand All @@ -153,8 +194,8 @@ private void addComplexityFileMeasures(String fileName, NodeList values) {
.save();
}

private void addComplexityFunctionMeasures(SwiftFunction component, NodeList values) {
LOGGER.debug("Function measures for {}",component.key);
private void addComplexityFunctionMeasures(InputComponent component, NodeList values) {
LOGGER.debug("Function measures for {}",component.key());
int complexity = Integer.parseInt(values.item(cyclomaticComplexityIndex).getTextContent());
context.<Integer>newMeasure()
.on(component)
Expand All @@ -169,53 +210,4 @@ private void addComplexityFunctionMeasures(SwiftFunction component, NodeList val
.withValue(numberOfLines)
.save();
}

private static class SwiftFunction implements InputModule {
private String name;
private String key;
private String file;
private int lineNumber;

public SwiftFunction(String name) {
String[] vals = name.split(" at ");
if (vals.length >= 2) {
this.name = vals[0].replaceAll("\\W","");

if (vals[1].contains(":")) {
String[] sp = vals[1].split(":");
this.file = sp[0].substring(0,sp[0].lastIndexOf("."));
this.lineNumber = Integer.parseInt(sp[1]);
} else {
this.file = vals[1];
this.lineNumber = 0;
}

this.key = String.format("%s.%s:%d", this.file, this.name, this.lineNumber);
} else {
this.key = name;
}
}

@Override
public String key() {
return key;
}

public String getName() {
return name;
}

public String getFile() {
return file;
}

public int getLineNumber() {
return lineNumber;
}

@Override
public boolean isFile() {
return false;
}
}
}
4 changes: 2 additions & 2 deletions sonar-swift-plugin/src/main/shell/run-sonar-swift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ if [[ "$workspaceFile" != "" ]] ; then
else
buildCmdPrefix="-project $projectFile"
fi
buildCmd=($XCODEBUILD_CMD clean build $buildCmdPrefix -scheme $appScheme)
buildCmd=($XCODEBUILD_CMD clean build $buildCmdPrefix -scheme "$appScheme")
if [[ ! -z "$destinationSimulator" ]]; then
buildCmd+=(-destination "$destinationSimulator" -destination-timeout 360 COMPILER_INDEX_STORE_ENABLE=NO)
fi
Expand Down Expand Up @@ -445,7 +445,7 @@ if [ "$fauxpas" = "on" ] && [ "$hasObjC" = "yes" ]; then
if [ "$projectCount" = "1" ]
then

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


else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* backelite-sonar-swift-plugin - Enables analysis of Swift and Objective-C projects into SonarQube.
* Copyright © 2015 Backelite (${email})
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.backelite.sonarqube.swift.complexity;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.batch.fs.*;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.measure.NewMeasure;

import java.io.File;
import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class LizardReportParserTest {

@Mock
SensorContext sensorContext;

@Mock
FileSystem fileSystem;

@Mock
FilePredicates filePredicates;

@Mock
FilePredicate filePredicate;

@Mock
InputFile inputFile;

@Mock
NewMeasure<Integer> newMeasure;

@Captor
ArgumentCaptor<String> hasRelativePathCaptor;

@Captor
ArgumentCaptor<InputComponent> onCaptor;

@Captor
ArgumentCaptor<Metric<Integer>> forMetricCaptor;

@Captor
ArgumentCaptor<Integer> withValueCaptor;


@Test
public void parseSimpleFile() {

LizardReportParser parser = new LizardReportParser(sensorContext);
File xmlFile = new File("src/test/resources/lizard-report.xml");

when(sensorContext.<Integer>newMeasure()).thenReturn(newMeasure);
when(newMeasure.on(onCaptor.capture())).thenReturn(newMeasure);
when(newMeasure.forMetric(forMetricCaptor.capture())).thenReturn(newMeasure);
when(newMeasure.withValue(withValueCaptor.capture())).thenReturn(newMeasure);

when(sensorContext.fileSystem()).thenReturn(fileSystem);
when(fileSystem.predicates()).thenReturn(filePredicates);
when(filePredicates.hasRelativePath(hasRelativePathCaptor.capture())).thenReturn(filePredicate);
when(fileSystem.hasFiles(filePredicate)).thenReturn(true);
when(fileSystem.inputFile(filePredicate)).thenReturn(inputFile);

parser.parseReport(xmlFile);

assertEquals(5, onCaptor.getAllValues().size());
assertEquals(5, forMetricCaptor.getAllValues().size());

assertEquals(Arrays.asList(1, 4, 8, 5, 46), withValueCaptor.getAllValues());
assertEquals(Arrays.asList("./Folder With Space/File With Space.swift"), hasRelativePathCaptor.getAllValues());
}

}
Loading

0 comments on commit 78982b7

Please sign in to comment.