private static boolean disabled(TopLevelItem item) { // TODO revisit once https://github.com/jenkinsci/jenkins/pull/2866 available in baseline Jenkins if (item instanceof AbstractFolder) { return ((AbstractFolder) item).isDisabled(); } else if (item instanceof AbstractProject) { return ((AbstractProject) item).isDisabled(); } else { try { Method isDisabled = item.getClass().getMethod("isDisabled"); return boolean.class.equals(isDisabled.getReturnType()) && (Boolean)isDisabled.invoke(item); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { // assume not disabled return false; } } }
private static boolean disabled(TopLevelItem item) { // TODO revisit once on 2.61+ for https://github.com/jenkinsci/jenkins/pull/2866 if (item instanceof AbstractFolder) { return ((AbstractFolder) item).isDisabled(); } else if (item instanceof AbstractProject) { return ((AbstractProject) item).isDisabled(); } else { try { Method isDisabled = item.getClass().getMethod("isDisabled"); return boolean.class.equals(isDisabled.getReturnType()) && (Boolean)isDisabled.invoke(item); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { // assume not disabled return false; } } }
/** * {@inheritDoc} */ @Override public boolean shouldSchedule(Queue.Task p, List<Action> actions) { if (p instanceof Item) { Item i = (Item) p; while (i != null) { if (i instanceof AbstractFolder && ((AbstractFolder) i).isDisabled()) { return false; } if (i.getParent() instanceof Item) { i = (Item) i.getParent(); } else { break; } } } return true; } }
/** * {@inheritDoc} */ @Override public boolean shouldSchedule(Queue.Task p, List<Action> actions) { if (p instanceof Item) { Item i = (Item) p; while (i != null) { if (i instanceof AbstractFolder && ((AbstractFolder) i).isDisabled()) { return false; } if (i.getParent() instanceof Item) { i = (Item) i.getParent(); } else { break; } } } return true; } }
/** * Whether it is permissible to recompute this folder at this time. * * @return {@code true} if this folder can currenty be recomputed. */ public boolean isBuildable() { if (isDisabled()) { return false; } // TODO revisit logic when Jenkins core allows ItemGroups to expose their disabled state // until then we just need to check if a parent is disabled for (ItemGroup p = getParent(); p instanceof Item; p = (((Item) p).getParent())) { if (p instanceof AbstractFolder && ((AbstractFolder) p).isDisabled()) { return false; } } return true; }
/** * Whether it is permissible to recompute this folder at this time. * * @return {@code true} if this folder can currently be recomputed. */ public boolean isBuildable() { if (isDisabled()) { return false; } // TODO revisit logic when Jenkins core allows ItemGroups to expose their disabled state // until then we just need to check if a parent is disabled for (ItemGroup p = getParent(); p instanceof Item; p = (((Item) p).getParent())) { if (p instanceof AbstractFolder && ((AbstractFolder) p).isDisabled()) { return false; } } return true; }
/** * 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.getActiveInstance().getQueue().cancel((Queue.Task)this); } save(); ItemListener.fireOnUpdated(this); }
/** * 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); }