Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
name: Build & Test
on:
push:
branches-ignore:
pull_request:
branches:
- 'master'
jobs:
Build:
runs-on: ubuntu-latest
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1
- uses: actions/checkout@v2
- run: make run-test
- uses: actions/checkout@v5
- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '11'
cache: 'maven'
- run: ./mvnw clean package -DskipTests
- uses: actions/upload-artifact@v4
with:
name: target
path: target/**
Integration-tests:
strategy:
matrix:
versions: [ '8-community', '9-community', 'latest' ]
fail-fast: false
runs-on: ubuntu-latest
needs: Build
steps:
- uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: target
path: target
- name: Run integration tests
run: VERSION=${{ matrix.versions }} docker compose up --build --exit-code-from external-analysis




1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ARG VERSION=latest
FROM sonarqube:${VERSION}

COPY target/sonar-clover-plugin.jar /opt/sonarqube/extensions/plugins/
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
sonarQube:
image: sonarqube-test-env:${VERSION}
build:
context: .
dockerfile: Dockerfile
args:
VERSION: ${VERSION}
ports:
- '9000:9000'
healthcheck:
test: |
wget -q http://localhost:9000/api/system/status -O /tmp/status && cat /tmp/status | grep UP || exit 1
external-analysis:
image: eclipse-temurin:17-jdk
command: |
./mvnw clean clover:setup test clover:aggregate
clover:clover sonar:sonar -Dsonar.sources=src
-Dsonar.host.url=http://sonarQube:9000
-Dsonar.login=admin -Dsonar.password=admin --batch-mode
depends_on:
sonarQube:
condition: service_healthy
volumes:
- type: bind
source: ./its/integration
target: /usr/src
working_dir: /usr/src
35 changes: 33 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</distributionManagement>

<properties>
<sonar.version>6.7</sonar.version>
<sonar.version>9.4.0.54424</sonar.version>
<sonar.pluginName>Clover</sonar.pluginName>
<sonar.pluginClass>org.sonar.plugins.clover.CloverPlugin</sonar.pluginClass>
<sonar.pluginUrl>${project.scm.url}</sonar.pluginUrl>
Expand All @@ -67,10 +67,16 @@
<version>2.6</version>
</dependency>

<dependency>
<groupId>org.codehaus.staxmate</groupId>
<artifactId>staxmate</artifactId>
<version>2.0.1</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<version>2.7</version>
</dependency>

<dependency>
Expand All @@ -85,6 +91,12 @@
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-lgpl</artifactId>
<version>4.4.0</version>
</dependency>

<!-- unit tests -->
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
Expand All @@ -102,6 +114,25 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
<version>${sonar.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
45 changes: 23 additions & 22 deletions src/main/java/org/sonar/plugins/clover/CloverXmlReportParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.codehaus.staxmate.in.SMFilterFactory;
import org.codehaus.staxmate.in.SMInputCursor;
import org.codehaus.staxmate.in.SimpleFilter;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.utils.MessageException;
Expand Down Expand Up @@ -144,34 +144,35 @@ private InputFile getInputFile(String path) {

private void saveHitsData(InputFile resource, SMInputCursor lineCursor) throws ParseException, XMLStreamException {
final NewCoverage coverage = context.newCoverage().onFile(resource);
// cursor should be on the metrics element
if (!canBeIncludedInFileMetrics(lineCursor)) {
// cursor should now be on the line cursor; exclude this file if there are no elements to cover
((DefaultInputFile) resource).setExcludedForCoverage(true);
}

while (lineCursor.getNext() != null) {
// skip class elements on format 2_3_2
if (isClass(lineCursor)) {
continue;
}
final int lineId = Integer.parseInt(lineCursor.getAttrValue("num"));

String lineNumber = lineCursor.getAttrValue("num");
String count = lineCursor.getAttrValue("count");
if (StringUtils.isNotBlank(count)) {
final int hits = Integer.parseInt(count);
coverage.lineHits(lineId, hits);
} else {
int trueCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("truecount"));
int falseCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("falsecount"));
int coveredConditions = 0;
if (trueCount > 0) {
coveredConditions++;
}
if (falseCount > 0) {
coveredConditions++;
}

coverage.conditions(lineId, 2, coveredConditions);
if (lineNumber != null && !lineNumber.equals("")) {
final int lineId = Integer.parseInt(lineNumber);

if (StringUtils.isNotBlank(count)) {
final int hits = Integer.parseInt(count);
coverage.lineHits(lineId, hits);
} else {
int trueCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("truecount"));
int falseCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("falsecount"));
int coveredConditions = 0;

if (trueCount > 0) {
coveredConditions++;
}
if (falseCount > 0) {
coveredConditions++;
}

coverage.conditions(lineId, 2, coveredConditions);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/java/org/sonar/plugins/clover/CloverPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.junit.Test;
import org.sonar.api.Plugin;
import org.sonar.api.SonarEdition;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.Version;
Expand All @@ -32,8 +33,9 @@ public class CloverPluginTest {
@Test
public void test_define() {
final Plugin.Context context = new Plugin.Context(SonarRuntimeImpl.forSonarQube(
Version.parse("6.7.4"),
SonarQubeSide.SCANNER));
Version.parse("9.4.0"),
SonarQubeSide.SCANNER,
SonarEdition.COMMUNITY));
new CloverPlugin().define(context);
assertThat(context.getExtensions()).hasSize(1);
}
Expand Down
Loading