Skip to content

Commit

Permalink
Migration to Jakarta EE
Browse files Browse the repository at this point in the history
  • Loading branch information
mawinter69 committed Jan 2, 2025
1 parent 1c3bfa3 commit 60d2b06
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
10 changes: 5 additions & 5 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 @@ -49,9 +49,9 @@
</scm>

<properties>
<jenkins.base>2.440</jenkins.base>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>${jenkins.base}.3</jenkins.version>
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<checkstyle.version>10.20.1</checkstyle.version>
<hpi.compatibleSinceVersion>640</hpi.compatibleSinceVersion>
Expand All @@ -61,8 +61,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.base}.x</artifactId>
<version>3221.ve8f7b_fdd149d</version>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3850.vb_c5319efa_e29</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import hudson.security.SecurityRealm;
import hudson.security.SidACL;
import hudson.util.FormValidation;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
Expand All @@ -78,8 +80,6 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.acegisecurity.acls.sid.PrincipalSid;
Expand All @@ -91,8 +91,8 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.kohsuke.stapler.verb.GET;
import org.kohsuke.stapler.verb.POST;
Expand Down Expand Up @@ -431,7 +431,7 @@ public void doAddTemplate(@QueryParameter(required = true) String name,
Set<Permission> permissionSet = PermissionHelper.fromStrings(permissionList, true);
PermissionTemplate template = new PermissionTemplate(permissionSet, name);
if (!overwrite && hasPermissionTemplate(name)) {
Stapler.getCurrentResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "A template with name " + name + " already exists.");
Stapler.getCurrentResponse2().sendError(HttpServletResponse.SC_BAD_REQUEST, "A template with name " + name + " already exists.");
return;
}
permissionTemplates.put(name, template);
Expand Down Expand Up @@ -518,7 +518,9 @@ public void doAddRole(@QueryParameter(required = true) String type,

if (RoleBasedAuthorizationStrategy.PROJECT.equals(type) && templateName != null) {
if (!hasPermissionTemplate(template)) {
Stapler.getCurrentResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "A template with name " + template + " doesn't exists.");
Stapler.getCurrentResponse2().sendError(
HttpServletResponse.SC_BAD_REQUEST, "A template with name " + template + " doesn't exists."
);
return;
}
role.setTemplateName(templateName);
Expand Down Expand Up @@ -844,8 +846,8 @@ public void doGetTemplate(@QueryParameter(required = true) String name) throws I
responseJson.put("permissionIds", permissionsMap);
responseJson.put("isUsed", template.isUsed());
}
Stapler.getCurrentResponse().setContentType("application/json;charset=UTF-8");
Writer writer = Stapler.getCurrentResponse().getCompressedWriter(Stapler.getCurrentRequest());
Stapler.getCurrentResponse2().setContentType("application/json;charset=UTF-8");
Writer writer = Stapler.getCurrentResponse2().getWriter();
responseJson.write(writer);
writer.close();

Expand Down Expand Up @@ -907,8 +909,8 @@ public void doGetRole(@QueryParameter(required = true) String type,
}
}

Stapler.getCurrentResponse().setContentType("application/json;charset=UTF-8");
Writer writer = Stapler.getCurrentResponse().getCompressedWriter(Stapler.getCurrentRequest());
Stapler.getCurrentResponse2().setContentType("application/json;charset=UTF-8");
Writer writer = Stapler.getCurrentResponse2().getWriter();
responseJson.write(writer);
writer.close();
}
Expand Down Expand Up @@ -948,8 +950,8 @@ public void doGetAllRoles(@QueryParameter(fixEmpty = true) String type) throws I
responseJson.put(grantedRole.getKey().getName(), grantedRole.getValue());
}

Stapler.getCurrentResponse().setContentType("application/json;charset=UTF-8");
Writer writer = Stapler.getCurrentResponse().getCompressedWriter(Stapler.getCurrentRequest());
Stapler.getCurrentResponse2().setContentType("application/json;charset=UTF-8");
Writer writer = Stapler.getCurrentResponse2().getWriter();
responseJson.write(writer);
writer.close();
}
Expand All @@ -974,9 +976,9 @@ public void doGetMatchingJobs(@QueryParameter(required = true) String pattern,
JSONObject responseJson = new JSONObject();
responseJson.put("matchingJobs", matchingItems);
responseJson.put("itemCount", itemCount);
StaplerResponse response = Stapler.getCurrentResponse();
StaplerResponse2 response = Stapler.getCurrentResponse2();
response.setContentType("application/json;charset=UTF-8");
Writer writer = response.getCompressedWriter(Stapler.getCurrentRequest());
Writer writer = response.getWriter();
responseJson.write(writer);
writer.close();
}
Expand All @@ -1001,9 +1003,9 @@ public void doGetMatchingAgents(@QueryParameter(required = true) String pattern,
JSONObject responseJson = new JSONObject();
responseJson.put("matchingAgents", matchingAgents);
responseJson.put("agentCount", agentCount);
StaplerResponse response = Stapler.getCurrentResponse();
StaplerResponse2 response = Stapler.getCurrentResponse2();
response.setContentType("application/json;charset=UTF-8");
Writer writer = response.getCompressedWriter(Stapler.getCurrentRequest());
Writer writer = response.getWriter();
responseJson.write(writer);
writer.close();
}
Expand Down Expand Up @@ -1269,7 +1271,7 @@ public FormValidation doCheckForWhitespace(@QueryParameter String value) {
*/
@RequirePOST
@Restricted(NoExternalUse.class)
public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
public void doRolesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException {
checkAdminPerm();

req.setCharacterEncoding("UTF-8");
Expand All @@ -1285,7 +1287,7 @@ public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws Servle
*/
@RequirePOST
@Restricted(NoExternalUse.class)
public void doAssignSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
public void doAssignSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException {
checkAdminPerm();

req.setCharacterEncoding("UTF-8");
Expand Down Expand Up @@ -1330,7 +1332,7 @@ public void doAssignSubmit(StaplerRequest req, StaplerResponse rsp) throws Servl
*/
@RequirePOST
@Restricted(NoExternalUse.class)
public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
public void doTemplatesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException {
checkAdminPerm();
req.setCharacterEncoding("UTF-8");
JSONObject json = req.getSubmittedForm();
Expand Down Expand Up @@ -1364,7 +1366,7 @@ public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws Se
* {@link AuthorizationStrategy} object.
*/
@Override
public AuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) {
public AuthorizationStrategy newInstance(StaplerRequest2 req, JSONObject formData) {
AuthorizationStrategy oldStrategy = instance().getAuthorizationStrategy();
RoleBasedAuthorizationStrategy strategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import hudson.security.AuthorizationStrategy;
import hudson.security.Permission;
import hudson.util.FormApply;
import jakarta.servlet.ServletException;
import java.io.IOException;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
Expand Down Expand Up @@ -149,7 +149,7 @@ public AuthorizationStrategy getStrategy() {
*/
@RequirePOST
@Restricted(NoExternalUse.class)
public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public void doRolesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
// Let the strategy descriptor handle the form
RoleBasedAuthorizationStrategy.DESCRIPTOR.doRolesSubmit(req, rsp);
Expand All @@ -162,7 +162,7 @@ public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws IOExce
*/
@RequirePOST
@Restricted(NoExternalUse.class)
public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public void doTemplatesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
// Let the strategy descriptor handle the form
RoleBasedAuthorizationStrategy.DESCRIPTOR.doTemplatesSubmit(req, rsp);
Expand All @@ -186,7 +186,7 @@ public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws IO
*/
@RequirePOST
@Restricted(NoExternalUse.class)
public void doAssignSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public void doAssignSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
// Let the strategy descriptor handle the form
RoleBasedAuthorizationStrategy.DESCRIPTOR.doAssignSubmit(req, rsp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

Expand All @@ -52,14 +52,14 @@ public RoleBasedProjectNamingStrategy(boolean forceExistingJobs) {

@Override
public void checkName(String name) throws Failure {
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
// Workaround until JENKINS-68602 is implemented
// This works only for requests via the UI. In case this method is called due to
// job creation request via the CLI, we have no way to determine the
// the parent so just check the name
String parentName = "";
if (request != null) {
ItemGroup<?> i = Stapler.getCurrentRequest().findAncestorObject(ItemGroup.class);
ItemGroup<?> i = Stapler.getCurrentRequest2().findAncestorObject(ItemGroup.class);
parentName = i.getFullName();
}
checkName(parentName, name);
Expand Down

0 comments on commit 60d2b06

Please sign in to comment.