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 from EE 8 to EE 9 #444

Merged
merged 3 commits into from
Jan 8, 2025
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 @@ -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 @@
* {@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,373 +755,443 @@
}

@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));
}

/**
* Checks if a top-level view with the given name exists.
*
* @param value the name of the child.
* @return the validation results.
*/
public FormValidation doViewExistsCheck(@QueryParameter String value) {
checkPermission(View.CREATE);

String view = fixEmpty(value);
if (view == null) {
return FormValidation.ok();
}

if (getView(view) == null) {
return FormValidation.ok();
} else {
return FormValidation.error(Messages.Hudson_ViewAlreadyExists(view));
}
}


/**
* Get the current health report for a folder.
*
* @return the health report. Never returns null
*/
public HealthReport getBuildHealth() {
List<HealthReport> reports = getBuildHealthReports();
return reports.isEmpty() ? new HealthReport() : reports.get(0);
}

/**
* Invalidates the cache of build health reports.
*
* @since FIXME
*/
public void invalidateBuildHealthReports() {
healthReports = null;
}

@Exported(name = "healthReport")
public List<HealthReport> getBuildHealthReports() {
if (healthMetrics == null || healthMetrics.isEmpty()) {
return Collections.emptyList();
}
List<HealthReport> reports = healthReports;
if (reports != null && nextHealthReportsRefreshMillis > System.currentTimeMillis()) {
// cache is still valid
return reports;
}
// ensure we refresh on average once every HEALTH_REPORT_CACHE_REFRESH_MIN but not all at once
nextHealthReportsRefreshMillis = System.currentTimeMillis()
+ TimeUnit.MINUTES.toMillis(HEALTH_REPORT_CACHE_REFRESH_MIN * 3L / 4L)
+ ENTROPY.nextInt((int)TimeUnit.MINUTES.toMillis(HEALTH_REPORT_CACHE_REFRESH_MIN / 2));
reports = new ArrayList<>();
List<FolderHealthMetric.Reporter> reporters = new ArrayList<>(healthMetrics.size());
boolean recursive = false;
boolean topLevelOnly = true;
for (FolderHealthMetric metric : healthMetrics) {
recursive = recursive || metric.getType().isRecursive();
topLevelOnly = topLevelOnly && metric.getType().isTopLevelItems();
reporters.add(metric.reporter());
}
for (AbstractFolderProperty<?> p : getProperties()) {
for (FolderHealthMetric metric : p.getHealthMetrics()) {
recursive = recursive || metric.getType().isRecursive();
topLevelOnly = topLevelOnly && metric.getType().isTopLevelItems();
reporters.add(metric.reporter());
}
}
if (recursive) {
Stack<Iterable<? extends Item>> stack = new Stack<>();
stack.push(getItems());
if (topLevelOnly) {
while (!stack.isEmpty()) {
for (Item item : stack.pop()) {
if (item instanceof TopLevelItem) {
for (FolderHealthMetric.Reporter reporter : reporters) {
reporter.observe(item);
}
if (item instanceof Folder) {
stack.push(((Folder) item).getItems());
}
}
}
}
} else {
while (!stack.isEmpty()) {
for (Item item : stack.pop()) {
for (FolderHealthMetric.Reporter reporter : reporters) {
reporter.observe(item);
}
if (item instanceof Folder) {
stack.push(((Folder) item).getItems());
}
}
}
}
} else {
for (Item item: getItems()) {
for (FolderHealthMetric.Reporter reporter : reporters) {
reporter.observe(item);
}
}
}
for (FolderHealthMetric.Reporter reporter : reporters) {
reports.addAll(reporter.report());
}
for (AbstractFolderProperty<?> p : getProperties()) {
reports.addAll(p.getHealthReports());
}

Collections.sort(reports);
healthReports = reports; // idempotent write
return reports;
}

public DescribableList<FolderHealthMetric, FolderHealthMetricDescriptor> getHealthMetrics() {
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();
}

/**
* Gets the icon used for this folder.
*
* @return the icon.
*/
public FolderIcon getIcon() {
return icon;
}

public void setIcon(FolderIcon icon) {
this.icon = icon;
icon.setOwner(this);
}

public FolderIcon getIconColor() {
return icon;
}

/**
* {@inheritDoc}
*/
@Override
public Collection<? extends Job> getAllJobs() {
Set<Job> jobs = new HashSet<>();
for (Item i : getItems()) {
jobs.addAll(i.getAllJobs());
}
return jobs;
}

/**
* {@inheritDoc}
*/
@Exported(name="jobs")
@Override
public Collection<I> getItems() {
return getItems(item -> true);
}

/**
* {@inheritDoc}
*/
@Override
public Collection<I> getItems(Predicate<I> pred) {
List<I> viewableItems = new ArrayList<>();
for (I item : items.values()) {
if (pred.test(item) && item.hasPermission(Item.READ)) {
viewableItems.add(item);
}
}
return viewableItems;
}

/**
* Checks if folder has visible items
* @return true if folder has visible items false otherwise
*/
public boolean hasVisibleItems() {
for (I item : items.values()) {
if (item.hasPermission(Item.READ)) {
return true;
}
}
return false;
}

/**
* {@inheritDoc}
*/
@Override
public I getItem(String name) throws AccessDeniedException {
if (items == null) {
return null;
}
I item = items.get(name);
if (item == null) {
return null;
}
if (!item.hasPermission(Item.READ)) {
if (item.hasPermission(Item.DISCOVER)) {
throw new AccessDeniedException("Please log in to access " + name);
}
return null;
}
return item;
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@Override
public void onRenamed(I item, String oldName, String newName) throws IOException {
items.remove(oldName);
itemsPut(newName, item);
// For compatibility with old views:
for (View v : folderViews.getViews()) {
v.onJobRenamed(item, oldName, newName);
}
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@Override
public void onDeleted(I item) throws IOException {
ItemListener.fireOnDeleted(item);
items.remove(item.getName());
// For compatibility with old views:
for (View v : folderViews.getViews()) {
v.onJobRenamed(item, item.getName(), null);
}
}

/**
* Is this folder disabled. A disabled folder should have all child items disabled.
*
* @return {@code true} if and only if the folder is disabled.
* @since 6.1.0
* @see FolderJobQueueDecisionHandler
*/
public boolean isDisabled() {
return false;
}

/**
* Sets the folder as disabled.
*
* @param disabled {@code true} if and only if the folder is to be disabled.
* @since 6.1.0
*/
protected void setDisabled(boolean disabled) {
throw new UnsupportedOperationException("must be implemented if supportsMakeDisabled is overridden");
}

/**
* Determines whether the folder supports being made disabled.
* @return {@code true} if and only if {@link #setDisabled(boolean)} is implemented
* @since 6.1.0
*/
public boolean supportsMakeDisabled() {
return false;
}

/**
* Makes the folder disabled. Will have no effect if the folder type does not {@linkplain #supportsMakeDisabled()}.
* @param disabled {@code true} if the folder should be disabled.
* @throws IOException if the operation could not complete.
* @since 6.1.0
*/
public void makeDisabled(boolean disabled) throws IOException {
if (isDisabled() == disabled) {
return; // noop
}
if (disabled && !supportsMakeDisabled()) {
return; // do nothing if the disabling is unsupported
}
setDisabled(disabled);
if (disabled && this instanceof Queue.Task) {
Jenkins.get().getQueue().cancel((Queue.Task)this);
}
save();
ItemListener.fireOnUpdated(this);
}

/**
* Stapler action method to disable the folder.
*
* @return the response.
* @throws IOException if the folder could not be disabled.
* @throws ServletException if something goes wrong.
* @since 6.1.0
*/
@RequirePOST
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler action method
public HttpResponse doDisable() throws IOException, ServletException {
checkPermission(CONFIGURE);
makeDisabled(true);
return new HttpRedirect(".");
}

/**
* Stapler action method to enable the folder.
*
* @return the response.
* @throws IOException if the folder could not be disabled.
* @throws ServletException if something goes wrong.
* @since 6.1.0
*/
@RequirePOST
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler action method
public HttpResponse doEnable() throws IOException, ServletException {
checkPermission(CONFIGURE);
makeDisabled(false);
return new HttpRedirect(".");
}

/**
* {@inheritDoc}
*/
@Override
public synchronized void save() throws IOException {
if (folderViews != null) {
folderViews.invalidateCaches();
}
if (BulkChange.contains(this)) {
return;
}
super.save();
// TODO should this not just be done in AbstractItem?
ItemListener.fireOnUpdated(this);
}

/**
* Renames this item container.
*/
@Override
public void renameTo(String newName) throws IOException {
super.renameTo(newName);
}

/**
* {@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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most if not all of these web methods could probably be simplified considerably by just deleting the deprecated overload, which I doubt is either called programmatically or overridden by any known subclass. Pending that, it would make sense to mark the new overloads final and/or @Restricted(NoExternalUse.class) unless and until some legitimate use case for overriding one is identified.

(not referring to submit, which is clearly overridden at least within this plugin, and also in branch-api)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not seem necessary for this PR.

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 @@
*
* @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 @@
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 @@
* 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,10 +238,35 @@
}

@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
try {
nue.delete();
} catch (InterruptedException x) {
Expand Down Expand Up @@ -288,7 +317,32 @@
}

@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
Loading