Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Jakarta EE 9 #560

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* {@link Publisher} that sends notification e-mail.
Expand Down Expand Up @@ -281,7 +281,7 @@ public void setClasspath(List<GroovyScriptPath> classpath) {
// Prepare the classpath for approval
ScriptApproval scriptApproval = ScriptApproval.get();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
context = context.withItem(request.findAncestorObject(Item.class));
}
Expand All @@ -307,7 +307,7 @@ public void setPresendScript(String presendScript) {
if (!StringUtils.isBlank(presendScript) && !"$DEFAULT_PRESEND_SCRIPT".equals(presendScript)) {
ScriptApproval scriptApproval = ScriptApproval.get();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
Ancestor ancestor = request.findAncestor(Item.class);
if (ancestor != null) {
Expand All @@ -325,7 +325,7 @@ public void setPostsendScript(String postsendScript) {
if (!StringUtils.isBlank(postsendScript) && !"$DEFAULT_POSTSEND_SCRIPT".equals(postsendScript)) {
ScriptApproval scriptApproval = ScriptApproval.get();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
Ancestor ancestor = request.findAncestor(Item.class);
if (ancestor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* These settings are global configurations
Expand Down Expand Up @@ -797,7 +797,7 @@ public ListBoxModel doFillDefaultContentTypeItems() {
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
public boolean configure(StaplerRequest2 req, JSONObject formData) throws FormException {
req.bindJSON(this, formData);
save();
return super.configure(req, formData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

public abstract class EmailTrigger implements Describable<EmailTrigger>, ExtensionPoint {

Expand Down Expand Up @@ -144,17 +144,17 @@
return (EmailTriggerDescriptor) Jenkins.get().getDescriptor(getClass());
}

public boolean configure(StaplerRequest req, JSONObject formData) {
public boolean configure(StaplerRequest2 req, JSONObject formData) {
setEmail(createMailType(req, formData));
return true;
}

@Deprecated
protected EmailType createMailType(JSONObject formData) {
return createMailType(Stapler.getCurrentRequest(), formData);
return createMailType(Stapler.getCurrentRequest2(), formData);

Check warning on line 154 in src/main/java/hudson/plugins/emailext/plugins/EmailTrigger.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 154 is not covered by tests
}

protected EmailType createMailType(StaplerRequest req, JSONObject formData) {
protected EmailType createMailType(StaplerRequest2 req, JSONObject formData) {
return req.bindJSON(EmailType.class, formData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.scriptsecurity.scripts.languages.GroovyLanguage;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

public abstract class AbstractScriptTrigger extends EmailTrigger {

Expand All @@ -60,7 +60,7 @@ public AbstractScriptTrigger(
attachBuildLog,
contentType);
this.secureTriggerScript = secureTriggerScript;
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
if (request != null) {
context = context.withItem(request.findAncestorObject(Item.class));
Expand Down Expand Up @@ -135,7 +135,7 @@ private boolean hasScript() {
}

@Override
public boolean configure(@NonNull StaplerRequest req, @NonNull JSONObject formData) {
public boolean configure(@NonNull StaplerRequest2 req, @NonNull JSONObject formData) {
super.configure(req, formData);
if (formData.containsKey("secureTriggerScript")) {
this.secureTriggerScript =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import hudson.plugins.emailext.plugins.EmailTrigger;
import hudson.tasks.Mailer;
import hudson.tasks.Publisher;
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.kohsuke.stapler.verb.POST;
Expand Down Expand Up @@ -71,7 +71,7 @@ public UserProperty newInstance(User user) {

@NonNull
@Override
public UserProperty newInstance(StaplerRequest req, @NonNull JSONObject json) throws FormException {
public UserProperty newInstance(StaplerRequest2 req, @NonNull JSONObject json) throws FormException {
List<EmailTrigger> triggers =
req != null ? req.bindJSONToList(EmailTrigger.class, json) : Collections.emptyList();
return new UserProperty(triggers);
Expand Down Expand Up @@ -153,7 +153,7 @@ public ExtendedEmailPublisher getPublisher() {
}

@POST
public void doStopWatching(StaplerRequest req, StaplerResponse rsp) throws IOException {
public void doStopWatching(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException {
// See src/main/resources/hudson/plugins/emailext/watching/EmailExtWatchAction/{index,jobMain}.groovy
User user = User.current();
if (user != null
Expand All @@ -174,7 +174,7 @@ public void doStopWatching(StaplerRequest req, StaplerResponse rsp) throws IOExc
}

@RequirePOST
public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public void doConfigSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
// See src/main/resources/hudson/plugins/emailext/watching/EmailExtWatchAction/{index,jobMain}.groovy
User user = User.current();
if (user != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Collections;
import java.util.List;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Created by acearl on 12/4/2014.
Expand Down Expand Up @@ -76,7 +76,7 @@ public boolean isApplicable(Class<? extends Job> jobType) {
}

@Override
public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
public JobProperty<?> newInstance(StaplerRequest2 req, JSONObject formData) throws FormException {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ public void testNewInstance_shouldGetBasicInformation() throws Exception {
form.put("project_replyto", "");

ExtendedEmailPublisherDescriptor descriptor = new ExtendedEmailPublisherDescriptor();
publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form);
publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest2(), form);

assertEquals("default", publisher.contentType);
assertEquals("ashlux@gmail.com", publisher.recipientList);
Expand Down Expand Up @@ -1462,7 +1462,7 @@ public void testAdditionalAccounts() throws Exception {

JSONObject form = new JSONObject();
form.put("project_from", "mail@test1.com");
publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form);
publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest2(), form);
assertEquals("mail@test1.com", publisher.from);
ExtendedEmailPublisherContext context =
new ExtendedEmailPublisherContext(publisher, null, null, null, TaskListener.NULL);
Expand All @@ -1485,15 +1485,15 @@ public void testAdditionalAccounts() throws Exception {
addaccs.add(new MailAccount(dform));
descriptor.setAddAccounts(addaccs);

publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form);
publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest2(), form);
assertEquals("mail@test1.com", publisher.from);
session = descriptor.createSession(publisher.getMailAccount(context), context);
assertEquals("smtp.test1.com", session.getProperty("mail.smtp.host"));
assertEquals("25", session.getProperty("mail.smtp.port"));
assertEquals("test1.com", session.getProperty("mail.smtp.ssl.trust"));

form.put("project_from", "mail@test2.com");
publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form);
publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest2(), form);
assertEquals("mail@test2.com", publisher.from);
session = descriptor.createSession(publisher.getMailAccount(context), context);
assertEquals("smtp.test2.com", session.getProperty("mail.smtp.host"));
Expand Down