Skip to content

Commit

Permalink
Use new coverage API (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony-Proum authored Aug 21, 2019
1 parent fe8e54c commit 019fed1
Show file tree
Hide file tree
Showing 29 changed files with 965 additions and 338 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!target/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Icon?
Thumbs.db
# Folder config file
Desktop.ini
its/plugin/projects/groovy-clover-sample/.sonar/*
its/plugin/projects/reuseReport/.sonar/*
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG VERSION=latest
FROM sonarqube:${VERSION}

COPY target/sonar-clover-plugin.jar /opt/sonarqube/extensions/plugins/
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
run-test: ## Allows to run all unit tests
@docker run --mount type=bind,src=$$(pwd),target=/usr/src -w /usr/src maven:alpine mvn test

run-integration-platform: ## Allows to run local integrations test with docker
@docker network create sonar || \
docker build --build-arg VERSION=$$VERSION --tag test-instance . && \
docker run -p 9000:9000 --name sonar-instance --net sonar test-instance

run-integration-test: ## Allows to push a report in integration platform
@docker run --mount type=bind,src=$$(pwd)/its/integration,target=/usr/src -w /usr/src --net sonar maven:alpine \
mvn clean clover:setup test clover:aggregate clover:clover sonar:sonar -Dsonar.sources=src -Dsonar.host.url=http://sonar-instance:9000

build-package: ## Allows to build artifacts
@docker run --mount type=bind,src=$$(pwd),target=/usr/src -w /usr/src maven:alpine mvn package

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ Sonar Clover
[![Build Status](https://travis-ci.org/sfeir-open-source/sonar-clover.svg?branch=master)](https://travis-ci.org/sfeir-open-source/sonar-clover)

## Description / Features
It provides the ability to feed SonarQube with code coverage data coming from Atlassian Clover.
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/).

## Usage
To display code coverage data:

1. Prior to the SonarQube analysis, execute your unit tests and generate the Clover report.
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.
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).

1. Import this report while running the SonarQube analysis by setting the sonar.clover.reportPath (using prior version to sonarQube version 6)
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.
The path may be absolute or relative to the project base directory.

##
19 changes: 19 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Contributions

All contributions have to be test using a manual (for now) process

## Test

Each contributions should allows us to use this plugin in version LTS and Latest

In order to test with different version of SonarQube, you could use:
```bash
VERSION=<myVersion> make run-integration-platform
```
This command will start a sonarQube container with version : myVersion (`lts` or `latest` could be used)

And run
```bash
make run-integration-test
```
Which will do a mvn build on a test project and upload the report in the sonarQube container created above.
41 changes: 41 additions & 0 deletions its/integration/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonar.tests</groupId>
<artifactId>integration</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Sonar tests - clover reuse report</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.3.1</version>
<configuration>
<generateHtml>false</generateHtml>
<generateXml>true</generateXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
61 changes: 61 additions & 0 deletions its/integration/src/main/java/DTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
public class DTO {
private String item1;

private String item2;

private String item3;

private int value1;

private int value2;

private int value3;

public String getItem1() {
return item1;
}

public void setItem1(String item1) {
this.item1 = item1;
}

public String getItem2() {
return item2;
}

public void setItem2(String item2) {
this.item2 = item2;
}

public String getItem3() {
return item3;
}

public void setItem3(String item3) {
this.item3 = item3;
}

public int getValue1() {
return value1;
}

public void setValue1(int value1) {
this.value1 = value1;
}

public int getValue2() {
return value2;
}

public void setValue2(int value2) {
this.value2 = value2;
}

public int getValue3() {
return value3;
}

public void setValue3(int value3) {
this.value3 = value3;
}
}
11 changes: 11 additions & 0 deletions its/integration/src/main/java/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class HelloWorld {

public void neverCalled() {
System.out.println("Hello world!");
}

public boolean isPositive(int value) {
return value > 0 ? true : false;
}

}
61 changes: 61 additions & 0 deletions its/integration/src/main/java/OmittedDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
public class OmittedDTO {
private String item1;

private String item2;

private String item3;

private int value1;

private int value2;

private int value3;

public String getItem1() {
return item1;
}

public void setItem1(String item1) {
this.item1 = item1;
}

public String getItem2() {
return item2;
}

public void setItem2(String item2) {
this.item2 = item2;
}

public String getItem3() {
return item3;
}

public void setItem3(String item3) {
this.item3 = item3;
}

public int getValue1() {
return value1;
}

public void setValue1(int value1) {
this.value1 = value1;
}

public int getValue2() {
return value2;
}

public void setValue2(int value2) {
this.value2 = value2;
}

public int getValue3() {
return value3;
}

public void setValue3(int value3) {
this.value3 = value3;
}
}
7 changes: 7 additions & 0 deletions its/integration/src/test/java/HelloWorldTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class HelloWorldTest extends junit.framework.TestCase {

public void testWillIncreaseCoverage() {
new HelloWorld().isPositive(0);
}

}
9 changes: 7 additions & 2 deletions its/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@
<dependency>
<groupId>org.sonarsource.orchestrator</groupId>
<artifactId>sonar-orchestrator</artifactId>
<version>3.10.1</version>
<version>3.15.2.1322</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
26 changes: 21 additions & 5 deletions its/plugin/projects/reuseReport/clover.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,27 @@
<class name="HelloWorld">
<metrics methods="2" conditionals="2" coveredstatements="1" coveredmethods="1" complexity="3" coveredconditionals="1" statements="2" coveredelements="3" elements="6"/>
</class>
<line num="5" count="0" complexity="1" type="method" signature="neverCalled() : void"/>
<line num="6" count="0" type="stmt"/>
<line num="9" count="1" complexity="2" type="method" signature="isPositive(int) : boolean"/>
<line num="10" count="1" type="stmt"/>
<line num="10" falsecount="1" type="cond" truecount="0"/>
<line num="3" count="0" complexity="1" type="method" signature="neverCalled() : void"/>
<line num="4" count="0" type="stmt"/>
<line num="7" count="1" complexity="2" type="method" signature="isPositive(int) : boolean"/>
<line num="8" count="1" type="stmt"/>
<line num="8" falsecount="1" type="cond" truecount="0"/>
</file>
<file name="DTO.java" path="src/main/java/DTO.java">
<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"/>
<class name="DTO">
<metrics coveredelements="4" coveredconditionals="0" complexity="1" coveredmethods="1" methods="1" elements="5" statements="1" conditionals="0" coveredstatements="1"/>
</class>
<line complexity="1" visibility="public" signature="setItem1(String) : void" num="18" count="5" type="method"/>
<line num="19" count="5" type="stmt"/>
<line complexity="1" visibility="public" signature="setItem2(String) : void" num="26" count="0" type="method"/>
<line num="27" count="0" type="stmt"/>
</file>
<file name="OmittedDTO.java" path="src/main/java/OmittedDTO.java">
<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"/>
<class name="OmittedDTO">
<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"/>
</class>
</file>
</package>
</project>
Expand Down
2 changes: 1 addition & 1 deletion its/plugin/projects/reuseReport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonar.tests.cloverReuseReport</groupId>
<artifactId>parent</artifactId>
<artifactId>reuseReport</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Sonar tests - clover reuse report</name>
<description>foo</description>
Expand Down
61 changes: 61 additions & 0 deletions its/plugin/projects/reuseReport/src/main/java/DTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
public class DTO {
private String item1;

private String item2;

private String item3;

private int value1;

private int value2;

private int value3;

public String getItem1() {
return item1;
}

public void setItem1(String item1) {
this.item1 = item1;
}

public String getItem2() {
return item2;
}

public void setItem2(String item2) {
this.item2 = item2;
}

public String getItem3() {
return item3;
}

public void setItem3(String item3) {
this.item3 = item3;
}

public int getValue1() {
return value1;
}

public void setValue1(int value1) {
this.value1 = value1;
}

public int getValue2() {
return value2;
}

public void setValue2(int value2) {
this.value2 = value2;
}

public int getValue3() {
return value3;
}

public void setValue3(int value3) {
this.value3 = value3;
}
}
Loading

0 comments on commit 019fed1

Please sign in to comment.