Skip to content

Commit

Permalink
SONARKT-356 CCT support using sonar-analyzer-commons 2.7 and sonar-pl…
Browse files Browse the repository at this point in the history
…ugin-api 10.1 (#363)
  • Loading branch information
alban-auzeill authored Aug 15, 2023
1 parent bac4c57 commit f561c3d
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 14 deletions.
6 changes: 4 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ dependencyResolutionManagement {
versionCatalogs {

val kotlinVersion: String by extra
val analyzerCommonsVersionStr = "2.5.0.1358"
val sonarPluginApi = "9.15.0.435"
val analyzerCommonsVersionStr = "2.7.0.1482"
val sonarPluginApi = "10.1.0.809"
val slf4jApi = "1.7.30"

create("libs") {
val analyzerCommons = version("analyzerCommons", analyzerCommonsVersionStr)
Expand All @@ -51,6 +52,7 @@ dependencyResolutionManagement {
library("sonar-analyzer-commons-recognizers", "org.sonarsource.analyzer-commons", "sonar-analyzer-recognizers").versionRef(analyzerCommons)
library("sonar-performance-measure", "org.sonarsource.analyzer-commons", "sonar-performance-measure").versionRef(analyzerCommons)
library("sonar-plugin-api", "org.sonarsource.api.plugin", "sonar-plugin-api").version(sonarPluginApi)
library("slf4j-api", "org.slf4j", "slf4j-api").version(slf4jApi)
library("sonar-regex-parsing", "org.sonarsource.analyzer-commons", "sonar-regex-parsing").versionRef(analyzerCommons)
library("sonar-xml-parsing", "org.sonarsource.analyzer-commons", "sonar-xml-parsing").versionRef(analyzerCommons)
library("staxmate", "com.fasterxml.staxmate", "staxmate").versionRef(staxmate)
Expand Down
2 changes: 2 additions & 0 deletions sonar-kotlin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
compileOnly(libs.sonar.plugin.api)
compileOnly(libs.slf4j.api)
implementation(libs.sonar.analyzer.commons)
implementation(libs.sonar.xml.parsing)
implementation(libs.sonar.regex.parsing)
Expand All @@ -13,6 +14,7 @@ dependencies {
implementation(libs.gson)
implementation(libs.sonar.analyzer.commons.recognizers)

testImplementation(libs.slf4j.api)
testImplementation(testLibs.junit.api)
testImplementation(testLibs.junit.params)
testRuntimeOnly(testLibs.junit.engine)
Expand Down
2 changes: 2 additions & 0 deletions sonar-kotlin-external-linters/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
compileOnly(libs.sonar.plugin.api)
compileOnly(libs.slf4j.api)
implementation(libs.sonar.analyzer.commons)
implementation(libs.sonar.xml.parsing)
implementation(libs.sonar.regex.parsing)
Expand All @@ -15,6 +16,7 @@ dependencies {

implementation(project(":sonar-kotlin-api"))

testImplementation(libs.slf4j.api)
testImplementation(testLibs.junit.api)
testImplementation(testLibs.junit.params)
testRuntimeOnly(testLibs.junit.engine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import kotlin.jvm.JvmField;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.event.Level;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.batch.sensor.issue.ExternalIssue;
import org.sonar.api.rules.RuleType;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonarsource.analyzer.commons.ExternalRuleLoader;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -77,7 +77,7 @@ void import_detekt_issues_with_rule_loader() throws IOException {
assertThat(third.primaryLocation().message()).isEqualTo("A class should always override hashCode when overriding equals and the other way around.");
assertThat(third.primaryLocation().textRange().start().line()).isEqualTo(3);

assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
assertThat(logTester.logs(Level.ERROR)).isEmpty();
}

private List<ExternalIssue> importIssues(String fileName) throws IOException {
Expand Down
2 changes: 2 additions & 0 deletions sonar-kotlin-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {

dependencies {
compileOnly(libs.sonar.plugin.api)
compileOnly(libs.slf4j.api)
implementation(libs.sonar.analyzer.commons)
implementation(libs.sonar.xml.parsing)
implementation(libs.sonar.regex.parsing)
Expand All @@ -21,6 +22,7 @@ dependencies {
implementation(project(":sonar-kotlin-api"))
implementation(project(":sonar-kotlin-surefire"))

testImplementation(libs.slf4j.api)
testImplementation(testLibs.junit.api)
testImplementation(testLibs.junit.params)
testRuntimeOnly(testLibs.junit.engine)
Expand Down
2 changes: 2 additions & 0 deletions sonar-kotlin-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repositories {

dependencies {
compileOnly(libs.sonar.plugin.api)
compileOnly(libs.slf4j.api)
implementation(libs.sonar.analyzer.commons)
implementation(libs.sonar.xml.parsing)
implementation(libs.sonar.regex.parsing)
Expand All @@ -30,6 +31,7 @@ dependencies {
implementation(project(":sonar-kotlin-surefire"))
implementation(project(":sonar-kotlin-checks"))

testImplementation(libs.slf4j.api)
testImplementation(testLibs.junit.api)
testImplementation(testLibs.junit.params)
testRuntimeOnly(testLibs.junit.engine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class KotlinRulesDefinitionTest {
@Test
fun rules() {
val repository = repositoryForVersion(Version.create(8, 9))
Assertions.assertThat(repository!!.name()).isEqualTo("SonarQube")
Assertions.assertThat(repository!!.name()).isEqualTo("Sonar")
Assertions.assertThat(repository.language()).isEqualTo("kotlin")
val rule = repository.rule("S1764")!!
Assertions.assertThat(rule.name())
Expand Down
2 changes: 2 additions & 0 deletions sonar-kotlin-surefire/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
compileOnly(libs.sonar.plugin.api)
compileOnly(libs.slf4j.api)
implementation(libs.sonar.analyzer.commons)
implementation(libs.sonar.xml.parsing)
implementation(libs.sonar.regex.parsing)
Expand All @@ -15,6 +16,7 @@ dependencies {

implementation(project(":sonar-kotlin-api"))

testImplementation(libs.slf4j.api)
testImplementation(testLibs.junit.api)
testImplementation(testLibs.junit.params)
testRuntimeOnly(testLibs.junit.engine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.event.Level;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.api.utils.log.LoggerLevel;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -92,9 +92,9 @@ void should_store_zero_tests_when_source_file_is_not_found() {
when(context.fileSystem()).thenReturn(new DefaultFileSystem(Paths.get("/test")));
parser.collect(context, getDirs("multipleReports"), false);
verify(context, never()).newMeasure();
assertThat(logTester.logs(LoggerLevel.WARN)).isNotEmpty();
assertThat(logTester.logs(LoggerLevel.WARN)).allMatch(message -> message.startsWith(PREFIX));
assertThat(logTester.logs(LoggerLevel.WARN)).allMatch(message -> message.endsWith(WARNING));
assertThat(logTester.logs(Level.WARN)).isNotEmpty();
assertThat(logTester.logs(Level.WARN)).allMatch(message -> message.startsWith(PREFIX));
assertThat(logTester.logs(Level.WARN)).allMatch(message -> message.endsWith(WARNING));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import kotlin.jvm.JvmField;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.event.Level;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.api.utils.log.LoggerLevel;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -48,7 +48,7 @@ void should_get_report_paths_from_property() {
DefaultFileSystem fs = new DefaultFileSystem(new File(API_PATH + "SurefireUtilsTest/shouldGetReportsPathFromProperty"));
PathResolver pathResolver = new PathResolver();

assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
assertThat(logTester.logs(Level.INFO)).isEmpty();

List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);

Expand All @@ -61,7 +61,7 @@ void should_get_report_paths_from_property() {
assertThat(directory2)
.exists()
.isDirectory();
assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
assertThat(logTester.logs(Level.INFO)).isEmpty();
}

@Test
Expand All @@ -70,7 +70,7 @@ void return_default_value_if_property_unset() throws Exception {
DefaultFileSystem fs = new DefaultFileSystem(new File(API_PATH + "SurefireUtilsTest"));
PathResolver pathResolver = new PathResolver();

assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
assertThat(logTester.logs(Level.INFO)).isEmpty();

List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);

Expand All @@ -79,6 +79,6 @@ void return_default_value_if_property_unset() throws Exception {
assertThat(directory.getCanonicalPath()).endsWith("target" + File.separator + "surefire-reports");
assertThat(directory).doesNotExist();
assertThat(directory.isDirectory()).isFalse();
assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
assertThat(logTester.logs(Level.INFO)).isEmpty();
}
}

0 comments on commit f561c3d

Please sign in to comment.