Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.7 refractor merge into master #22

Merged
merged 31 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
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
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ script: ./travis.sh
env:
matrix:
- TEST=ci
- TEST=plugin SQ_VERSION=6.1
- TEST=plugin SQ_VERSION=6.2
- TEST=plugin SQ_VERSION=6.7
- TEST=plugin SQ_VERSION=7.0

matrix:
fast_finish: true


before_cache:
# remove all the artifacts that are installed in local repo because of mvn deploy
- rm -rf $HOME/.m2/repository/org/sonarsource/java
- find $HOME/.m2 -name resolver-status.properties -exec rm {} \;

cache:
directories:
- '$HOME/.m2/repository'

- '$HOME/.sonar'
- '$HOME/jvm'
- '$HOME/maven'
notifications:
email: false
674 changes: 674 additions & 0 deletions LICENCE

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sonar Cobertura
===============
Current version: 1.9.1
Current version: 2.0
===============
[![Build Status](https://travis-ci.org/galexandre/sonar-cobertura.svg?branch=master)](https://travis-ci.org/galexandre/sonar-cobertura) [![Code Climate](https://codeclimate.com/github/galexandre/sonar-cobertura/badges/gpa.svg)](https://codeclimate.com/github/galexandre/sonar-cobertura) [![Issue Count](https://codeclimate.com/github/galexandre/sonar-cobertura/badges/issue_count.svg)](https://codeclimate.com/github/galexandre/sonar-cobertura) [Slack](https://sonar-cobertura.slack.com/)

Expand All @@ -12,9 +12,9 @@ Current version: 1.9.1
## Description / Feature
This plugin provides the ability to feed SonarQube with code coverage data coming from [Cobertura](http://cobertura.github.io/cobertura/).

Cobertura Plugin | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 1.9 | 1.9.1 |
Cobertura Plugin | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 1.9 | 1.9.1 | 2.0 |
---------------- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
Reports generated with Cobertura | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1
Reports generated with Cobertura | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1 | 1.9.4.1

## Usage
The default location of the XML Cobertura report is: target/site/cobertura/coverage.xml . You can change it in Configure in the `Settings > General Settings > Java > Cobertura page`
Expand Down
30 changes: 28 additions & 2 deletions its/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>it-cobertura</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Cobertura :: Integration Tests</name>
<inceptionYear>2009</inceptionYear>
<inceptionYear>2018</inceptionYear>
<organization>
<name>SonarSource</name>
<url>http://www.sonarsource.com</url>
Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>org.sonarsource.orchestrator</groupId>
<artifactId>sonar-orchestrator</artifactId>
<version>3.10.1</version>
<version>3.15.2.1322</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -41,6 +41,22 @@
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-ws</artifactId>
<version>6.7</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-qa-util</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand All @@ -57,6 +73,16 @@
</plugin>
</plugins>
</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>
</plugins>
</build>

</project>
102 changes: 67 additions & 35 deletions its/plugin/src/test/java/com/sonar/cobertura/it/CoberturaTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Cobertura :: Integration Tests
* Copyright (C) 2009 SonarSource
* Copyright (C) 2018 SonarSource
* dev@sonar.codehaus.org
*
* This program is free software; you can redistribute it and/or
Expand All @@ -20,54 +20,86 @@
package com.sonar.cobertura.it;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.MavenBuild;
import com.sonar.orchestrator.locator.FileLocation;
import org.fest.assertions.Delta;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonarqube.ws.WsMeasures;
import org.sonarqube.ws.client.measure.ComponentWsRequest;

import javax.annotation.CheckForNull;
import java.io.File;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class CoberturaTest {

@ClassRule
public static Orchestrator orchestrator = Orchestrator.builderEnv()
.addPlugin("java")
.addPlugin(FileLocation.of("../../target/sonar-cobertura-plugin.jar"))
.build();
private static final Logger LOGGER = LoggerFactory.getLogger(CoberturaTest.class);
@ClassRule
public static Orchestrator orchestrator = Orchestrator.builderEnv()
.addPlugin("java")
.addPlugin(FileLocation.of("../../target/sonar-cobertura-plugin.jar"))
.build();

@Test
public void shouldReuseCoberturaAndSurefireReports() {
MavenBuild build = MavenBuild.create(new File("projects/cobertura-example/pom.xml"));
if (orchestrator.getConfiguration().getPluginVersion("cobertura").isGreaterThanOrEquals("1.6")) {
build.setProperty("cobertura.report.format", "xml").setGoals("clean", "cobertura:cobertura", "install"); // cobertura and surefire are NOT executed during build
} else {
build.setGoals("clean", "install"); // cobertura and surefire are executed during build
}
MavenBuild analysis = MavenBuild.create(new File("projects/cobertura-example/pom.xml"))
// Do not clean to reuse reports
.setGoals("sonar:sonar")
.setProperty("sonar.java.coveragePlugin", "cobertura"); //set this property for java versions 2.1 and prior.
if (!orchestrator.getConfiguration().getPluginVersion("cobertura").isGreaterThan("1.6.2")) {
analysis.setProperty("sonar.cobertura.reportPath", "target/site/cobertura/coverage.xml");
}
orchestrator.executeBuilds(build, analysis);
Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("com.sonarsource.it.samples:cobertura-example",
"test_success_density", "test_failures", "test_errors", "tests", "skipped_tests", "test_execution_time", "coverage"));
if (!orchestrator.getConfiguration().getPluginVersion("cobertura").isGreaterThanOrEquals("1.6")) {
//no automatic import of surefire information since 1.6
assertThat(project.getMeasureIntValue("tests")).isEqualTo(2);
assertThat(project.getMeasureIntValue("test_failures")).isEqualTo(0);
assertThat(project.getMeasureIntValue("test_errors")).isEqualTo(0);
assertThat(project.getMeasureIntValue("skipped_tests")).isEqualTo(0);
assertThat(project.getMeasureIntValue("test_execution_time")).isGreaterThan(0);
assertThat(project.getMeasureValue("test_success_density")).isEqualTo(100.0);
assertTrue(true);
MavenBuild build = MavenBuild.create(new File("projects/cobertura-example/pom.xml"));
if (orchestrator.getConfiguration().getPluginVersion("cobertura").isGreaterThanOrEquals("1.6")) {
build.setProperty("cobertura.report.format", "xml").setGoals("clean", "install", "cobertura:cobertura"); // cobertura and surefire are NOT executed during build
} else {
build.setProperty("cobertura.report.format", "xml").setGoals("clean", "install", "cobertura:cobertura"); // cobertura and surefire are executed during build
}
MavenBuild analysis = MavenBuild.create(new File("projects/cobertura-example/pom.xml"))
// Do not clean to reuse reports
.setGoals("sonar:sonar")
.setProperty("sonar.java.coveragePlugin", "cobertura"); //set this property for java versions 2.1 and prior.
//if (!orchestrator.getConfiguration().getPluginVersion("cobertura").isGreaterThan("1.6.2")) {
analysis.setProperty("sonar.cobertura.reportPath", "target/site/cobertura/coverage.xml");
//}
BuildResult[] buildResult = orchestrator.executeBuilds(build, analysis);
for (int i = 0; i < buildResult.length; i++) {
assertTrue(buildResult[i].isSuccess());
}

Map<String, WsMeasures.Measure> measureMap = getMeasures("com.sonarsource.it.samples:cobertura-example",
"test_success_density", "test_failures", "test_errors", "tests", "skipped_tests",
"test_execution_time", "coverage");

LOGGER.debug("mesureMap size: "+measureMap.size());
assertNotNull(orchestrator.getServer().getUrl());
assertNotNull(measureMap);
if (measureMap!=null){
if (!orchestrator.getConfiguration().getPluginVersion("cobertura").isGreaterThanOrEquals("1.6")) {
//no automatic import of surefire information since 1.6
assertThat(Integer.parseInt(measureMap.get("tests").getValue())).isEqualTo(2);
assertThat(Integer.parseInt(measureMap.get("test_failures").getValue())).isEqualTo(0);
assertThat(Integer.parseInt(measureMap.get("test_errors").getValue())).isEqualTo(0);
assertThat(Integer.parseInt(measureMap.get("skipped_tests").getValue())).isEqualTo(0);
assertThat(Integer.parseInt(measureMap.get("test_execution_time").getValue())).isGreaterThan(0);
assertThat(Double.parseDouble(measureMap.get("test_success_density").getValue())).isEqualTo(100.0);
}
assertThat(Double.parseDouble(measureMap.get("coverage").getValue())).isEqualTo(57.1);
}
assertThat(project.getMeasureValue("coverage")).isEqualTo(57.1, Delta.delta(0.1));
}

}
@CheckForNull
Map<String,WsMeasures.Measure> getMeasures(String componentKey, String... metricKey) {
return TestUtils.newWsClient(orchestrator).measures().component(new ComponentWsRequest()
.setComponentKey(componentKey)
.setMetricKeys(asList(metricKey)))
.getComponent()
.getMeasuresList()
.stream()
.collect(Collectors.toMap(WsMeasures.Measure::getMetric, Function.identity()));
}
}
50 changes: 50 additions & 0 deletions its/plugin/src/test/java/com/sonar/cobertura/it/TestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Cobertura :: Integration Tests
* Copyright (C) 2018 SonarSource
* dev@sonar.codehaus.org
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package com.sonar.cobertura.it;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.container.Server;
import org.sonarqube.ws.client.HttpConnector;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.WsClientFactories;

import javax.annotation.Nullable;

public class TestUtils {

/**
* @deprecated replaced by {@link Tester#wsClient()}
*/
public static WsClient newWsClient(Orchestrator orchestrator) {
return newUserWsClient(orchestrator, null, null);
}

/**
* @deprecated replaced by {@link Tester#wsClient()}
*/
public static WsClient newUserWsClient(Orchestrator orchestrator, @Nullable String login, @Nullable String password) {
Server server = orchestrator.getServer();
return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
.url(server.getUrl())
.credentials(login, password)
.build());
}

}
38 changes: 26 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
</parent>

<artifactId>sonar-cobertura-plugin</artifactId>
<version>TRUNK-SNAPSHOT</version>
<version>2.0</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube Cobertura Plugin</name>
<description>Code coverage analysis using Cobertura</description>
<url>http://redirect.sonarsource.com/plugins/cobertura.html</url>
<inceptionYear>2013</inceptionYear>
<url>https://github.com/galexandre/sonar-cobertura</url>
<inceptionYear>2018</inceptionYear>
<organization>
<name>SonarSource</name>
<url>http://www.sonarsource.com</url>
Expand All @@ -30,21 +30,21 @@
</licenses>

<scm>
<connection>scm:git:git@github.com:SonarQubeCommunity/sonar-cobertura.git</connection>
<developerConnection>scm:git:git@github.com:SonarQubeCommunity/sonar-cobertura.git</developerConnection>
<url>https://github.com/SonarQubeCommunity/sonar-cobertura</url>
<connection>scm:git:git@github.com:galexandre/sonar-cobertura.git</connection>
<developerConnection>scm:git:git@github.com:galexandre/sonar-cobertura.git</developerConnection>
<url>https://github.com/galexandre/sonar-cobertura/</url>
<tag>HEAD</tag>
</scm>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/SonarQubeCommunity/sonar-cobertura/issues</url>
<url>https://github.com/galexandre/sonar-cobertura/issues</url>
</issueManagement>

<properties>
<license.title>SonarQube Cobertura Plugin</license.title>

<sonar.version>6.1</sonar.version>
<sonar-java.version>4.2</sonar-java.version>
<sonar.version>6.7</sonar.version>
<!--<sonar-java.version>5.1.0.13090</sonar-java.version>-->

<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
</properties>
Expand All @@ -56,12 +56,18 @@
<version>${sonar.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<!--<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
<version>${sonar-java.version}</version>
<type>sonar-plugin</type>
<scope>provided</scope>
</dependency>-->
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
<version>5.1.0.13090</version>
<scope>provided</scope>
</dependency>

<!-- http://jira.codehaus.org/browse/SONAR-2011
Expand Down Expand Up @@ -115,7 +121,15 @@
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.13.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.30</version>
Expand All @@ -142,7 +156,7 @@
<pluginName>Cobertura</pluginName>
<pluginClass>org.sonar.plugins.cobertura.CoberturaPlugin</pluginClass>
<pluginDescription><![CDATA[Get code coverage with <a href="http://cobertura.sourceforge.net/">Cobertura</a>.]]></pluginDescription>
<requirePlugins>java:${sonar-java.version}</requirePlugins>
<requirePlugins>java:5.1.0.13090</requirePlugins>
</configuration>
</plugin>
</plugins>
Expand Down
Loading