From 12361079bb6ab478062c76778fbb69164b5c71b5 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Thu, 12 Dec 2024 17:36:58 +0100 Subject: [PATCH] SONARGO-52 Create a new repository for common Gradle scripts (#38) --- .cirrus.yml | 7 ++- .gitmodules | 3 + build-logic | 1 + build.gradle | 59 +------------------ its/plugin/build.gradle | 5 ++ .../org/sonarsource/slang/MeasuresTest.java | 7 --- its/ruling/build.gradle | 5 ++ settings.gradle | 10 ++-- sonar-go-plugin/build.gradle | 6 +- 9 files changed, 27 insertions(+), 76 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..73aed1c5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [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 diff --git a/build-logic b/build-logic new file mode 160000 index 00000000..14a35c8a --- /dev/null +++ b/build-logic @@ -0,0 +1 @@ +Subproject commit 14a35c8a3ca4546308e1e638a4b0e581deacc059 diff --git a/build.gradle b/build.gradle index 23c3070c..71c6d374 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,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,21 +9,10 @@ plugins { allprojects { apply plugin: 'java' - apply plugin: 'jacoco' apply plugin: 'com.jfrog.artifactory' 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") @@ -66,46 +53,12 @@ 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" - } - - 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 } - if (!project.path.startsWith(":its")) { - test { - useJUnitPlatform() - } - } - - 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) - } + 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 } @@ -115,16 +68,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..7a9c0508 100644 --- a/its/plugin/build.gradle +++ b/its/plugin/build.gradle @@ -1,9 +1,14 @@ +plugins { + id("org.sonarsource.cloud-native.java-conventions") +} + dependencies { testImplementation libs.sonar.analyzer.commons testImplementation testLibs.sonar.ws testImplementation testLibs.assertj.core testImplementation testLibs.sonarlint.core testImplementation testLibs.sonar.orchestrator + testRuntimeOnly testLibs.junit.vintage.engine } sonarqube.skipProject = true 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/its/ruling/build.gradle b/its/ruling/build.gradle index 7091905c..dda1c08b 100644 --- a/its/ruling/build.gradle +++ b/its/ruling/build.gradle @@ -1,7 +1,12 @@ +plugins { + id("org.sonarsource.cloud-native.java-conventions") +} + 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 baae4825..4965002a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ pluginManagement { + includeBuild("build-logic") repositories { mavenCentral() gradlePluginPortal() @@ -40,13 +41,14 @@ 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") } } } 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' 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)