From 8d683cf22f689f95f4078afbb7b01ccf39e4076a Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 26 Jan 2023 15:07:14 -0500 Subject: [PATCH] Cleanup of `ComputedFolder` --- .../folder/computed/ComputedFolder.java | 123 +----------------- 1 file changed, 4 insertions(+), 119 deletions(-) diff --git a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java index c64e7907..cf6e9d58 100644 --- a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java +++ b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java @@ -30,7 +30,6 @@ import hudson.ExtensionList; import hudson.Util; import hudson.XmlFile; -import hudson.model.AbstractProject; import hudson.model.Action; import hudson.model.BuildableItem; import hudson.model.Cause; @@ -44,26 +43,20 @@ import hudson.model.Node; import hudson.model.ParametersAction; import hudson.model.Queue; -import hudson.model.ResourceList; import hudson.model.Result; import hudson.model.TaskListener; import hudson.model.TopLevelItem; import hudson.model.listeners.ItemListener; import hudson.model.queue.CauseOfBlockage; -import hudson.model.queue.SubTask; -import hudson.security.ACL; import hudson.triggers.TimerTrigger; import hudson.triggers.Trigger; import hudson.triggers.TriggerDescriptor; import hudson.util.DescribableList; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -83,7 +76,6 @@ import jenkins.util.TimeDuration; import net.jcip.annotations.GuardedBy; import net.sf.json.JSONObject; -import org.acegisecurity.Authentication; import org.apache.commons.io.FileUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.DoNotUse; @@ -104,7 +96,7 @@ * @param the child item type * @since 4.11-beta-1 */ -@SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) // generics mistakes in various places; BuildableItem defines deprecated methods (and @SW on those overrides does not seem to work) +@SuppressWarnings({"unchecked", "rawtypes"}) // generics mistakes in various places public abstract class ComputedFolder extends AbstractFolder implements BuildableItem, TriggeredItem, Queue.FlyweightTask { /** @@ -171,7 +163,6 @@ public abstract class ComputedFolder extends AbstractFol * @see #recalculateAfterSubmitted(boolean) * @see #submit(StaplerRequest, StaplerResponse) * @see #doConfigSubmit(StaplerRequest, StaplerResponse) - * @since FIXME */ private transient Recalculation recalculate; @@ -313,24 +304,10 @@ final void updateChildren(final TaskListener listener) throws IOException, Inter private void applyDisabled(I item, boolean disabled) { try { - // TODO revisit once on 2.61+ for https://github.com/jenkinsci/jenkins/pull/2866 if (item instanceof AbstractFolder) { ((AbstractFolder) item).makeDisabled(disabled); - } else if (item instanceof AbstractProject) { - ((AbstractProject) item).makeDisabled(disabled); - } else { - try { - Method makeDisabled = item.getClass().getMethod("makeDisabled", boolean.class); - makeDisabled.invoke(item, disabled); - } catch (NoSuchMethodException | IllegalAccessException e) { - // it's just not supported, so we cannot expect it to succeed - LOGGER.log(Level.FINE, - "Cannot not " + (disabled ? "disable " : "enable ") + item.getFullName(), e); - } catch (InvocationTargetException e) { - // it's supported but something went wrong - LOGGER.log(Level.WARNING, - "Could not " + (disabled ? "disable " : "enable ") + item.getFullName(), e); - } + } else if (item instanceof ParameterizedJobMixIn.ParameterizedJob) { + ((ParameterizedJobMixIn.ParameterizedJob) item).makeDisabled(disabled); } } catch (IOException e) { LOGGER.log(Level.WARNING, @@ -413,7 +390,7 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOExc recalculate = Recalculation.UNKNOWN; super.doConfigSubmit(req, rsp); if (recalculate != Recalculation.NO_RECALCULATION && isBuildable()) { - scheduleBuild(); + scheduleBuild(new Cause.UserIdCause()); } } finally { recalculate = null; @@ -428,7 +405,6 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOExc * to suppress recalculation. * * @param recalculate {@code true} to require recalculation, {@code false} to suppress recalculation. - * @since FIXME * @see #submit(StaplerRequest, StaplerResponse) */ /* @@ -592,14 +568,6 @@ public Queue.Item scheduleBuild2(int quietPeriod, Action... actions) { return Queue.getInstance().schedule2(this, quietPeriod, Arrays.asList(actions)).getItem(); } - /** - * {@inheritDoc} - */ - @Override - public boolean scheduleBuild() { - return scheduleBuild2(0) != null; - } - /** * {@inheritDoc} */ @@ -608,14 +576,6 @@ public boolean scheduleBuild(Cause c) { return scheduleBuild2(0, new CauseAction(c)) != null; } - /** - * {@inheritDoc} - */ - @Override - public boolean scheduleBuild(int quietPeriod) { - return scheduleBuild2(quietPeriod) != null; - } - /** * {@inheritDoc} */ @@ -624,24 +584,6 @@ public boolean scheduleBuild(int quietPeriod, Cause c) { return scheduleBuild2(quietPeriod, new CauseAction(c)) != null; } - /** - * {@inheritDoc} - */ - @Override - public boolean isBuildBlocked() { - return getCauseOfBlockage() != null; - } - - /** - * {@inheritDoc} - */ - @Deprecated - @Override - public String getWhyBlocked() { - CauseOfBlockage causeOfBlockage = getCauseOfBlockage(); - return causeOfBlockage == null ? null : causeOfBlockage.getShortDescription(); - } - /** * {@inheritDoc} */ @@ -669,38 +611,6 @@ public boolean hasAbortPermission() { return hasPermission(CANCEL); } - /** - * {@inheritDoc} - */ - @Override - public boolean isConcurrentBuild() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public Collection getSubTasks() { - return Collections.singleton(this); - } - - /** - * {@inheritDoc} - */ - @Override - public Authentication getDefaultAuthentication() { - return ACL.SYSTEM; - } - - /** - * {@inheritDoc} - */ - @Override - public Authentication getDefaultAuthentication(Queue.Item item) { - return getDefaultAuthentication(); - } - /** * {@inheritDoc} */ @@ -748,30 +658,6 @@ protected FolderComputation createComputation(@CheckForNull FolderComputation return new FolderComputation(this, previous); } - /** - * {@inheritDoc} - */ - @Override - public Queue.Task getOwnerTask() { - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public Object getSameNodeConstraint() { - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public ResourceList getResourceList() { - return ResourceList.EMPTY; - } - protected File getComputationDir() { return new File(getRootDir(), "computation"); } @@ -782,7 +668,6 @@ protected File getComputationDir() { * always present in the UI. * * @return {@code true} if this {@link ComputedFolder} has a separate out of band events log. - * @since FIXME */ public boolean isHasEvents() { return getComputation().getEventsFile().length() > 0;