Skip to content

Commit

Permalink
SONARGO-52 Create a new repository for common Gradle scripts (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
petertrr authored Dec 12, 2024
1 parent 7e4becb commit 1236107
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 76 deletions.
7 changes: 5 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions build-logic
Submodule build-logic added at 14a35c
59 changes: 1 addition & 58 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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 }
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions its/plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
5 changes: 5 additions & 0 deletions its/ruling/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 6 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pluginManagement {
includeBuild("build-logic")
repositories {
mavenCentral()
gradlePluginPortal()
Expand Down Expand Up @@ -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'
6 changes: 1 addition & 5 deletions sonar-go-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id("org.sonarsource.cloud-native.java-conventions")
id 'com.github.johnrengelman.shadow' version '7.1.0'
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1236107

Please sign in to comment.