From 1115ea2003f8dcc56dae0e68fcaf4a11963dec64 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Mon, 16 Dec 2024 12:21:04 +0100 Subject: [PATCH] SONARGO-71 Extend "code-style-convention" to optionally support Go, add to common Gradle modules --- .gitmodules | 1 + build-logic | 2 +- build.gradle | 15 --------------- its/plugin/build.gradle.kts | 1 + its/ruling/build.gradle.kts | 1 + settings.gradle.kts | 1 + sonar-go-plugin/build.gradle.kts | 1 + sonar-go-to-slang/build.gradle.kts | 23 +++++++++++++++++++++++ 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.gitmodules b/.gitmodules index 73aed1c5..5acf88d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,4 @@ [submodule "build-logic"] path = build-logic url = https://github.com/SonarSource/cloud-native-gradle-modules + branch = SONARGO-71 diff --git a/build-logic b/build-logic index 586c6435..2f73f4fc 160000 --- a/build-logic +++ b/build-logic @@ -1 +1 @@ -Subproject commit 586c643589c7c79b4a394d04095106ddf44d64c1 +Subproject commit 2f73f4fc590ebcae8b51213d07f16918e90f2902 diff --git a/build.gradle b/build.gradle index eff6c1c2..031e14c9 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,6 @@ plugins { id 'com.jfrog.artifactory' version '4.28.2' id 'org.sonarqube' version '6.0.1.5171' id 'de.thetaphi.forbiddenapis' version '3.0' apply false - id 'com.diffplug.spotless' version '6.15.0' } allprojects { @@ -51,8 +50,6 @@ subprojects { // do not publish to Artifactory by default artifactoryPublish.skip = true - apply plugin: 'com.diffplug.spotless' - configurations { // include compileOnly dependencies during test testCompile.extendsFrom compileOnly @@ -68,18 +65,6 @@ subprojects { } } - // license updater - spotless { - java { - targetExclude "**/src/test/resources/**", "**/build/**", "its/sources/**", "its/plugin/projects/**" - licenseHeaderFile(rootProject.file("LICENSE_HEADER")).updateYearWithLatest(true) - } - format("javaMisc") { - target("src/**/package-info.java") - licenseHeaderFile(rootProject.file("LICENSE_HEADER"), "(@javax.annotation|@ParametersAreNonnullByDefault)").updateYearWithLatest(true) - } - } - publishing { publications { mavenJava(MavenPublication) { diff --git a/its/plugin/build.gradle.kts b/its/plugin/build.gradle.kts index e9fe1ed1..d9bf1938 100644 --- a/its/plugin/build.gradle.kts +++ b/its/plugin/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("org.sonarsource.cloud-native.java-conventions") + id("org.sonarsource.cloud-native.code-style-conventions") id("org.sonarsource.cloud-native.integration-test") } diff --git a/its/ruling/build.gradle.kts b/its/ruling/build.gradle.kts index 95713577..5b796fd1 100644 --- a/its/ruling/build.gradle.kts +++ b/its/ruling/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("org.sonarsource.cloud-native.java-conventions") + id("org.sonarsource.cloud-native.code-style-conventions") id("org.sonarsource.cloud-native.integration-test") } diff --git a/settings.gradle.kts b/settings.gradle.kts index 06e67521..423fd47c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,6 +8,7 @@ pluginManagement { plugins { id("com.gradle.develocity") version "3.18.2" + id("com.diffplug.blowdryerSetup") version "1.7.1" } develocity { diff --git a/sonar-go-plugin/build.gradle.kts b/sonar-go-plugin/build.gradle.kts index 25061476..79a4e9ab 100644 --- a/sonar-go-plugin/build.gradle.kts +++ b/sonar-go-plugin/build.gradle.kts @@ -5,6 +5,7 @@ import java.util.jar.JarInputStream plugins { id("org.sonarsource.cloud-native.java-conventions") + id("org.sonarsource.cloud-native.code-style-conventions") id("com.github.johnrengelman.shadow") version "7.1.0" } diff --git a/sonar-go-to-slang/build.gradle.kts b/sonar-go-to-slang/build.gradle.kts index 632bf8c7..9d6b2637 100644 --- a/sonar-go-to-slang/build.gradle.kts +++ b/sonar-go-to-slang/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("org.sonarsource.cloud-native.code-style-conventions") +} + sonarqube { properties { property("sonar.sources", ".") @@ -44,3 +48,22 @@ generateTestReport { tasks.build { dependsOn(generateTestReport) } + +if (System.getenv("CI") == "true") { + // spotless is enabled only for CI, because spotless relies on Go installation being available on the machine + spotless { + go { + val goVersion = providers.environmentVariable("GO_VERSION").getOrElse("1.23.4") + gofmt("go$goVersion").withGoExecutable(System.getenv("HOME") + "/go/bin/go") + target("*.go", "**/*.go") + targetExclude("*_generated.go") + } + } + // For now, these tasks rely on installation of Go performed by the call to make.sh + tasks.spotlessCheck { + dependsOn(generateParserAndBuild) + } + tasks.spotlessApply { + dependsOn(generateParserAndBuild) + } +}