Skip to content
Permalink
Browse files
[JENKINS-39404 Follow-up] Add replaceActions methods
  • Loading branch information
stephenc committed Nov 1, 2016
1 parent 1fa3195 commit 53cc6b2b5fd940240bf1f1be51fc73822c8a9ecf
Showing with 26 additions and 0 deletions.
  1. +26 −0 src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java
@@ -351,6 +351,32 @@ public boolean removeActions(@Nonnull Class<? extends Action> clazz) {
return current.removeAll(old);
}

/**
* Replaces any actions of the specified type by the supplied action.
*
* @param clazz the type of actions to replace
* @param a the action to replace with
* @since FIXME
*/
// @Override // TODO uncomment once baseline has JENKINS-39404
@SuppressWarnings({"ConstantConditions", "deprecation"})
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public void replaceActions(@Nonnull Class<? extends Action> clazz, Action a) {
if (clazz == null) {
throw new IllegalArgumentException("Action type must be non-null");
}
// CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
List<Action> old = new ArrayList<Action>();
List<Action> current = super.getActions();
for (Action a1 : current) {
if (clazz.isInstance(a1)) {
old.add(a1);
}
}
current.removeAll(old);
addAction(a);
}

@Override
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
super.onLoad(parent, name);

0 comments on commit 53cc6b2

Please sign in to comment.