From 3d88d2eaf9fa2aeb0a9198656a7f551e55b00096 Mon Sep 17 00:00:00 2001 From: GabinL21 Date: Mon, 4 Nov 2024 12:25:21 +0100 Subject: [PATCH] SONARPHP-1519 Address comments --- README.md | 4 +-- build-logic/settings.gradle.kts | 4 +-- ...onarsource.php.java-conventions.gradle.kts | 17 ++++++++++ .../kotlin/org/sonarsource/php/BuildUtils.kt | 17 ++++++++++ php-checks/build.gradle.kts | 1 - php-frontend/build.gradle.kts | 1 - sonar-php-plugin/build.gradle.kts | 34 ++----------------- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 362b6bf19..955ed1f8d 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,13 @@ Before running any of the integration tests make sure the submodules are checked #### Plugin Test The "Plugin Test" is an additional integration test that verifies plugin features such as metric calculation, coverage, etc. To launch it: ```shell -./gradlew build -p its/plugin +./gradlew its:plugin:tests:test ``` #### Ruling Test The "Ruling Test" is a special integration test that launches the analysis of a large code base, saves the issues created by the plugin in report files, and then compares those results to the set of expected issues (stored as JSON files). To launch the ruling test: ```shell -./gradlew build -p its/ruling +./gradlew its:ruling:test ``` This test gives you the opportunity to examine the issues created by each rule and make sure they're what you expect. You can inspect new/lost issues by checking the SonarQube local URL mentioned in the logs at the end of the analysis. diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts index 15195a620..d05cbfe74 100644 --- a/build-logic/settings.gradle.kts +++ b/build-logic/settings.gradle.kts @@ -30,6 +30,8 @@ dependencyResolutionManagement { pluginManagement { repositories { + mavenCentral() + gradlePluginPortal() maven { url = uri("https://repox.jfrog.io/repox/sonarsource") @@ -49,7 +51,5 @@ pluginManagement { } } } - mavenCentral() - gradlePluginPortal() } } diff --git a/build-logic/src/main/kotlin/org.sonarsource.php.java-conventions.gradle.kts b/build-logic/src/main/kotlin/org.sonarsource.php.java-conventions.gradle.kts index a24118bc2..970cfd067 100644 --- a/build-logic/src/main/kotlin/org.sonarsource.php.java-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/org.sonarsource.php.java-conventions.gradle.kts @@ -34,3 +34,20 @@ tasks.withType { events(SKIPPED, FAILED) } } + +jacoco { + toolVersion = "0.8.12" +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + reports { + xml.required.set(true) + csv.required.set(false) + html.required.set(providers.environmentVariable("CI").map { it.toBoolean().not() }.orElse(true)) + } +} + +plugins.withType { + tasks["test"].finalizedBy("jacocoTestReport") +} diff --git a/build-logic/src/main/kotlin/org/sonarsource/php/BuildUtils.kt b/build-logic/src/main/kotlin/org/sonarsource/php/BuildUtils.kt index 96f4e9fc9..223d29fb6 100644 --- a/build-logic/src/main/kotlin/org/sonarsource/php/BuildUtils.kt +++ b/build-logic/src/main/kotlin/org/sonarsource/php/BuildUtils.kt @@ -2,6 +2,9 @@ package org.sonarsource.php import org.gradle.api.GradleException import org.gradle.api.Project +import org.gradle.api.tasks.Delete +import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.register import java.io.File fun enforceJarSize( @@ -22,3 +25,17 @@ fun Project.signingCondition(): Boolean { return (branch == "master" || branch.matches("branch-[\\d.]+".toRegex())) && gradle.taskGraph.hasTask(":artifactoryPublish") } + +fun Project.registerCleanupTask(): TaskProvider { + return tasks.register("cleanupOldVersion") { + group = "build" + description = "Clean up jars of old plugin version" + + delete( + fileTree(project.layout.buildDirectory.dir("libs")).matching { + include("${project.name}-*.jar") + exclude("${project.name}-${project.version}-*.jar") + } + ) + } +} diff --git a/php-checks/build.gradle.kts b/php-checks/build.gradle.kts index 0337313c5..9a2119272 100644 --- a/php-checks/build.gradle.kts +++ b/php-checks/build.gradle.kts @@ -11,7 +11,6 @@ dependencies { implementation(libs.sonar.plugin.api) implementation(libs.sonar.analyzer.commons) implementation(libs.commons.lang) - compileOnly(libs.slf4j.api) testImplementation(libs.junit.jupiter) testImplementation(libs.assertj.core) diff --git a/php-frontend/build.gradle.kts b/php-frontend/build.gradle.kts index 2c78c3335..71d5d7cb2 100644 --- a/php-frontend/build.gradle.kts +++ b/php-frontend/build.gradle.kts @@ -14,7 +14,6 @@ dependencies { implementation(libs.sonar.plugin.api) implementation(libs.commons.lang) - compileOnly(libs.slf4j.api) testImplementation(libs.junit.jupiter) testImplementation(libs.mockito.core) diff --git a/sonar-php-plugin/build.gradle.kts b/sonar-php-plugin/build.gradle.kts index 2cb6ec5b1..d90e5bbca 100644 --- a/sonar-php-plugin/build.gradle.kts +++ b/sonar-php-plugin/build.gradle.kts @@ -1,4 +1,5 @@ import org.sonarsource.php.enforceJarSize +import org.sonarsource.php.registerCleanupTask plugins { id("org.sonarsource.php.java-conventions") @@ -15,7 +16,6 @@ dependencies { implementation(libs.sonar.xml.parsing) implementation(libs.staxmate) implementation(libs.commons.lang) - compileOnly(libs.slf4j.api) testImplementation(testFixtures(project(":php-frontend"))) testImplementation(libs.junit.jupiter) @@ -29,24 +29,6 @@ dependencies { description = "SonarSource PHP Analyzer :: Sonar Plugin" -jacoco { - toolVersion = "0.8.12" -} - -tasks.jacocoTestReport { - dependsOn(tasks.test) - reports { - xml.required.set(true) - csv.required.set(false) - html.required.set(false) - } -} - -// when subproject has Jacoco plugin applied we want to generate XML report for coverage -plugins.withType { - tasks["test"].finalizedBy("jacocoTestReport") -} - tasks.jar { manifest { attributes( @@ -74,19 +56,7 @@ tasks.jar { } } -val cleanupTask = - tasks.register("cleanupOldVersion") { - group = "build" - description = "Clean up jars of old plugin version" - - delete( - fileTree(project.layout.buildDirectory.dir("libs")).matching { - include("${project.name}-*.jar") - exclude("${project.name}-${project.version}-*.jar") - exclude("${project.name}-${project.version}.jar") - }, - ) - } +val cleanupTask = registerCleanupTask() tasks.shadowJar { dependsOn(cleanupTask)