From 3fc4fa8b726910e8585b97341940a0090afb21ab Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 10 Dec 2024 15:59:21 +0100 Subject: [PATCH 1/3] SONARGO-52 Create a new repository for common Gradle scripts --- .cirrus.yml | 7 +++++-- .gitmodules | 4 ++++ build-logic | 1 + build.gradle | 16 ---------------- its/plugin/build.gradle | 4 ++++ its/ruling/build.gradle | 4 ++++ settings.gradle | 1 + sonar-go-plugin/build.gradle | 6 +----- 8 files changed, 20 insertions(+), 23 deletions(-) create mode 160000 build-logic diff --git a/.cirrus.yml b/.cirrus.yml index c6993051..0ec3b01f 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -66,6 +66,7 @@ build_task: SONAR_HOST_URL: VAULT[development/kv/data/next data.url] DEPLOY_PULL_REQUEST: "true" build_script: + - git submodule update --init --depth 1 -- build-logic - source cirrus-env BUILD - function gradle(){ ./gradlew "$@"; }; export -f gradle - gradle --version @@ -138,6 +139,7 @@ ws_scan_task: maven_cache: folder: ${CIRRUS_WORKING_DIR}/.m2/repository whitesource_script: + - git submodule update --init --depth 1 -- build-logic - source cirrus-env QA - ./gradlew --no-daemon --console plain clean - ./gradlew --no-daemon --info --stacktrace --console plain --no-daemon build -x test @@ -158,11 +160,12 @@ promote_task: <<: *ONLY_IF_SONARSOURCE_QA eks_container: <<: *CONTAINER_DEFINITION - cpu: 1 - memory: 1G + cpu: 2 + memory: 2G env: ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token] GITHUB_TOKEN: VAULT[development/github/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promotion token] promote_script: + - git submodule update --init --depth 1 -- build-logic - function gradle(){ ./gradlew "$@"; }; export -f gradle - cirrus_promote_gradle multi diff --git a/.gitmodules b/.gitmodules index 957e3d4b..df4aa593 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,7 @@ [submodule "its/sources/kubernetes-client-go"] path = its/sources/kubernetes-client-go url = https://github.com/kubernetes/client-go +[submodule "build-logic"] + path = build-logic + url = https://github.com/SonarSource/cloud-native-gradle-modules + branch = SONARGO-52 diff --git a/build-logic b/build-logic new file mode 160000 index 00000000..ee1ab073 --- /dev/null +++ b/build-logic @@ -0,0 +1 @@ +Subproject commit ee1ab07379579ff56a9c9d950dabe1c528490c41 diff --git a/build.gradle b/build.gradle index 23c3070c..2ce60cf4 100644 --- a/build.gradle +++ b/build.gradle @@ -66,12 +66,6 @@ subprojects { apply plugin: 'com.diffplug.spotless' - java.sourceCompatibility = JavaVersion.VERSION_17 - tasks.withType(JavaCompile) { - options.encoding = "UTF-8" - options.release = java.sourceCompatibility.majorVersion as int - } - jacoco { toolVersion = "0.8.7" } @@ -115,16 +109,6 @@ subprojects { } } - task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource - } - - task javadocJar(type: Jar, dependsOn: javadoc) { - archiveClassifier = 'javadoc' - from javadoc.destinationDir - } - // license updater spotless { java { diff --git a/its/plugin/build.gradle b/its/plugin/build.gradle index 5f181c4d..f3a4b67b 100644 --- a/its/plugin/build.gradle +++ b/its/plugin/build.gradle @@ -1,3 +1,7 @@ +plugins { + id("org.sonarsource.cloud-native.java-conventions") +} + dependencies { testImplementation libs.sonar.analyzer.commons testImplementation testLibs.sonar.ws diff --git a/its/ruling/build.gradle b/its/ruling/build.gradle index 7091905c..f6a1301d 100644 --- a/its/ruling/build.gradle +++ b/its/ruling/build.gradle @@ -1,3 +1,7 @@ +plugins { + id("org.sonarsource.cloud-native.java-conventions") +} + dependencies { testImplementation libs.sonar.analyzer.commons testImplementation testLibs.assertj.core diff --git a/settings.gradle b/settings.gradle index baae4825..dae0628f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ pluginManagement { + includeBuild("build-logic") repositories { mavenCentral() gradlePluginPortal() diff --git a/sonar-go-plugin/build.gradle b/sonar-go-plugin/build.gradle index 877ba7d6..292620cb 100644 --- a/sonar-go-plugin/build.gradle +++ b/sonar-go-plugin/build.gradle @@ -1,4 +1,5 @@ plugins { + id("org.sonarsource.cloud-native.java-conventions") id 'com.github.johnrengelman.shadow' version '7.1.0' } @@ -30,11 +31,6 @@ dependencies { testRuntimeOnly testLibs.junit.jupiter.engine } -tasks.withType(JavaCompile) { - // Prevent warning: Gradle 5.0 will ignore annotation processors - options.compilerArgs += [ "-proc:none" ] -} - test { testLogging { exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace) From 420621923287e474499542c8b8df5e06a8467b26 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Thu, 12 Dec 2024 14:36:00 +0100 Subject: [PATCH 2/3] Integrate changes from cloud-native-gradle-modules --- .gitmodules | 1 - build-logic | 2 +- build.gradle | 24 ------------------------ its/plugin/build.gradle | 1 + its/ruling/build.gradle | 1 + settings.gradle | 1 + 6 files changed, 4 insertions(+), 26 deletions(-) diff --git a/.gitmodules b/.gitmodules index df4aa593..73aed1c5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,4 +13,3 @@ [submodule "build-logic"] path = build-logic url = https://github.com/SonarSource/cloud-native-gradle-modules - branch = SONARGO-52 diff --git a/build-logic b/build-logic index ee1ab073..14a35c8a 160000 --- a/build-logic +++ b/build-logic @@ -1 +1 @@ -Subproject commit ee1ab07379579ff56a9c9d950dabe1c528490c41 +Subproject commit 14a35c8a3ca4546308e1e638a4b0e581deacc059 diff --git a/build.gradle b/build.gradle index 2ce60cf4..ad814196 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,6 @@ import java.util.jar.JarInputStream plugins { id 'java' - id 'jacoco' id 'com.jfrog.artifactory' version '4.28.2' id 'org.sonarqube' version '3.5.0.2730' id 'de.thetaphi.forbiddenapis' version '3.0' apply false @@ -11,7 +10,6 @@ plugins { allprojects { apply plugin: 'java' - apply plugin: 'jacoco' apply plugin: 'com.jfrog.artifactory' apply plugin: 'maven-publish' apply plugin: 'signing' @@ -66,23 +64,6 @@ subprojects { apply plugin: 'com.diffplug.spotless' - jacoco { - toolVersion = "0.8.7" - } - - jacocoTestReport { - reports { - xml.required = true - csv.required = false - html.required = false - } - } - - // when subproject has Jacoco pLugin applied we want to generate XML report for coverage - plugins.withType(JacocoPlugin) { - tasks["test"].finalizedBy 'jacocoTestReport' - } - configurations { // include compileOnly dependencies during test testCompile.extendsFrom compileOnly @@ -95,11 +76,6 @@ subprojects { } test { - testLogging { - exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace) - events "skipped", "failed" - // verbose log for failed and skipped tests (by default the name of the tests are not logged) - } def propKeys = System.properties.findAll { it.key.startsWith("orchestrator") || it.key.startsWith("sonar") || it.key == "buildNumber" || it.key == "slangVersion" }.collect { it.key } diff --git a/its/plugin/build.gradle b/its/plugin/build.gradle index f3a4b67b..7a9c0508 100644 --- a/its/plugin/build.gradle +++ b/its/plugin/build.gradle @@ -8,6 +8,7 @@ dependencies { testImplementation testLibs.assertj.core testImplementation testLibs.sonarlint.core testImplementation testLibs.sonar.orchestrator + testRuntimeOnly testLibs.junit.vintage.engine } sonarqube.skipProject = true diff --git a/its/ruling/build.gradle b/its/ruling/build.gradle index f6a1301d..dda1c08b 100644 --- a/its/ruling/build.gradle +++ b/its/ruling/build.gradle @@ -6,6 +6,7 @@ dependencies { testImplementation libs.sonar.analyzer.commons testImplementation testLibs.assertj.core testImplementation testLibs.sonar.orchestrator + testRuntimeOnly testLibs.junit.vintage.engine } sonarqube.skipProject = true diff --git a/settings.gradle b/settings.gradle index dae0628f..0ba7343b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -41,6 +41,7 @@ dependencyResolutionManagement { library("assertj-core", "org.assertj", "assertj-core").version("3.26.3") library("junit-jupiter-api", "org.junit.jupiter", "junit-jupiter-api").version("5.11.0") library("junit-jupiter-engine", "org.junit.jupiter", "junit-jupiter-engine").version("5.11.0") + library("junit-vintage-engine", "org.junit.vintage", "junit-vintage-engine").version("5.11.0") } } } From 5460c346ac8a7042fc5692471fd2f2bf936adafe Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Thu, 12 Dec 2024 17:14:00 +0100 Subject: [PATCH 3/3] Review notes & remove broken assertion --- build.gradle | 19 +------------------ .../org/sonarsource/slang/MeasuresTest.java | 7 ------- settings.gradle | 8 ++++---- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index ad814196..71c6d374 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ import java.util.jar.JarInputStream plugins { - id 'java' id 'com.jfrog.artifactory' version '4.28.2' id 'org.sonarqube' version '3.5.0.2730' id 'de.thetaphi.forbiddenapis' version '3.0' apply false @@ -14,16 +13,6 @@ allprojects { apply plugin: 'maven-publish' apply plugin: 'signing' - gradle.projectsEvaluated { - tasks.withType(JavaCompile).configureEach { - if (project.hasProperty('warn')) { - options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } else { - options.compilerArgs << "-Xlint:-unchecked" << "-Xlint:-deprecation" - } - } - } - ext { buildNumber = System.getProperty("buildNumber") @@ -69,13 +58,7 @@ subprojects { testCompile.extendsFrom compileOnly } - if (!project.path.startsWith(":its")) { - test { - useJUnitPlatform() - } - } - - test { + tasks.withType(Test).configureEach { def propKeys = System.properties.findAll { it.key.startsWith("orchestrator") || it.key.startsWith("sonar") || it.key == "buildNumber" || it.key == "slangVersion" }.collect { it.key } diff --git a/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java b/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java index 48411f4f..165d3605 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java @@ -35,13 +35,6 @@ public void go_measures() { assertThat(getMeasureAsInt(componentKey, "ncloc")).isEqualTo(41); assertThat(getMeasureAsInt(componentKey, "comment_lines")).isEqualTo(2); - assertThat(getMeasure(componentKey, "ncloc_data").getValue()) - .isEqualTo("1=1;3=1;4=1;5=1;6=1;7=1;8=1;10=1;11=1;12=1;13=1;14=1;16=1;17=1;18=1;20=1;21=1;22=1;23=1;24=1;25=1;" + - "26=1;27=1;28=1;29=1;30=1;31=1;32=1;33=1;35=1;36=1;37=1;38=1;39=1;40=1;41=1;46=1;47=1;48=1;49=1;50=1"); - assertThat(getMeasureAsInt(componentKey, "functions")).isEqualTo(3); - - assertThat(getMeasure(componentKey, "executable_lines_data").getValue()) - .isEqualTo("32=1;36=1;37=1;38=1;40=1;49=1;22=1;23=1;25=1;26=1;27=1;29=1;30=1"); } } diff --git a/settings.gradle b/settings.gradle index 0ba7343b..4965002a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -48,7 +48,7 @@ dependencyResolutionManagement { rootProject.name = 'sonar-go' -include 'sonar-go-to-slang' -include 'sonar-go-plugin' -include 'its:plugin' -include 'its:ruling' +include ':sonar-go-to-slang' +include ':sonar-go-plugin' +include ':its:plugin' +include ':its:ruling'