Skip to content

Commit

Permalink
Require Jenkins 2.479.1 or newer (#346)
Browse files Browse the repository at this point in the history
* require Jenkins 2.479

* update to Java 17
* use matching plugin BOM

* use Java 17 syntax

Used OpenRewrite

* Adjust mocks for StaplerRequest2

* Require Jenkins 2.479 or newer

Compile with Java 17 and Jakarta EE 9.

* Require Jenkins 2.479.1 or newer

Prefer LTS baseline rather than a weekly baseline

* Use parent pom 5.3

* Use bom 3790.va_b_a_2d26d2b_69

* Use paremt pom 5.4

Use latest plugin BOM

---------

Co-authored-by: Mark Waite <[email protected]>
  • Loading branch information
darinpope and MarkEWaite authored Dec 20, 2024
1 parent f020ea2 commit 5653c6e
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 32 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.4</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -44,8 +44,8 @@
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.452</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.threshold>Low</spotbugs.threshold>
<spotless.check.skip>false</spotless.check.skip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> colors = new HashMap<>() {
@Serial
private static final long serialVersionUID = 1L;

{
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jenkinsci/plugins/badge/StatusImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +21,9 @@
*/
@ExportedBean(defaultVisibility = 2)
public class EmbeddableBadgeConfigsAction implements Action, Serializable, BuildBadgeAction {
@Serial
private static final long serialVersionUID = 1L;

private Map<String, EmbeddableBadgeConfig> badgeConfigs = new HashMap<>();

public EmbeddableBadgeConfigsAction() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {

Check warning on line 70 in src/main/java/org/jenkinsci/plugins/badge/extensions/BuildParameterResolverExtension.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 70 is only partially covered, one branch is missing
parameter = resolve(job.getLastBuild(), parameter);

Check warning on line 71 in src/main/java/org/jenkinsci/plugins/badge/extensions/BuildParameterResolverExtension.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 71 is not covered by tests
}
return parameter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -39,9 +39,9 @@ void getUrlEncodedFullNameWithProjectNull() {
@Test
void getUrlWithoutBadge() {
try (MockedStatic<Stapler> 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/"));
}
Expand All @@ -50,9 +50,9 @@ void getUrlWithoutBadge() {
@Test
void getUrlWithBadge() {
try (MockedStatic<Stapler> 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/"));
}
Expand Down

0 comments on commit 5653c6e

Please sign in to comment.