Skip to content

Commit

Permalink
Migrate from EE 8 to EE 9
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Nov 18, 2024
1 parent 917eb99 commit 72a9b3b
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 49 deletions.
117 changes: 112 additions & 5 deletions src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
import hudson.util.HttpResponses;
import hudson.views.DefaultViewsTabBar;
import hudson.views.ViewsTabBar;
import io.jenkins.servlet.ServletExceptionWrapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -94,12 +97,12 @@
import java.util.logging.Logger;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.ServletException;
import jenkins.model.DirectlyModifiableTopLevelItemGroup;
import jenkins.model.Jenkins;
import jenkins.model.ModelObjectWithChildren;
import jenkins.model.ProjectNamingStrategy;
import jenkins.model.TransientActionFactory;
import jenkins.security.stapler.StaplerNotDispatchable;
import net.sf.json.JSONObject;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
Expand All @@ -110,7 +113,9 @@
import org.kohsuke.stapler.StaplerFallback;
import org.kohsuke.stapler.StaplerOverridable;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse;
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 @@ -723,7 +728,25 @@ private ItemGroup<?> grp() {
* {@inheritDoc}
*/
@Override
public ContextMenu doChildrenContextMenu(StaplerRequest2 request, StaplerResponse2 response) {
if (Util.isOverridden(AbstractFolder.class, getClass(), "doChildrenContextMenu", StaplerRequest.class, StaplerResponse.class)) {
return doChildrenContextMenu(request != null ? StaplerRequest.fromStaplerRequest2(request) : null, response != null ? StaplerResponse.fromStaplerResponse2(response) : null);
} else {
return doChildrenContextMenuImpl(request, response);
}
}

/**
* @deprecated use {@link #doChildrenContextMenu(StaplerRequest2, StaplerResponse2)}
*/
@Deprecated
@Override
@StaplerNotDispatchable
public ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse response) {
return doChildrenContextMenuImpl(request != null ? StaplerRequest.toStaplerRequest2(request) : null, response != null ? StaplerResponse.toStaplerResponse2(response) : null);

Check warning on line 746 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 732-746 are not covered by tests
}

private ContextMenu doChildrenContextMenuImpl(StaplerRequest2 request, StaplerResponse2 response) {
ContextMenu menu = new ContextMenu();
for (View view : getViews()) {
menu.add(view.getAbsoluteUrl(),view.getDisplayName());
Expand All @@ -732,7 +755,34 @@ public ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse
}

@POST
public synchronized void doCreateView(StaplerRequest2 req, StaplerResponse2 rsp)
throws IOException, ServletException, ParseException, Descriptor.FormException {
if (Util.isOverridden(AbstractFolder.class, getClass(), "doCreateView", StaplerRequest.class, StaplerResponse.class)) {

Check warning on line 760 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 760 is only partially covered, one branch is missing
try {
doCreateView(req != null ? StaplerRequest.fromStaplerRequest2(req) : null, rsp != null ? StaplerResponse.fromStaplerResponse2(rsp) : null);
} catch (javax.servlet.ServletException e) {
throw ServletExceptionWrapper.toJakartaServletException(e);
}

Check warning on line 765 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 762-765 are not covered by tests
} else {
doCreateViewImpl(req, rsp);
}
}

/**
* @deprecated use {@link #doCreateView(StaplerRequest2, StaplerResponse2)}
*/
@Deprecated
@StaplerNotDispatchable
public synchronized void doCreateView(StaplerRequest req, StaplerResponse rsp)
throws IOException, javax.servlet.ServletException, ParseException, Descriptor.FormException {
try {
doCreateViewImpl(req != null ? StaplerRequest.toStaplerRequest2(req) : null, rsp != null ? StaplerResponse.toStaplerResponse2(rsp) : null);
} catch (ServletException e) {
throw ServletExceptionWrapper.fromJakartaServletException(e);
}
}

private void doCreateViewImpl(StaplerRequest2 req, StaplerResponse2 rsp)
throws IOException, ServletException, ParseException, Descriptor.FormException {
checkPermission(View.CREATE);
addView(View.create(req, rsp, this));
Expand Down Expand Up @@ -860,7 +910,24 @@ public DescribableList<FolderHealthMetric, FolderHealthMetricDescriptor> getHeal
return healthMetrics;
}

public HttpResponse doLastBuild(StaplerRequest2 req) {
if (Util.isOverridden(AbstractFolder.class, getClass(), "doLastBuild", StaplerRequest.class)) {
return doLastBuild(req != null ? StaplerRequest.fromStaplerRequest2(req) : null);
} else {
return doLastBuildImpl(req);
}
}

/**
* @deprecated use {@link #doLastBuild(StaplerRequest2)}
*/
@Deprecated
@StaplerNotDispatchable
public HttpResponse doLastBuild(StaplerRequest req) {
return doLastBuildImpl(req != null ? StaplerRequest.toStaplerRequest2(req) : null);
}

private HttpResponse doLastBuildImpl(StaplerRequest2 req) {
return HttpResponses.redirectToDot();
}

Expand Down Expand Up @@ -1092,13 +1159,39 @@ public void renameTo(String newName) throws IOException {
* {@inheritDoc}
*/
@Override
public synchronized void doSubmitDescription(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public synchronized void doSubmitDescription(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
if (Util.isOverridden(AbstractFolder.class, getClass(), "doSubmitDescription", StaplerRequest.class, StaplerResponse.class)) {
try {
doSubmitDescription(req != null ? StaplerRequest.fromStaplerRequest2(req) : null, rsp != null ? StaplerResponse.fromStaplerResponse2(rsp) : null);
} catch (javax.servlet.ServletException e) {
throw ServletExceptionWrapper.toJakartaServletException(e);
}
} else {
doSubmitDescriptionImpl(req, rsp);
}
}

/**
* @deprecated use {@link #doSubmitDescription(StaplerRequest2, StaplerResponse2)}
*/
@Deprecated
@Override
@StaplerNotDispatchable
public synchronized void doSubmitDescription(StaplerRequest req, StaplerResponse rsp) throws IOException, javax.servlet.ServletException {
try {
doSubmitDescriptionImpl(req != null ? StaplerRequest.toStaplerRequest2(req) : null, rsp != null ? StaplerResponse.toStaplerResponse2(rsp) : null);
} catch (ServletException e) {
throw ServletExceptionWrapper.fromJakartaServletException(e);
}
}

Check warning on line 1186 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 779-1186 are not covered by tests

private void doSubmitDescriptionImpl(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
getPrimaryView().doSubmitDescription(req, rsp);
}

@Restricted(NoExternalUse.class)
@RequirePOST
public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException {
public void doConfigSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException, Descriptor.FormException {
checkPermission(CONFIGURE);

req.setCharacterEncoding("UTF-8");
Expand Down Expand Up @@ -1147,15 +1240,29 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOExc
*
* @return A string that represents the redirect location URL.
*
* @see javax.servlet.http.HttpServletResponse#sendRedirect(String)
* @see HttpServletResponse#sendRedirect(String)
*/
@Restricted(NoExternalUse.class)
@NonNull
protected String getSuccessfulDestination() {
return ".";
}

protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException {}
protected void submit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException, Descriptor.FormException {
if (Util.isOverridden(AbstractFolder.class, getClass(), "submit", StaplerRequest.class, StaplerResponse.class)) {

Check warning on line 1252 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1252 is only partially covered, one branch is missing
try {
submit(req != null ? StaplerRequest.fromStaplerRequest2(req) : null, rsp != null ? StaplerResponse.fromStaplerResponse2(rsp) : null);

Check warning on line 1254 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1254 is only partially covered, 2 branches are missing
} catch (javax.servlet.ServletException e) {
throw ServletExceptionWrapper.toJakartaServletException(e);

Check warning on line 1256 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1255-1256 are not covered by tests
}
}
}

/**
* @deprecated use {@link #submit(StaplerRequest2, StaplerResponse2)}
*/
@Deprecated
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, javax.servlet.ServletException, Descriptor.FormException {}

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Category of {@link AbstractFolder}.
Expand Down Expand Up @@ -124,7 +124,7 @@ public List<FolderIconDescriptor> getIconDescriptors() {
r.add(p);
}
}
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
AbstractFolder<?> folder = request.findAncestorObject(AbstractFolder.class);
if (folder != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.cloudbees.hudson.plugins.folder.health.FolderHealthMetric;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionPoint;
import hudson.Util;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.HealthReport;
Expand All @@ -39,6 +40,7 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerOverridable;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Property potentially applicable to any {@link AbstractFolder}.
Expand Down Expand Up @@ -88,8 +90,25 @@ public Collection<?> getItemContainerOverrides() {
return Collections.emptyList();
}

@Override
public AbstractFolderProperty<?> reconfigure(StaplerRequest2 req, JSONObject form) throws Descriptor.FormException {
if (Util.isOverridden(AbstractFolderProperty.class, getClass(), "reconfigure", StaplerRequest.class, JSONObject.class)) {
return reconfigure(req != null ? StaplerRequest.fromStaplerRequest2(req) : null, form);
} else {
return reconfigureImpl(req, form);
}
}

/**
* @deprecated use {@link #reconfigure(StaplerRequest2, JSONObject)}
*/
@Deprecated
@Override
public AbstractFolderProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException {
return reconfigureImpl(req != null ? StaplerRequest.toStaplerRequest2(req) : null, form);

Check warning on line 108 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolderProperty.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 95-108 are not covered by tests
}

private AbstractFolderProperty<?> reconfigureImpl(StaplerRequest2 req, JSONObject form) throws Descriptor.FormException {
return form == null ? null : getDescriptor().newInstance(req, form);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.cloudbees.hudson.plugins.folder;

import hudson.ExtensionList;
import hudson.Util;
import hudson.model.Descriptor;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand All @@ -33,6 +34,7 @@
import net.sf.json.JSONObject;
import org.jvnet.tiger_types.Types;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Category of {@link AbstractFolderProperty}.
Expand All @@ -47,6 +49,23 @@ public abstract class AbstractFolderPropertyDescriptor extends Descriptor<Abstra
* null to avoid setting an instance of {@link AbstractFolderProperty} to the target folder.
*/
@Override
public AbstractFolderProperty<?> newInstance(StaplerRequest2 req, JSONObject formData) throws FormException {
if (Util.isOverridden(AbstractFolderPropertyDescriptor.class, getClass(), "newInstance", StaplerRequest.class, JSONObject.class)) {
return newInstance(req != null ? StaplerRequest.fromStaplerRequest2(req) : null, formData);
} else {
// Analogous to hack in JobPropertyDescriptor.
if (formData.isNullObject()) {
formData = new JSONObject();
}
return super.newInstance(req, formData);

Check warning on line 60 in src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolderPropertyDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 53-60 are not covered by tests
}
}

/**
* @deprecated use {@link #newInstance(StaplerRequest2, JSONObject)}
*/
@Deprecated
@Override
public AbstractFolderProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
// Analogous to hack in JobPropertyDescriptor.
if (formData.isNullObject()) {
Expand Down
60 changes: 57 additions & 3 deletions src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import hudson.util.DescribableList;
import hudson.views.ListViewColumn;
import hudson.views.ViewJobFilter;
import io.jenkins.servlet.ServletExceptionWrapper;
import jakarta.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -52,16 +54,18 @@
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import jenkins.model.DirectlyModifiableTopLevelItemGroup;
import jenkins.model.Jenkins;
import jenkins.model.TransientActionFactory;
import jenkins.security.stapler.StaplerNotDispatchable;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.verb.POST;

/**
Expand Down Expand Up @@ -234,7 +238,32 @@ public void onCopiedFrom(Item _src) {
}

@POST
public TopLevelItem doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public TopLevelItem doCreateItem(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
if (Util.isOverridden(Folder.class, getClass(), "doCreateItem", StaplerRequest.class, StaplerResponse.class)) {

Check warning on line 242 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 242 is only partially covered, one branch is missing
try {
return doCreateItem(req != null ? StaplerRequest.fromStaplerRequest2(req) : null, rsp != null ? StaplerResponse.fromStaplerResponse2(rsp) : null);

Check warning on line 244 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 244 is only partially covered, 2 branches are missing
} catch (javax.servlet.ServletException e) {
throw ServletExceptionWrapper.toJakartaServletException(e);
}
} else {
return doCreateItemImpl(req, rsp);

Check warning on line 249 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 245-249 are not covered by tests
}
}

/**
* @deprecated use {@link #doCreateItem(StaplerRequest2, StaplerResponse2)}
*/
@Deprecated
@StaplerNotDispatchable
public TopLevelItem doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, javax.servlet.ServletException {
try {
return doCreateItemImpl(req != null ? StaplerRequest.toStaplerRequest2(req) : null, rsp != null ? StaplerResponse.toStaplerResponse2(rsp) : null);

Check warning on line 260 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 260 is only partially covered, 2 branches are missing
} catch (ServletException e) {
throw ServletExceptionWrapper.fromJakartaServletException(e);

Check warning on line 262 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 261-262 are not covered by tests
}
}

private TopLevelItem doCreateItemImpl(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
TopLevelItem nue = mixin.createTopLevelItem(req, rsp);
if (!isAllowedChild(nue)) {
// TODO would be better to intercept it before creation, if mode is set

Check warning on line 269 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: would be better to intercept it before creation, if mode is set
Expand Down Expand Up @@ -288,7 +317,32 @@ public TopLevelItem createProject(@NonNull TopLevelItemDescriptor type, @NonNull
}

@Override
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
protected void submit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException, FormException {
if (Util.isOverridden(Folder.class, getClass(), "submit", StaplerRequest.class, StaplerResponse.class)) {

Check warning on line 321 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 321 is only partially covered, one branch is missing
try {
submit(req != null ? StaplerRequest.fromStaplerRequest2(req) : null, rsp != null ? StaplerResponse.fromStaplerResponse2(rsp) : null);

Check warning on line 323 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 323 is only partially covered, 2 branches are missing
} catch (javax.servlet.ServletException e) {
throw ServletExceptionWrapper.toJakartaServletException(e);

Check warning on line 325 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 324-325 are not covered by tests
}
} else {
submitImpl(req, rsp);

Check warning on line 328 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 328 is not covered by tests
}
}

/**
* @deprecated use {@link #submit(StaplerRequest2, StaplerResponse2)}
*/
@Deprecated
@Override
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, javax.servlet.ServletException, FormException {
try {
submitImpl(req != null ? StaplerRequest.toStaplerRequest2(req) : null, rsp != null ? StaplerResponse.toStaplerResponse2(rsp) : null);

Check warning on line 339 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 339 is only partially covered, 2 branches are missing
} catch (ServletException e) {
throw ServletExceptionWrapper.fromJakartaServletException(e);

Check warning on line 341 in src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 340-341 are not covered by tests
}
}

private void submitImpl(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException, FormException {
updateTransientActions();
}

Expand Down
Loading

0 comments on commit 72a9b3b

Please sign in to comment.