diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml
index 0d0b1c99..d98cff48 100644
--- a/.github/release-drafter.yml
+++ b/.github/release-drafter.yml
@@ -1 +1,2 @@
_extends: .github
+tag-template: demo-$NEXT_MINOR_VERSION
diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml
deleted file mode 100644
index 0279984d..00000000
--- a/.github/workflows/cd.yaml
+++ /dev/null
@@ -1,15 +0,0 @@
-# Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins
-
-name: cd
-on:
- workflow_dispatch:
- check_run:
- types:
- - completed
-
-jobs:
- maven-cd:
- uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yml@v1
- secrets:
- MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
- MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}
diff --git a/.github/workflows/jenkins-security-scan.yml b/.github/workflows/jenkins-security-scan.yml
index c7b41fc2..f1995d84 100644
--- a/.github/workflows/jenkins-security-scan.yml
+++ b/.github/workflows/jenkins-security-scan.yml
@@ -1,9 +1,11 @@
-name: Jenkins Security Scan
+# More information about the Jenkins security scan can be found at the developer docs: https://www.jenkins.io/redirect/jenkins-security-scan/
+name: Jenkins Security Scan
on:
push:
branches:
- - master
+ - "master"
+ - "main"
pull_request:
types: [ opened, synchronize, reopened ]
workflow_dispatch:
@@ -18,4 +20,4 @@ jobs:
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2
with:
java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate.
- # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default.
+ java-version: 11 # What version of Java to set up for the build.
diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml
new file mode 100644
index 00000000..58835450
--- /dev/null
+++ b/.github/workflows/release-drafter.yml
@@ -0,0 +1,17 @@
+# Automates creation of Release Drafts using Release Drafter
+# More Info: https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc
+
+on:
+ push:
+ branches:
+ - master
+ - main
+
+jobs:
+ update_release_draft:
+ runs-on: ubuntu-latest
+ steps:
+ # Drafts your next Release notes as Pull Requests are merged into the default branch
+ - uses: release-drafter/release-drafter@v5
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/Jenkinsfile b/Jenkinsfile
index 48bf230e..4f38f482 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1 +1,7 @@
-buildPlugin()
\ No newline at end of file
+buildPlugin(
+ useContainerAgent: false, // Set to `false` if you need to use Docker for containerized tests
+ failFast: false,
+ configurations: [
+ [platform: 'linux', jdk: 21],
+ ]
+)
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 419dc602..6c097528 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.jenkins-ci.plugins
plugin
- 4.32
+ 4.87
@@ -18,17 +18,14 @@
999999-SNAPSHOT
jenkinsci/${project.artifactId}-plugin
- 2.277.4
- 8
- 1674.v3b8b1441e939
+ 2.361.4
- 4.5.13
+ 4.5.14
2.8.8
2.35.0
- 23.0
0.9.4.0
5.10.2
1.16.2
@@ -37,7 +34,7 @@
2.7
3.21.0
- 1.2.3
+ 1.5.8
7.7.0
@@ -48,8 +45,8 @@
io.jenkins.tools.bom
- bom-2.249.x
- 984.vb5eaac999a7e
+ bom-2.361.x
+ 2102.v854b_fec19c92
import
pom
@@ -66,7 +63,7 @@
org.slf4j
slf4j-api
- 2.0.13
+ 2.0.15
org.apache.commons
@@ -122,7 +119,6 @@
com.google.guava
guava
- ${guava.version}
me.redaalaoui.gerrit_rest_java_client
@@ -138,14 +134,12 @@
org.junit.jupiter
junit-jupiter
- ${junit.jupiter.version}
test
org.junit.vintage
junit-vintage-engine
- ${junit.jupiter.version}
test
@@ -183,7 +177,6 @@
org.mockito
mockito-core
- 4.2.0
test
@@ -194,7 +187,6 @@
org.jenkins-ci.plugins
durable-task
- test
com.fasterxml.jackson.core
diff --git a/src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritPublisher.java b/src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritPublisher.java
index a0a38378..4ede17be 100644
--- a/src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritPublisher.java
+++ b/src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritPublisher.java
@@ -138,7 +138,7 @@ public void perform(
} catch (RestApiException e) {
LOGGER.log(Level.SEVERE, e, () -> "Unable to post review: " + e.getMessage());
throw new AbortException("Unable to post review: " + e.getMessage());
- } catch (NullPointerException | IllegalArgumentException | IllegalStateException e) {
+ } catch (IllegalArgumentException | IllegalStateException e) {
LOGGER.log(Level.SEVERE, e, e::getMessage);
throw new IOException(e.getMessage(), e);
}
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/HttpUsernamePasswordPipelineMigrationTest.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/HttpUsernamePasswordPipelineMigrationTest.java
index cec3e3fa..dd5aff9e 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/HttpUsernamePasswordPipelineMigrationTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/HttpUsernamePasswordPipelineMigrationTest.java
@@ -66,16 +66,24 @@ static void beforeAll(Cluster cluster, @TempDir Path workTree) throws Exception
"\n"
+ "\n"
+ " 4.0.0\n"
- + "\n"
+ " org.example\n"
+ " example\n"
+ " 1.0-SNAPSHOT\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " org.apache.maven.plugins\n"
+ + " maven-compiler-plugin\n"
+ + " 3.12.1\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ "");
git.push();
FreeStyleProject masterJob = cluster.jenkinsRule().createFreeStyleProject();
- masterJob.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk8InstallationName()));
+ masterJob.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk17InstallationName()));
masterJob.setScm(createGitSCM());
masterJob
.getBuildWrappersList()
@@ -163,7 +171,7 @@ private Job createPipelineJob(GerritChange change) throws IOException {
"withSonarQubeEnv('%s') {\n", cluster.jenkinsSonarqubeInstallationName())
+ String.format(
"withMaven(jdk: '%s', maven: '%s') {\n",
- cluster.jenkinsJdk8InstallationName(), cluster.jenkinsMavenInstallationName())
+ cluster.jenkinsJdk17InstallationName(), cluster.jenkinsMavenInstallationName())
+ String.format("sh \"mvn %s\"\n", MAVEN_TARGET)
+ "}\n" // withMaven
+ "}\n" // withSonarQubeEnv
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/ReviewTest.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/ReviewTest.java
index 8bc1e8bc..91f9172e 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/ReviewTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/gerrit/ReviewTest.java
@@ -64,6 +64,15 @@ static void beforeAll(Cluster cluster, @TempDir Path workTree) throws Exception
+ " 1.0-SNAPSHOT\n"
+ " pom"
+ "\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " org.apache.maven.plugins\n"
+ + " maven-compiler-plugin\n"
+ + " 3.12.1\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ "\n"
+ "child1"
+ ""
@@ -87,7 +96,7 @@ static void beforeAll(Cluster cluster, @TempDir Path workTree) throws Exception
git.push();
FreeStyleProject masterJob = cluster.jenkinsRule().createFreeStyleProject();
- masterJob.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk8InstallationName()));
+ masterJob.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk17InstallationName()));
masterJob.setScm(createGitSCM());
masterJob
.getBuildWrappersList()
@@ -240,7 +249,7 @@ private Job createPipelineJob(
"withSonarQubeEnv('%s') {\n", cluster.jenkinsSonarqubeInstallationName())
+ String.format(
"withMaven(jdk: '%s', maven: '%s') {\n",
- cluster.jenkinsJdk8InstallationName(), cluster.jenkinsMavenInstallationName())
+ cluster.jenkinsJdk17InstallationName(), cluster.jenkinsMavenInstallationName())
+ String.format("sh \"mvn %s\"\n", MAVEN_TARGET)
+ "}\n" // withMaven
+ "}\n" // withSonarQubeEnv
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/preview_mode_analysis/PreviewModeAnalysisTest.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/preview_mode_analysis/PreviewModeAnalysisTest.java
deleted file mode 100644
index 9e81903c..00000000
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/preview_mode_analysis/PreviewModeAnalysisTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-package org.jenkinsci.plugins.sonargerrit.sonar.preview_mode_analysis;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import hudson.model.FreeStyleProject;
-import hudson.model.Job;
-import hudson.model.queue.QueueTaskFuture;
-import hudson.plugins.git.BranchSpec;
-import hudson.plugins.git.GitSCM;
-import hudson.plugins.git.UserRemoteConfig;
-import hudson.plugins.sonar.SonarBuildWrapper;
-import hudson.tasks.Maven;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.Collections;
-import java.util.List;
-import jenkins.model.Jenkins;
-import jenkins.model.ParameterizedJobMixIn;
-import me.redaalaoui.gerrit_rest_java_client.thirdparty.com.google.gerrit.extensions.common.ChangeInfo;
-import org.eclipse.jgit.api.errors.GitAPIException;
-import org.jenkinsci.plugins.sonargerrit.SonarToGerritPublisher;
-import org.jenkinsci.plugins.sonargerrit.gerrit.ScoreConfig;
-import org.jenkinsci.plugins.sonargerrit.sonar.Inspection;
-import org.jenkinsci.plugins.sonargerrit.sonar.IssueFilterConfig;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.cluster.Cluster;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.cluster.EnableCluster;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.gerrit.GerritChange;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.gerrit.GerritGit;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.gerrit.GerritServer;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.jenkins.EnvironmentVariableBuildWrapper;
-import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
-import org.jenkinsci.plugins.workflow.job.WorkflowJob;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-/** @author Réda Housni Alaoui */
-@EnableCluster
-class PreviewModeAnalysisTest {
-
- private static final String MAVEN_TARGET =
- "clean verify sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json";
-
- private static Cluster cluster;
- private static GerritGit git;
-
- @BeforeAll
- static void beforeAll(Cluster cluster, @TempDir Path workTree)
- throws GitAPIException, IOException {
-
- PreviewModeAnalysisTest.cluster = cluster;
-
- git = GerritGit.createAndCloneRepository(cluster.gerrit(), workTree);
-
- git.addAndCommitFile(
- "pom.xml",
- "\n"
- + "\n"
- + " 4.0.0\n"
- + "\n"
- + " org.example\n"
- + " example\n"
- + " 1.0-SNAPSHOT\n"
- + "");
-
- git.push();
- }
-
- @BeforeEach
- void beforeEach() throws GitAPIException {
- git.resetToOriginMaster();
- }
-
- @Test
- @DisplayName("Bad quality freestyle build")
- void test1() throws Exception {
- testWithBadQualityCode(this::createFreestyleJob);
- }
-
- @Test
- @DisplayName("Good quality freestyle build")
- void test2() throws Exception {
- testWithGoodQualityCode(this::createFreestyleJob);
- }
-
- @Test
- @DisplayName("Bad quality pipeline build")
- void test3() throws Exception {
- testWithBadQualityCode(this::createPipelineJob);
- }
-
- @Test
- @DisplayName("Good quality pipeline build")
- void test4() throws Exception {
- testWithGoodQualityCode(this::createPipelineJob);
- }
-
- private void testWithBadQualityCode(JobFactory jobFactory) throws Exception {
- git.addAndCommitFile(
- "src/main/java/org/example/UselessConstructorDeclaration.java",
- "package org.example; "
- + "public class UselessConstructorDeclaration { "
- + "public UselessConstructorDeclaration() {} "
- + "}");
- GerritChange change = git.createGerritChangeForMaster();
-
- triggerAndAssertSuccess(jobFactory.build(change));
-
- ChangeInfo changeDetail = change.getDetail();
- assertThat(changeDetail.labels.get(GerritServer.CODE_QUALITY_LABEL).all)
- .hasSize(1)
- .map(approvalInfo -> approvalInfo.value)
- .containsExactly(-1);
- assertThat(change.listComments())
- .map(commentInfo -> commentInfo.message)
- .filteredOn(message -> message.contains("S1186"))
- .hasSize(1);
- }
-
- private void testWithGoodQualityCode(JobFactory jobFactory) throws Exception {
- git.addAndCommitFile(
- "src/main/java/org/example/Foo.java", "package org.example; public interface Foo {}");
- GerritChange change = git.createGerritChangeForMaster();
-
- triggerAndAssertSuccess(jobFactory.build(change));
-
- ChangeInfo changeDetail = change.getDetail();
- assertThat(changeDetail.labels.get(GerritServer.CODE_QUALITY_LABEL).all)
- .hasSize(1)
- .map(approvalInfo -> approvalInfo.value)
- .containsExactly(1);
- assertThat(change.listComments()).isEmpty();
- }
-
- @SuppressWarnings("rawtypes")
- private Job createFreestyleJob(GerritChange change) throws IOException {
- FreeStyleProject job = cluster.jenkinsRule().createFreeStyleProject();
- job.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk8InstallationName()));
-
- int patchSetNumber = 1;
- job.setScm(createGitSCM(change, patchSetNumber));
-
- job.getBuildWrappersList()
- .add(new SonarBuildWrapper(cluster.jenkinsSonarqube7InstallationName()));
-
- job.getBuildWrappersList()
- .add(
- new EnvironmentVariableBuildWrapper()
- .add("GERRIT_NAME", cluster.jenkinsGerritTriggerServerName())
- .add("GERRIT_CHANGE_NUMBER", change.changeNumericId())
- .add("GERRIT_PATCHSET_NUMBER", String.valueOf(patchSetNumber)));
-
- job.getBuildersList().add(new Maven(MAVEN_TARGET, cluster.jenkinsMavenInstallationName()));
-
- SonarToGerritPublisher sonarToGerrit = new SonarToGerritPublisher();
- Inspection inspectionConfig = sonarToGerrit.getInspectionConfig();
- PreviewModeAnalysisStrategy analysisStrategy = new PreviewModeAnalysisStrategy();
- analysisStrategy.setSonarQubeInstallationName(cluster.jenkinsSonarqube7InstallationName());
- analysisStrategy.setAutoMatch(true);
- inspectionConfig.setAnalysisStrategy(analysisStrategy);
- IssueFilterConfig issueFilterConfig = sonarToGerrit.getReviewConfig().getIssueFilterConfig();
- issueFilterConfig.setSeverity("MINOR");
- issueFilterConfig.setChangedLinesOnly(true);
-
- ScoreConfig scoreConfig = new ScoreConfig();
- scoreConfig.getIssueFilterConfig().setSeverity("MINOR");
- scoreConfig.getIssueFilterConfig().setNewIssuesOnly(false);
- scoreConfig.getIssueFilterConfig().setChangedLinesOnly(true);
- scoreConfig.setCategory(GerritServer.CODE_QUALITY_LABEL);
- scoreConfig.setNoIssuesScore(1);
- scoreConfig.setIssuesScore(-1);
- sonarToGerrit.setScoreConfig(scoreConfig);
- job.getPublishersList().add(sonarToGerrit);
- return job;
- }
-
- @SuppressWarnings("rawtypes")
- private Job createPipelineJob(GerritChange change) throws IOException {
- WorkflowJob job = cluster.jenkinsRule().createProject(WorkflowJob.class);
- int patchSetNumber = 1;
- String script =
- "node {\n"
- + "stage('Build') {\n"
- + "try {\n"
- + String.format("env.GERRIT_NAME = '%s'\n", cluster.jenkinsGerritTriggerServerName())
- + String.format("env.GERRIT_CHANGE_NUMBER = '%s'\n", change.changeNumericId())
- + String.format("env.GERRIT_PATCHSET_NUMBER = '%s'\n", patchSetNumber)
- + "checkout scm: ([\n"
- + "$class: 'GitSCM',\n"
- + String.format(
- "userRemoteConfigs: [[url: '%s', refspec: '%s', credentialsId: '%s']],\n",
- git.httpUrl(), change.refName(patchSetNumber), cluster.jenkinsGerritCredentialsId())
- + "branches: [[name: 'FETCH_HEAD']]\n"
- + "])\n"
- + String.format(
- "withSonarQubeEnv('%s') {\n", cluster.jenkinsSonarqube7InstallationName())
- + String.format(
- "withMaven(jdk: '%s', maven: '%s') {\n",
- cluster.jenkinsJdk8InstallationName(), cluster.jenkinsMavenInstallationName())
- + String.format("sh 'mvn %s'\n", MAVEN_TARGET)
- + "}\n" // withMaven
- + "}\n" // withSonarQubeEnv
- + "} finally {\n"
- + "sonarToGerrit(\n"
- + "inspectionConfig: [\n"
- + "analysisStrategy: previewMode(\n"
- + String.format(
- "sonarQubeInstallationName: '%s',\n", cluster.jenkinsSonarqube7InstallationName())
- + "baseConfig: [autoMatch: true]\n"
- + ")\n"
- + "],\n" // inspectionConfig
- + "reviewConfig: [\n"
- + "issueFilterConfig: [\n"
- + "severity: 'MINOR',\n"
- + "newIssuesOnly: false,\n"
- + "changedLinesOnly: true\n"
- + "]\n" // issueFilterConfig
- + "],\n" // reviewConfig
- + "scoreConfig: [\n"
- + "issueFilterConfig: [\n"
- + "severity: 'MINOR',"
- + "newIssuesOnly: false,"
- + "changedLinesOnly: true"
- + "],\n" // issueFilterConfig
- + String.format("category: '%s',\n", GerritServer.CODE_QUALITY_LABEL)
- + "noIssuesScore: 1,\n"
- + "issuesScore: -1,\n"
- + "]\n" // scoreConfig
- + ")\n" // sonarToGerrit
- + "}\n" // finally
- + "}\n" // stage('Build')
- + "}";
- job.setDefinition(new CpsFlowDefinition(script, true));
- return job;
- }
-
- private GitSCM createGitSCM(GerritChange change, int patchSetNumber) {
- String refName = change.refName(patchSetNumber);
- List remoteConfigs =
- Collections.singletonList(
- new UserRemoteConfig(
- git.httpUrl(), null, refName, cluster.jenkinsGerritCredentialsId()));
- return new GitSCM(
- remoteConfigs,
- Collections.singletonList(new BranchSpec("FETCH_HEAD")),
- null,
- null,
- Collections.emptyList());
- }
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- private void triggerAndAssertSuccess(Job job) throws Exception {
- final QueueTaskFuture future =
- new ParameterizedJobMixIn() {
- @Override
- protected Job asJob() {
- return job;
- }
- }.scheduleBuild2(0);
- cluster.jenkinsRule().assertBuildStatusSuccess(future);
- }
-
- private interface JobFactory {
- @SuppressWarnings("rawtypes")
- Job build(GerritChange change) throws Exception;
- }
-}
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java
index 71988783..6219c1c6 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java
@@ -71,12 +71,21 @@ static void beforeAll(Cluster cluster, @TempDir Path workTree) throws Exception
+ " org.example\n"
+ " example\n"
+ " 1.0-SNAPSHOT\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " org.apache.maven.plugins\n"
+ + " maven-compiler-plugin\n"
+ + " 3.12.1\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ "");
git.push();
FreeStyleProject masterJob = cluster.jenkinsRule().createFreeStyleProject();
- masterJob.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk8InstallationName()));
+ masterJob.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk17InstallationName()));
masterJob.setScm(createGitSCM());
masterJob
.getBuildWrappersList()
@@ -159,7 +168,7 @@ private void testWithGoodQualityCode(JobFactory jobFactory) throws Exception {
@SuppressWarnings("rawtypes")
private Job createFreestyleJob(GerritChange change) throws IOException {
FreeStyleProject job = cluster.jenkinsRule().createFreeStyleProject();
- job.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk8InstallationName()));
+ job.setJDK(Jenkins.get().getJDK(cluster.jenkinsJdk17InstallationName()));
int patchSetNumber = 1;
job.setScm(createGitSCM(change, patchSetNumber));
@@ -222,7 +231,7 @@ private Job createPipelineJob(GerritChange change) throws IOException {
"withSonarQubeEnv('%s') {\n", cluster.jenkinsSonarqubeInstallationName())
+ String.format(
"withMaven(jdk: '%s', maven: '%s') {\n",
- cluster.jenkinsJdk8InstallationName(), cluster.jenkinsMavenInstallationName())
+ cluster.jenkinsJdk17InstallationName(), cluster.jenkinsMavenInstallationName())
+ String.format("sh \"mvn %s\"\n", MAVEN_PIPELINE_TARGET)
+ "}\n" // withMaven
+ "}\n" // withSonarQubeEnv
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/LogbackConfigurator.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/LogbackConfigurator.java
index 0ddc3db8..c1f5fea6 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/LogbackConfigurator.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/LogbackConfigurator.java
@@ -8,7 +8,8 @@
/** @author Réda Housni Alaoui */
public class LogbackConfigurator extends BasicConfigurator {
- public void configure(LoggerContext lc) {
+ @Override
+ public ExecutionStatus configure(LoggerContext lc) {
super.configure(lc);
Level rootLevel =
Optional.ofNullable(System.getenv("SONAR_GERRIT_PLUGIN_TEST_LOG_ROOT_LEVEL"))
@@ -16,5 +17,6 @@ public void configure(LoggerContext lc) {
.orElse(Level.OFF);
lc.getLogger("ROOT").setLevel(rootLevel);
lc.getLogger("com.sonyericsson.hudson").setLevel(Level.WARN);
+ return ExecutionStatus.NEUTRAL;
}
}
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/Cluster.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/Cluster.java
index 2522fe11..6817c46b 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/Cluster.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/Cluster.java
@@ -13,7 +13,6 @@
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.jenkins.JDKs;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.jenkins.MavenConfiguration;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.jenkins.SonarqubeConfiguration;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube.Sonarqube7Server;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube.SonarqubeAccessTokens;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube.SonarqubeServer;
import org.jvnet.hudson.test.JenkinsRule;
@@ -26,17 +25,12 @@ public class Cluster {
private final JenkinsRule jenkinsRule;
private final String jenkinsGerritCredentialsId;
- private final String jenkinsJdk8InstallationName;
+ private final String jenkinsJdk17InstallationName;
private final String jenkinsMavenInstallationName;
- private final String jenkinsSonarqube7InstallationName;
private final String jenkinsSonarqubeInstallationName;
private final String jenkinsGerritTriggerServerName;
- private Cluster(
- GerritServer gerrit,
- Sonarqube7Server sonarqube7,
- SonarqubeServer sonarqube,
- JenkinsRule jenkinsRule)
+ private Cluster(GerritServer gerrit, SonarqubeServer sonarqube, JenkinsRule jenkinsRule)
throws IOException {
this.gerrit = requireNonNull(gerrit);
this.sonarqube = requireNonNull(sonarqube);
@@ -54,7 +48,7 @@ private Cluster(
credentialsProvider.getCredentials().add(credentials);
credentialsProvider.save();
- jenkinsJdk8InstallationName = new JDKs(jenkinsRule.jenkins).addJdk8();
+ jenkinsJdk17InstallationName = new JDKs(jenkinsRule.jenkins).addJdk17();
jenkinsMavenInstallationName = new MavenConfiguration(jenkinsRule.jenkins).addInstallation();
jenkinsGerritTriggerServerName =
@@ -63,11 +57,6 @@ private Cluster(
SonarqubeConfiguration sonarqubeConfiguration = new SonarqubeConfiguration(jenkinsRule.jenkins);
- jenkinsSonarqube7InstallationName =
- sonarqubeConfiguration.addInstallation(
- sonarqube7.url(),
- new SonarqubeAccessTokens(sonarqube7.url(), sonarqube7.adminAuthorization())
- .createAdminAccessToken(UUID.randomUUID().toString()));
jenkinsSonarqubeInstallationName =
sonarqubeConfiguration.addInstallation(
sonarqube.url(),
@@ -76,12 +65,8 @@ private Cluster(
}
public static Cluster configure(
- GerritServer gerrit,
- Sonarqube7Server sonarqube7,
- SonarqubeServer sonarqube,
- JenkinsRule jenkinsRule)
- throws IOException {
- return new Cluster(gerrit, sonarqube7, sonarqube, jenkinsRule);
+ GerritServer gerrit, SonarqubeServer sonarqube, JenkinsRule jenkinsRule) throws IOException {
+ return new Cluster(gerrit, sonarqube, jenkinsRule);
}
public String jenkinsGerritCredentialsId() {
@@ -104,16 +89,12 @@ public String jenkinsMavenInstallationName() {
return jenkinsMavenInstallationName;
}
- public String jenkinsSonarqube7InstallationName() {
- return jenkinsSonarqube7InstallationName;
- }
-
public String jenkinsSonarqubeInstallationName() {
return jenkinsSonarqubeInstallationName;
}
- public String jenkinsJdk8InstallationName() {
- return jenkinsJdk8InstallationName;
+ public String jenkinsJdk17InstallationName() {
+ return jenkinsJdk17InstallationName;
}
public String jenkinsGerritTriggerServerName() {
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/ClusterTestExtension.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/ClusterTestExtension.java
index fd4abdf0..fc06ba78 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/ClusterTestExtension.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/ClusterTestExtension.java
@@ -1,7 +1,6 @@
package org.jenkinsci.plugins.sonargerrit.test_infrastructure.cluster;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.gerrit.GerritServer;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube.Sonarqube7Server;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube.SonarqubeServer;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
@@ -20,13 +19,10 @@ public void beforeAll(ExtensionContext context) throws Exception {
}
GerritServer gerritServer = store.get(GerritServer.class, GerritServer.class);
- Sonarqube7Server sonarqube7Server = store.get(Sonarqube7Server.class, Sonarqube7Server.class);
SonarqubeServer sonarqubeServer = store.get(SonarqubeServer.class, SonarqubeServer.class);
JenkinsRule jenkinsRule = store.get(JenkinsRule.class, JenkinsRule.class);
- store.put(
- Cluster.class,
- Cluster.configure(gerritServer, sonarqube7Server, sonarqubeServer, jenkinsRule));
+ store.put(Cluster.class, Cluster.configure(gerritServer, sonarqubeServer, jenkinsRule));
}
@Override
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/EnableCluster.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/EnableCluster.java
index 175fd02a..7ed47ae4 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/EnableCluster.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/cluster/EnableCluster.java
@@ -8,7 +8,6 @@
import java.lang.annotation.Target;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.gerrit.EnableGerritServer;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.jenkins.EnableJenkinsRule;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube.EnableSonarqube7Server;
import org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube.EnableSonarqubeServer;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -16,7 +15,6 @@
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@EnableGerritServer
-@EnableSonarqube7Server
@EnableSonarqubeServer
@EnableJenkinsRule
@ExtendWith(ClusterTestExtension.class)
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JDKs.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JDKs.java
index a4bd009c..29050ea8 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JDKs.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JDKs.java
@@ -17,10 +17,10 @@ public JDKs(Jenkins jenkins) {
this.jenkins = jenkins;
}
- public String addJdk8() throws IOException {
+ public String addJdk17() throws IOException {
return addJdk(
- "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u312-b07/OpenJDK8U-jdk_x64_linux_hotspot_8u312b07.tar.gz",
- "jdk8u312-b07");
+ "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.12%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.12_7.tar.gz",
+ "jdk-17.0.12+7");
}
private String addJdk(String url, String subdir) throws IOException {
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JupiterJenkinsRule.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JupiterJenkinsRule.java
index 07263347..0be034cb 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JupiterJenkinsRule.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/jenkins/JupiterJenkinsRule.java
@@ -1,13 +1,17 @@
package org.jenkinsci.plugins.sonargerrit.test_infrastructure.jenkins;
+import java.nio.file.FileSystemException;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.platform.commons.util.AnnotationUtils;
import org.jvnet.hudson.test.JenkinsRecipe;
import org.jvnet.hudson.test.JenkinsRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/** @author Réda Housni Alaoui */
class JupiterJenkinsRule extends JenkinsRule implements ExtensionContext.Store.CloseableResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(JupiterJenkinsRule.class);
private final ExtensionContext context;
JupiterJenkinsRule(ExtensionContext context) {
@@ -35,6 +39,11 @@ public void recipe() throws Exception {
@Override
public void close() throws Throwable {
- after();
+ try {
+ after();
+ } catch (FileSystemException e) {
+ // Can happen on Windows CI agent
+ LOGGER.warn(e.getMessage());
+ }
}
}
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/EnableSonarqube7Server.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/EnableSonarqube7Server.java
deleted file mode 100644
index 55098781..00000000
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/EnableSonarqube7Server.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube;
-
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.docker_network.EnableDockerNetwork;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-/** @author Réda Housni Alaoui */
-@Target({TYPE, ANNOTATION_TYPE})
-@Retention(RUNTIME)
-@EnableDockerNetwork
-@ExtendWith(Sonarqube7TestExtension.class)
-public @interface EnableSonarqube7Server {}
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/Sonarqube7Server.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/Sonarqube7Server.java
deleted file mode 100644
index e7067533..00000000
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/Sonarqube7Server.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Base64;
-import okhttp3.MediaType;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.CloseableResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.containers.Network;
-import org.testcontainers.containers.output.Slf4jLogConsumer;
-
-/** @author Réda Housni Alaoui */
-public class Sonarqube7Server {
-
- private static final Logger LOG = LoggerFactory.getLogger(Sonarqube7Server.class);
-
- private static final int HTTP_PORT = 9000;
-
- private static final String NETWORK_ALIAS = "sonarqube";
- private static final String ADMIN_USERNAME = "admin";
-
- private final GenericContainer> container;
- private final String url;
- private final String adminPassword;
-
- public static CloseableResource start(Network network) {
- Sonarqube7Server sonarqubeServer = new Sonarqube7Server(network);
- return new CloseableResource() {
- @Override
- public Sonarqube7Server resource() {
- return sonarqubeServer;
- }
-
- @Override
- public void close() {
- sonarqubeServer.stop();
- }
- };
- }
-
- private Sonarqube7Server(Network network) {
- container =
- new GenericContainer<>("sonarqube:7.6-community")
- .withLogConsumer(new Slf4jLogConsumer(LOG))
- .withExposedPorts(HTTP_PORT)
- .withNetwork(network)
- .withNetworkAliases(NETWORK_ALIAS);
- container.start();
- url = "http://localhost:" + container.getMappedPort(HTTP_PORT);
-
- adminPassword = "1234";
- changeOwnPassword(url, ADMIN_USERNAME, "admin", adminPassword);
- authorizeThirdPartyPlugins(url, adminPassword);
- }
-
- public String url() {
- return url;
- }
-
- public String adminAuthorization() {
- return createAuthorization(ADMIN_USERNAME, adminPassword);
- }
-
- private void stop() {
- container.stop();
- }
-
- private static void changeOwnPassword(
- String sonarqubeUrl, String username, String currentPassword, String newPassword) {
- OkHttpClient httpClient = SonarqubeOkHttpClients.get();
- RequestBody requestBody =
- RequestBody.create(
- MediaType.parse("application/x-www-form-urlencoded"),
- "login="
- + username
- + "&previousPassword="
- + currentPassword
- + "&password="
- + newPassword);
- Request request =
- new Request.Builder()
- .url(sonarqubeUrl + "/api/users/change_password")
- .header("Authorization", createAuthorization(username, currentPassword))
- .post(requestBody)
- .build();
- try (Response response = httpClient.newCall(request).execute()) {
- if (response.isSuccessful()) {
- return;
- }
- throw new IllegalStateException(
- "Own password change failed with code "
- + response.code()
- + " and message '"
- + response.message()
- + "'");
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private static void authorizeThirdPartyPlugins(String sonarqubeUrl, String adminPassword) {
- OkHttpClient httpClient = SonarqubeOkHttpClients.get();
- RequestBody requestBody =
- RequestBody.create(
- MediaType.parse("application/x-www-form-urlencoded"),
- "key=sonar.plugins.risk.consent&value=ACCEPTED");
- Request request =
- new Request.Builder()
- .url(sonarqubeUrl + "/api/settings/set")
- .header("Authorization", createAuthorization(ADMIN_USERNAME, adminPassword))
- .post(requestBody)
- .build();
- try (Response response = httpClient.newCall(request).execute()) {
- if (response.isSuccessful()) {
- return;
- }
- throw new IllegalStateException(
- "Third party plugins authorization failed with code "
- + response.code()
- + " and message '"
- + response.message()
- + "'");
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private static String createAuthorization(String username, String password) {
- return "Basic "
- + Base64.getEncoder()
- .encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
- }
-}
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/Sonarqube7TestExtension.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/Sonarqube7TestExtension.java
deleted file mode 100644
index 96631527..00000000
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/Sonarqube7TestExtension.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.jenkinsci.plugins.sonargerrit.test_infrastructure.sonarqube;
-
-import org.jenkinsci.plugins.sonargerrit.test_infrastructure.docker_network.DockerDependentTestExtension;
-
-class Sonarqube7TestExtension extends DockerDependentTestExtension {
-
- protected Sonarqube7TestExtension() {
- super(Sonarqube7Server.class, Sonarqube7Server::start);
- }
-}
diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/SonarqubeServer.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/SonarqubeServer.java
index 659da2c9..97d524f8 100644
--- a/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/SonarqubeServer.java
+++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/test_infrastructure/sonarqube/SonarqubeServer.java
@@ -52,7 +52,7 @@ private SonarqubeServer(Network network) {
.withDockerfileFromBuilder(
builder ->
builder
- .from("docker.cosium.dev/sonarqube:8.9.2-community")
+ .from("sonarqube:8.9.2-community")
.add(
"https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/download/1.8.1/sonarqube-community-branch-plugin-1.8.1.jar",
"/opt/sonarqube/extensions/plugins/sonarqube-community-branch-plugin.jar")))