diff --git a/pom.xml b/pom.xml index 906e19ad4..7287d31a8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.88 + 5.4 @@ -44,8 +44,8 @@ 999999-SNAPSHOT jenkinsci/${project.artifactId}-plugin - 2.452 - ${jenkins.baseline}.4 + 2.479 + ${jenkins.baseline}.1 Max Low false diff --git a/src/main/java/org/jenkinsci/plugins/badge/EmbeddableBadgeConfig.java b/src/main/java/org/jenkinsci/plugins/badge/EmbeddableBadgeConfig.java index 5b517d734..29baa4718 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/EmbeddableBadgeConfig.java +++ b/src/main/java/org/jenkinsci/plugins/badge/EmbeddableBadgeConfig.java @@ -4,14 +4,18 @@ */ package org.jenkinsci.plugins.badge; +import java.io.Serial; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; public class EmbeddableBadgeConfig implements Serializable { + @Serial private static final long serialVersionUID = 1L; + private final Map colors = new HashMap<>() { + @Serial private static final long serialVersionUID = 1L; { diff --git a/src/main/java/org/jenkinsci/plugins/badge/StatusImage.java b/src/main/java/org/jenkinsci/plugins/badge/StatusImage.java index c4b8f2f52..02a4a847d 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/StatusImage.java +++ b/src/main/java/org/jenkinsci/plugins/badge/StatusImage.java @@ -5,10 +5,11 @@ */ package org.jenkinsci.plugins.badge; -import static javax.servlet.http.HttpServletResponse.*; +import static jakarta.servlet.http.HttpServletResponse.*; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.PluginWrapper; +import jakarta.servlet.ServletException; import java.awt.Canvas; import java.awt.Font; import java.awt.FontFormatException; @@ -23,13 +24,12 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import javax.servlet.ServletException; import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringEscapeUtils; import org.kohsuke.stapler.HttpResponse; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; /** * Status image as an {@link HttpResponse}, with proper cache handling. @@ -242,7 +242,7 @@ public int measureText(String text) throws IOException { } @Override - public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) + public void generateResponse(StaplerRequest2 req, StaplerResponse2 rsp, Object node) throws IOException, ServletException { String v = req.getHeader("If-None-Match"); if (etag.equals(v)) { diff --git a/src/main/java/org/jenkinsci/plugins/badge/actions/EmbeddableBadgeConfigsAction.java b/src/main/java/org/jenkinsci/plugins/badge/actions/EmbeddableBadgeConfigsAction.java index 9da913e12..bd52ae962 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/actions/EmbeddableBadgeConfigsAction.java +++ b/src/main/java/org/jenkinsci/plugins/badge/actions/EmbeddableBadgeConfigsAction.java @@ -8,6 +8,7 @@ import hudson.model.BuildBadgeAction; import hudson.model.Job; import hudson.model.Run; +import java.io.Serial; import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -20,7 +21,9 @@ */ @ExportedBean(defaultVisibility = 2) public class EmbeddableBadgeConfigsAction implements Action, Serializable, BuildBadgeAction { + @Serial private static final long serialVersionUID = 1L; + private Map badgeConfigs = new HashMap<>(); public EmbeddableBadgeConfigsAction() {} diff --git a/src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java b/src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java index f6d1cfc2b..c8c3a1b37 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java +++ b/src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java @@ -15,7 +15,7 @@ import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.kohsuke.stapler.WebMethod; /** @@ -52,7 +52,7 @@ public String getUrlName() { public String getUrl() { /* Needed for the jelly syntax hints page */ String url = ""; - StaplerRequest req = Stapler.getCurrentRequest(); + StaplerRequest2 req = Stapler.getCurrentRequest2(); if (req != null && req.getRequestURL() != null) { url = req.getRequestURL().toString(); int badgeIndex = url.lastIndexOf("badge/"); diff --git a/src/main/java/org/jenkinsci/plugins/badge/actions/PublicBuildStatusAction.java b/src/main/java/org/jenkinsci/plugins/badge/actions/PublicBuildStatusAction.java index fc6d9d7f6..39e9f1d63 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/actions/PublicBuildStatusAction.java +++ b/src/main/java/org/jenkinsci/plugins/badge/actions/PublicBuildStatusAction.java @@ -25,8 +25,8 @@ import org.jenkinsci.plugins.badge.extensionpoints.RunSelectorExtensionPoint; import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.kohsuke.stapler.WebMethod; /** @@ -65,8 +65,8 @@ public String getDisplayName() { @WebMethod(name = "icon") public HttpResponse doIcon( - StaplerRequest req, - StaplerResponse rsp, + StaplerRequest2 req, + StaplerResponse2 rsp, @QueryParameter String job, @QueryParameter String build, @QueryParameter String style, @@ -94,8 +94,8 @@ public HttpResponse doIcon( @WebMethod(name = "icon.svg") public HttpResponse doIconDotSvg( - StaplerRequest req, - StaplerResponse rsp, + StaplerRequest2 req, + StaplerResponse2 rsp, @QueryParameter String job, @QueryParameter String build, @QueryParameter String style, @@ -109,7 +109,7 @@ public HttpResponse doIconDotSvg( } public String doText( - StaplerRequest req, StaplerResponse rsp, @QueryParameter String job, @QueryParameter String build) { + StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter String job, @QueryParameter String build) { if (job == null) { return "Missing query parameter: job"; } diff --git a/src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java b/src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java index e12c12df7..5ecea61ea 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java +++ b/src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java @@ -14,7 +14,7 @@ import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.kohsuke.stapler.WebMethod; public class RunBadgeAction implements Action, IconSpec { @@ -50,7 +50,7 @@ public String getUrl() { /* TODO: Is a permission check needed here? */ /* Needed for the jelly syntax hints page */ String url = ""; - StaplerRequest req = Stapler.getCurrentRequest(); + StaplerRequest2 req = Stapler.getCurrentRequest2(); if (req != null && req.getRequestURL() != null) { url = req.getRequestURL().toString(); int badgeIndex = url.lastIndexOf("badge/"); diff --git a/src/main/java/org/jenkinsci/plugins/badge/extensions/BuildParameterResolverExtension.java b/src/main/java/org/jenkinsci/plugins/badge/extensions/BuildParameterResolverExtension.java index cdb81f2b5..a6ab8e9f0 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/extensions/BuildParameterResolverExtension.java +++ b/src/main/java/org/jenkinsci/plugins/badge/extensions/BuildParameterResolverExtension.java @@ -21,8 +21,7 @@ public class BuildParameterResolverExtension implements ParameterResolverExtensi @Override public String resolve(Actionable actionable, String parameter) { - if (actionable instanceof Run) { - Run run = (Run) actionable; + if (actionable instanceof Run run) { ParametersAction params = run.getAction(ParametersAction.class); if (params != null) { @@ -68,8 +67,8 @@ public String resolve(Actionable actionable, String parameter) { } } } - } else if (actionable instanceof Job) { - parameter = resolve(((Job) actionable).getLastBuild(), parameter); + } else if (actionable instanceof Job job) { + parameter = resolve(job.getLastBuild(), parameter); } return parameter; } diff --git a/src/main/java/org/jenkinsci/plugins/badge/extensions/SpecialValueParameterResolverExtension.java b/src/main/java/org/jenkinsci/plugins/badge/extensions/SpecialValueParameterResolverExtension.java index 51e438892..8dae6c491 100644 --- a/src/main/java/org/jenkinsci/plugins/badge/extensions/SpecialValueParameterResolverExtension.java +++ b/src/main/java/org/jenkinsci/plugins/badge/extensions/SpecialValueParameterResolverExtension.java @@ -17,8 +17,7 @@ public class SpecialValueParameterResolverExtension implements ParameterResolver @Override public String resolve(Actionable actionable, String parameter) { if (parameter != null) { - if (actionable instanceof Run) { - Run run = (Run) actionable; + if (actionable instanceof Run run) { /* try to match any custom value: ${buildId} ${buildNumber} @@ -36,8 +35,8 @@ public String resolve(Actionable actionable, String parameter) { .replace("displayName", run.getDisplayName()) .replace("startTime", run.getTimestampString()); - } else if (actionable instanceof Job) { - parameter = resolve(((Job) actionable).getLastBuild(), parameter); + } else if (actionable instanceof Job job) { + parameter = resolve(job.getLastBuild(), parameter); } } return parameter; diff --git a/src/test/java/org/jenkinsci/plugins/badge/actions/RunBadgeActionTest.java b/src/test/java/org/jenkinsci/plugins/badge/actions/RunBadgeActionTest.java index 00f3302b7..ade1c06b2 100644 --- a/src/test/java/org/jenkinsci/plugins/badge/actions/RunBadgeActionTest.java +++ b/src/test/java/org/jenkinsci/plugins/badge/actions/RunBadgeActionTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.mockito.MockedStatic; import org.mockito.Mockito; @@ -39,9 +39,9 @@ void getUrlEncodedFullNameWithProjectNull() { @Test void getUrlWithoutBadge() { try (MockedStatic mockedStatic = Mockito.mockStatic(Stapler.class)) { - StaplerRequest staplerRequest = Mockito.mock(StaplerRequest.class); + StaplerRequest2 staplerRequest = Mockito.mock(StaplerRequest2.class); Mockito.when(staplerRequest.getRequestURL()).thenReturn(new StringBuffer("http://jenkins.io/")); - mockedStatic.when(() -> Stapler.getCurrentRequest()).thenReturn(staplerRequest); + mockedStatic.when(() -> Stapler.getCurrentRequest2()).thenReturn(staplerRequest); assertThat(runBadgeAction.getUrl(), is("http://jenkins.io/")); } @@ -50,9 +50,9 @@ void getUrlWithoutBadge() { @Test void getUrlWithBadge() { try (MockedStatic mockedStatic = Mockito.mockStatic(Stapler.class)) { - StaplerRequest staplerRequest = Mockito.mock(StaplerRequest.class); + StaplerRequest2 staplerRequest = Mockito.mock(StaplerRequest2.class); Mockito.when(staplerRequest.getRequestURL()).thenReturn(new StringBuffer("http://jenkins.io/badge/")); - mockedStatic.when(() -> Stapler.getCurrentRequest()).thenReturn(staplerRequest); + mockedStatic.when(() -> Stapler.getCurrentRequest2()).thenReturn(staplerRequest); assertThat(runBadgeAction.getUrl(), is("http://jenkins.io/")); }