Skip to content

Commit

Permalink
Merge remote-tracking branch 'sig-eng/sonar17'
Browse files Browse the repository at this point in the history
  • Loading branch information
snps-acho committed Oct 9, 2019
2 parents 81e5867 + 97977ee commit ad4a0c6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The Coverity Sonar Plugin automatically import issues from Coverity Connect into
Coverity® Sonar Plug-in Installation and Configuration Guide
============================================================

Version 1.7.2
Version 1.7.3

This guide is intended to assist you with the installation and
configuration of the Coverity Sonar plug-in. Once completed, you will be
Expand All @@ -22,16 +22,16 @@ Sonar plug-in.

| **Software** | **Supported versions** |
|------------------|------------------------|
| SonarQube | 6.7.5+ |
| SonarQube Scanner| 3.0+ |
| SonarQube | 6.7.5 - 7.9.1 |
| SonarQube Scanner| 3.0 - 4.0 |
| Coverity Connect | 8.0+ |

Installing the Coverity Sonar Plug-in
=====================================

To install the Coverity Sonar plug-in, complete the following steps.

1. Ensure that you have SonarQube v6.7.5+ and SonarQube Scanner v3.0 installed.
1. Ensure that you have SonarQube(v6.7.5 ~ v7.9.1) and SonarQube Scanner(v3.0 ~ v4.0) installed.
Sonar installation and setup instructions are located at
<http://docs.sonarqube.org/display/SONAR/Setup+and+Upgrade>.

Expand Down Expand Up @@ -81,7 +81,7 @@ projects.
3. Click on **Quality Profiles**.

4. Change the Quality Profile option for your project to
*Coverity (&lt;language&gt;)*, and click **Update.**
*Coverity(&lt;language&gt;)*, and click **Update.**

5. Choose **Configuration &gt; General Settings**.

Expand Down Expand Up @@ -135,10 +135,6 @@ See below for a complete example sonar-project.properties file.
>
> sonar.sources=.
>
> \# The profile used by sonar can be specified either on the UI or by:
>
> \# sonar.profile=Coverity(cov-cpp)
>
> \# Encoding of the source files
>
> sonar.sourceEncoding=UTF-8
Expand Down Expand Up @@ -243,6 +239,10 @@ If you have any questions or issues with the Coverity plugin, contact <coverity-
Changelog
=========

* __1.7.3__
* Fixed an issue where C/C++ project is displayed as an empty project in the SonarQube after running Coverity SonarQube plugin. (SQP-144)
* "sonar.coverity.cov-cpp.suffixes" property is declared as multi-value property. (SQP-136)

* __1.7.2__
* Coverity SonarQube plugin now support importing defects from configured stream. (SQP-130, SQP-131)
* Coverity SonarQube plugin now support SonarQube 7.9LTS. (SQP-137)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.sonar.plugins.coverity</groupId>
<artifactId>coverity-sonar-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>1.7.2</version>
<version>1.7.3</version>

<name>Coverity</name>
<description>Imports Coverity defects into SonarQube</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private List getExtensions() {
.description("Comma-separated list of source file suffixes to retrieve issues from Coverity Connect.")
.defaultValue(CppLanguage.DEFAULT_SUFFIXES)
.subCategory("Languages")
.type(PropertyType.STRING)
.multiValues(true)
.index(1)
.build(),
/*
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/sonar/plugins/coverity/batch/CoveritySensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.sonar.api.batch.sensor.issue.NewIssue;
import org.sonar.api.batch.sensor.issue.NewIssueLocation;
import org.sonar.api.config.Configuration;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.rule.RuleKey;
import org.sonar.plugins.coverity.CoverityPlugin;
import org.sonar.plugins.coverity.base.CoverityPluginMetrics;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class CoveritySensor implements Sensor {
private String platform;
private CIMClientFactory cimClientFactory;
private HashMap<String, InputFile> localInputFiles;
private HashMap<String, Integer> inputFileLines;

public CoveritySensor(CIMClientFactory cimClientFactory) {
this.cimClientFactory = cimClientFactory;
Expand All @@ -77,6 +79,7 @@ public void describe(SensorDescriptor descriptor) {
public void execute(SensorContext context) {
Configuration config = context.config();
localInputFiles = new HashMap<String, InputFile>();
inputFileLines = new HashMap<String, Integer>();

boolean enabled = config.getBoolean(CoverityPlugin.COVERITY_ENABLE).orElse(false);

Expand All @@ -85,6 +88,8 @@ public void execute(SensorContext context) {
int mediumImpactDefectsCounter = 0;
int lowImpactDefectsCounter = 0;

HashSet<String> inputFileSet = new HashSet<String>();

LOG.info(CoverityPlugin.COVERITY_ENABLE + "=" + enabled);

if(!enabled) {
Expand Down Expand Up @@ -240,6 +245,8 @@ public void execute(SensorContext context) {
if (!validateInputFile(inputFile, mainEventFilePath, mddo.getCid())){
continue;
}


}

String subcategory = dido.getSubcategory();
Expand All @@ -250,6 +257,7 @@ public void execute(SensorContext context) {

ActiveRule ar = findActiveRule(context, dido.getDomain(), dido.getCheckerName(), subcategory, inputFile.language());


LOG.debug("ar=" + ar);
if(ar != null) {
LOG.debug("instance=" + instance);
Expand Down Expand Up @@ -421,6 +429,15 @@ private void getCoverityLogoMeasures(SensorContext sensorContext, CIMClient clie
.on(sensorContext.module())
.withValue(lowImpactDefects)
.save();

int lines = 0;
Iterator iterator = inputFileLines.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry mapElement = (Map.Entry)iterator.next();
lines = lines + (int)mapElement.getValue();
}

sensorContext.<Integer>newMeasure().forMetric(CoreMetrics.NCLOC).on(sensorContext.module()).withValue(lines).save();
}

protected ActiveRule findActiveRule(SensorContext context, String domain, String checkerName, String subCategory, String lang) {
Expand Down Expand Up @@ -518,6 +535,10 @@ protected InputFile findLocalFile(SensorContext context, String filePath, List<F
}
}

if (inputFile != null && !inputFileLines.containsKey(filePath)){
inputFileLines.put(filePath, inputFile.lines());
}

return inputFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.rule.RuleKey;
import org.sonar.plugins.coverity.CoverityPlugin;
import org.sonar.plugins.coverity.base.CoverityPluginMetrics;
Expand Down Expand Up @@ -180,6 +181,10 @@ public void testExecute_savesIssue_FromStream() {
assertEquals(ruleKey, issue.ruleKey());
assertEquals(inputFile, issue.primaryLocation().inputComponent());
assertEquals(expectedIssueMessage, issue.primaryLocation().message());

Measure measure = sensorContextTester.measure("projectKey", CoreMetrics.NCLOC);
assertNotNull(measure);
assertEquals(inputFile.lines(), measure.value());
}

@Test
Expand Down

0 comments on commit ad4a0c6

Please sign in to comment.