Skip to content

Commit 1d91961

Browse files
committed
SONARJAVA-5720 Unify Platform Dogfooding of sonar-java
1 parent f002a03 commit 1d91961

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

.cirrus.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ build_task:
8989
- regular_mvn_build_deploy_analyze -Dmaven.test.skip=true -Dsonar.skip=true -pl '!java-checks-test-sources/default,!java-checks-test-sources/aws,!java-checks-test-sources/spring-web-4.0'
9090
cleanup_before_cache_script: cleanup_maven_repository
9191

92+
sonar_shadow_scan_and_issue_replication_task:
93+
<<: *COMMON_BUILD_DEFINITION
94+
depends_on:
95+
- build
96+
# Only run when triggered by the cirrus-ci cron job named "nightly"
97+
# TODO only_if: $CIRRUS_CRON == "nightly"
98+
env:
99+
SONAR_PROJECT_KEY: "org.sonarsource.java:java"
100+
SHADOW_ORGANIZATION: "sonarsource"
101+
SHADOW_PROJECT_KEY: "SonarSource_sonar-java"
102+
# to replicate issue states from next
103+
SONAR_TOKEN: VAULT[development/kv/data/next data.token]
104+
SONAR_HOST_URL: https://next.sonarqube.com/sonarqube
105+
matrix:
106+
- name: "sonarcloud.io"
107+
SHADOW_SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
108+
SHADOW_SONAR_HOST_URL: "https://sonarcloud.io"
109+
- name: "sonarqube.us"
110+
SHADOW_SONAR_TOKEN: VAULT[development/kv/data/sonarqube-us data.token]
111+
SHADOW_SONAR_HOST_URL: "https://sonarqube.us"
112+
build_script:
113+
- *log_develocity_url_script
114+
- source cirrus-env BUILD
115+
- ./shadow-scan-and-issue-replication.sh
116+
cleanup_before_cache_script: cleanup_maven_repository
117+
92118
test_analyze_task:
93119
<<: *COMMON_BUILD_DEFINITION
94120
build_script:
@@ -282,6 +308,7 @@ autoscan_task:
282308
promote_task:
283309
depends_on:
284310
- build
311+
- sonar_shadow_scan_and_issue_replication
285312
- test_analyze
286313
- qa_os_win
287314
- sanity
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# IRIS: Issue Replication for Sonarqube
6+
IRIS_JAR_URL="${ARTIFACTORY_URL}/sonarsource-private-releases/com/sonarsource/iris/iris/\[RELEASE\]/iris-\[RELEASE\]-jar-with-dependencies.jar"
7+
IRIS_JAR_PATH="target/libs/iris.jar"
8+
9+
function build_and_analyze_the_project() {
10+
echo
11+
echo "===== Build and analyze the project targeting a shadow SonarQube instance"
12+
mvn \
13+
-Pcoverage \
14+
-Dmaven.test.redirectTestOutputToFile=false \
15+
-Dsonar.host.url="${SHADOW_SONAR_HOST_URL}" \
16+
-Dsonar.token="${SHADOW_SONAR_TOKEN}" \
17+
-Dsonar.organization="${SHADOW_ORGANIZATION}" \
18+
-Dsonar.projectKey="${SHADOW_PROJECT_KEY}" \
19+
-Dsonar.analysis.buildNumber="${BUILD_NUMBER}" \
20+
-Dsonar.analysis.repository="${GITHUB_REPO}" \
21+
--batch-mode --errors --show-version \
22+
-Dsonar.analysisCache.enabled=true \
23+
-Dsonar.sca.exclusions="**/test/files/**, **/test/resources/**, its/plugin/projects/**, java-checks-test-sources/**, its/sources/**," \
24+
verify sonar:sonar
25+
}
26+
27+
function download_iris() {
28+
echo
29+
echo "===== Download ${IRIS_JAR_URL}"
30+
mkdir -p target/libs
31+
curl --silent --fail-with-body --location --header "Authorization: Bearer ${ARTIFACTORY_PRIVATE_PASSWORD}" \
32+
--output "${IRIS_JAR_PATH}" "${IRIS_JAR_URL}"
33+
}
34+
35+
function run_iris() {
36+
local DRY_RUN="$1"
37+
java \
38+
-Diris.source.projectKey="${SONAR_PROJECT_KEY}" \
39+
-Diris.source.url="${SONAR_HOST_URL}" \
40+
-Diris.source.token="${SONAR_TOKEN}" \
41+
-Diris.destination.projectKey="${SHADOW_PROJECT_KEY}" \
42+
-Diris.destination.organization="${SHADOW_ORGANIZATION}" \
43+
-Diris.destination.url="${SHADOW_SONAR_HOST_URL}" \
44+
-Diris.destination.token="${SHADOW_SONAR_TOKEN}" \
45+
-Diris.dryrun="${DRY_RUN}" \
46+
-jar "${IRIS_JAR_PATH}"
47+
}
48+
49+
function run_iris_with_and_without_dry_run() {
50+
echo
51+
echo "===== Execute IRIS as dry-run"
52+
if run_iris true; then
53+
echo "===== Successful IRIS execution as dry-run"
54+
echo "===== Execute IRIS for real"
55+
if run_iris false; then
56+
echo "===== Successful IRIS execution for real"
57+
return 0
58+
else
59+
echo "===== Failed IRIS execution for real"
60+
return 1
61+
fi
62+
else
63+
echo "===== Failed IRIS execution as dry-run"
64+
return 1
65+
fi
66+
}
67+
68+
source cirrus-env BUILD
69+
. set_maven_build_version "$BUILD_NUMBER"
70+
build_and_analyze_the_project
71+
download_iris
72+
run_iris_with_and_without_dry_run

0 commit comments

Comments
 (0)