Skip to content

Commit 019fed1

Browse files
authored
Use new coverage API (#34)
1 parent fe8e54c commit 019fed1

File tree

29 files changed

+965
-338
lines changed

29 files changed

+965
-338
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!target/

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ Icon?
2626
Thumbs.db
2727
# Folder config file
2828
Desktop.ini
29+
its/plugin/projects/groovy-clover-sample/.sonar/*
30+
its/plugin/projects/reuseReport/.sonar/*

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ARG VERSION=latest
2+
FROM sonarqube:${VERSION}
3+
4+
COPY target/sonar-clover-plugin.jar /opt/sonarqube/extensions/plugins/

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
run-test: ## Allows to run all unit tests
22
@docker run --mount type=bind,src=$$(pwd),target=/usr/src -w /usr/src maven:alpine mvn test
33

4+
run-integration-platform: ## Allows to run local integrations test with docker
5+
@docker network create sonar || \
6+
docker build --build-arg VERSION=$$VERSION --tag test-instance . && \
7+
docker run -p 9000:9000 --name sonar-instance --net sonar test-instance
8+
9+
run-integration-test: ## Allows to push a report in integration platform
10+
@docker run --mount type=bind,src=$$(pwd)/its/integration,target=/usr/src -w /usr/src --net sonar maven:alpine \
11+
mvn clean clover:setup test clover:aggregate clover:clover sonar:sonar -Dsonar.sources=src -Dsonar.host.url=http://sonar-instance:9000
12+
413
build-package: ## Allows to build artifacts
514
@docker run --mount type=bind,src=$$(pwd),target=/usr/src -w /usr/src maven:alpine mvn package
615

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ Sonar Clover
33
[![Build Status](https://travis-ci.org/sfeir-open-source/sonar-clover.svg?branch=master)](https://travis-ci.org/sfeir-open-source/sonar-clover)
44

55
## Description / Features
6-
It provides the ability to feed SonarQube with code coverage data coming from Atlassian Clover.
6+
It provides the ability to feed SonarQube with code coverage data coming from Atlassian Clover or it's new open source version: [OpenClover](http://openclover.org/).
77

88
## Usage
99
To display code coverage data:
1010

11-
1. Prior to the SonarQube analysis, execute your unit tests and generate the Clover report.
12-
1. Import this report while running the SonarQube analysis by setting the sonar.clover.reportPath property to the path to the Clover report. The path may be absolute or relative to the project base directory.
11+
1. Prior to the SonarQube analysis, execute your unit tests and generate the [Clover report](http://openclover.org/doc/manual/latest/maven--quick-start-guide.html).
12+
13+
1. Import this report while running the SonarQube analysis by setting the sonar.clover.reportPath (using prior version to sonarQube version 6)
14+
or sonar.coverageReportPaths (sonarQube v7 or higher, FYI with this version, only the xml format is supported) property to the path to the Clover report.
15+
The path may be absolute or relative to the project base directory.
16+
17+
##

contributing.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Contributions
2+
3+
All contributions have to be test using a manual (for now) process
4+
5+
## Test
6+
7+
Each contributions should allows us to use this plugin in version LTS and Latest
8+
9+
In order to test with different version of SonarQube, you could use:
10+
```bash
11+
VERSION=<myVersion> make run-integration-platform
12+
```
13+
This command will start a sonarQube container with version : myVersion (`lts` or `latest` could be used)
14+
15+
And run
16+
```bash
17+
make run-integration-test
18+
```
19+
Which will do a mvn build on a test project and upload the report in the sonarQube container created above.

its/integration/pom.xml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.sonar.tests</groupId>
5+
<artifactId>integration</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Sonar tests - clover reuse report</name>
8+
<build>
9+
<pluginManagement>
10+
<plugins>
11+
<plugin>
12+
<groupId>org.apache.maven.plugins</groupId>
13+
<artifactId>maven-compiler-plugin</artifactId>
14+
<configuration>
15+
<source>1.8</source>
16+
<target>1.8</target>
17+
</configuration>
18+
</plugin>
19+
<plugin>
20+
<groupId>org.openclover</groupId>
21+
<artifactId>clover-maven-plugin</artifactId>
22+
<version>4.3.1</version>
23+
<configuration>
24+
<generateHtml>false</generateHtml>
25+
<generateXml>true</generateXml>
26+
</configuration>
27+
</plugin>
28+
</plugins>
29+
</pluginManagement>
30+
</build>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>junit</groupId>
35+
<artifactId>junit</artifactId>
36+
<version>4.7</version>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
</project>
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
public class DTO {
2+
private String item1;
3+
4+
private String item2;
5+
6+
private String item3;
7+
8+
private int value1;
9+
10+
private int value2;
11+
12+
private int value3;
13+
14+
public String getItem1() {
15+
return item1;
16+
}
17+
18+
public void setItem1(String item1) {
19+
this.item1 = item1;
20+
}
21+
22+
public String getItem2() {
23+
return item2;
24+
}
25+
26+
public void setItem2(String item2) {
27+
this.item2 = item2;
28+
}
29+
30+
public String getItem3() {
31+
return item3;
32+
}
33+
34+
public void setItem3(String item3) {
35+
this.item3 = item3;
36+
}
37+
38+
public int getValue1() {
39+
return value1;
40+
}
41+
42+
public void setValue1(int value1) {
43+
this.value1 = value1;
44+
}
45+
46+
public int getValue2() {
47+
return value2;
48+
}
49+
50+
public void setValue2(int value2) {
51+
this.value2 = value2;
52+
}
53+
54+
public int getValue3() {
55+
return value3;
56+
}
57+
58+
public void setValue3(int value3) {
59+
this.value3 = value3;
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class HelloWorld {
2+
3+
public void neverCalled() {
4+
System.out.println("Hello world!");
5+
}
6+
7+
public boolean isPositive(int value) {
8+
return value > 0 ? true : false;
9+
}
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
public class OmittedDTO {
2+
private String item1;
3+
4+
private String item2;
5+
6+
private String item3;
7+
8+
private int value1;
9+
10+
private int value2;
11+
12+
private int value3;
13+
14+
public String getItem1() {
15+
return item1;
16+
}
17+
18+
public void setItem1(String item1) {
19+
this.item1 = item1;
20+
}
21+
22+
public String getItem2() {
23+
return item2;
24+
}
25+
26+
public void setItem2(String item2) {
27+
this.item2 = item2;
28+
}
29+
30+
public String getItem3() {
31+
return item3;
32+
}
33+
34+
public void setItem3(String item3) {
35+
this.item3 = item3;
36+
}
37+
38+
public int getValue1() {
39+
return value1;
40+
}
41+
42+
public void setValue1(int value1) {
43+
this.value1 = value1;
44+
}
45+
46+
public int getValue2() {
47+
return value2;
48+
}
49+
50+
public void setValue2(int value2) {
51+
this.value2 = value2;
52+
}
53+
54+
public int getValue3() {
55+
return value3;
56+
}
57+
58+
public void setValue3(int value3) {
59+
this.value3 = value3;
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class HelloWorldTest extends junit.framework.TestCase {
2+
3+
public void testWillIncreaseCoverage() {
4+
new HelloWorld().isPositive(0);
5+
}
6+
7+
}

its/plugin/pom.xml

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@
2222
<dependency>
2323
<groupId>org.sonarsource.orchestrator</groupId>
2424
<artifactId>sonar-orchestrator</artifactId>
25-
<version>3.10.1</version>
25+
<version>3.15.2.1322</version>
2626
</dependency>
2727
<dependency>
2828
<groupId>junit</groupId>
2929
<artifactId>junit</artifactId>
30-
<version>4.11</version>
30+
<version>4.12</version>
3131
</dependency>
3232
<dependency>
3333
<groupId>org.easytesting</groupId>
3434
<artifactId>fest-assert</artifactId>
3535
<version>1.4</version>
3636
</dependency>
37+
<dependency>
38+
<groupId>com.googlecode.json-simple</groupId>
39+
<artifactId>json-simple</artifactId>
40+
<version>1.1.1</version>
41+
</dependency>
3742
</dependencies>
3843
<build>
3944
<pluginManagement>

its/plugin/projects/reuseReport/clover.xml

+21-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,27 @@
1010
<class name="HelloWorld">
1111
<metrics methods="2" conditionals="2" coveredstatements="1" coveredmethods="1" complexity="3" coveredconditionals="1" statements="2" coveredelements="3" elements="6"/>
1212
</class>
13-
<line num="5" count="0" complexity="1" type="method" signature="neverCalled() : void"/>
14-
<line num="6" count="0" type="stmt"/>
15-
<line num="9" count="1" complexity="2" type="method" signature="isPositive(int) : boolean"/>
16-
<line num="10" count="1" type="stmt"/>
17-
<line num="10" falsecount="1" type="cond" truecount="0"/>
13+
<line num="3" count="0" complexity="1" type="method" signature="neverCalled() : void"/>
14+
<line num="4" count="0" type="stmt"/>
15+
<line num="7" count="1" complexity="2" type="method" signature="isPositive(int) : boolean"/>
16+
<line num="8" count="1" type="stmt"/>
17+
<line num="8" falsecount="1" type="cond" truecount="0"/>
18+
</file>
19+
<file name="DTO.java" path="src/main/java/DTO.java">
20+
<metrics classes="1" methods="2" conditionals="0" ncloc="18" coveredstatements="1" coveredmethods="1" complexity="1" coveredconditionals="0" statements="2" loc="61" coveredelements="4" elements="5"/>
21+
<class name="DTO">
22+
<metrics coveredelements="4" coveredconditionals="0" complexity="1" coveredmethods="1" methods="1" elements="5" statements="1" conditionals="0" coveredstatements="1"/>
23+
</class>
24+
<line complexity="1" visibility="public" signature="setItem1(String) : void" num="18" count="5" type="method"/>
25+
<line num="19" count="5" type="stmt"/>
26+
<line complexity="1" visibility="public" signature="setItem2(String) : void" num="26" count="0" type="method"/>
27+
<line num="27" count="0" type="stmt"/>
28+
</file>
29+
<file name="OmittedDTO.java" path="src/main/java/OmittedDTO.java">
30+
<metrics classes="1" methods="0" conditionals="0" ncloc="18" coveredstatements="0" coveredmethods="0" complexity="0" coveredconditionals="0" statements="0" loc="61" coveredelements="0" elements="0"/>
31+
<class name="OmittedDTO">
32+
<metrics classes="1" methods="0" conditionals="0" ncloc="18" coveredstatements="0" coveredmethods="0" complexity="0" coveredconditionals="0" statements="0" loc="61" coveredelements="0" elements="0"/>
33+
</class>
1834
</file>
1935
</package>
2036
</project>

its/plugin/projects/reuseReport/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.sonar.tests.cloverReuseReport</groupId>
5-
<artifactId>parent</artifactId>
5+
<artifactId>reuseReport</artifactId>
66
<version>1.0-SNAPSHOT</version>
77
<name>Sonar tests - clover reuse report</name>
88
<description>foo</description>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
public class DTO {
2+
private String item1;
3+
4+
private String item2;
5+
6+
private String item3;
7+
8+
private int value1;
9+
10+
private int value2;
11+
12+
private int value3;
13+
14+
public String getItem1() {
15+
return item1;
16+
}
17+
18+
public void setItem1(String item1) {
19+
this.item1 = item1;
20+
}
21+
22+
public String getItem2() {
23+
return item2;
24+
}
25+
26+
public void setItem2(String item2) {
27+
this.item2 = item2;
28+
}
29+
30+
public String getItem3() {
31+
return item3;
32+
}
33+
34+
public void setItem3(String item3) {
35+
this.item3 = item3;
36+
}
37+
38+
public int getValue1() {
39+
return value1;
40+
}
41+
42+
public void setValue1(int value1) {
43+
this.value1 = value1;
44+
}
45+
46+
public int getValue2() {
47+
return value2;
48+
}
49+
50+
public void setValue2(int value2) {
51+
this.value2 = value2;
52+
}
53+
54+
public int getValue3() {
55+
return value3;
56+
}
57+
58+
public void setValue3(int value3) {
59+
this.value3 = value3;
60+
}
61+
}

0 commit comments

Comments
 (0)