Skip to content
Permalink
Browse files
[JENKINS-39404 Follow-up] Add removeAction and removeActions methods
  • Loading branch information
stephenc committed Nov 1, 2016
1 parent f5bd177 commit 1fa3195bd00eaeb014a4ede66c776d226f386465
Showing with 46 additions and 0 deletions.
  1. +46 −0 src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java
@@ -30,6 +30,7 @@
import com.cloudbees.hudson.plugins.folder.icons.StockFolderIcon;
import com.cloudbees.hudson.plugins.folder.views.DefaultFolderViewHolder;
import com.cloudbees.hudson.plugins.folder.views.AbstractFolderViewHolder;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.AbortException;
import hudson.BulkChange;
import hudson.Util;
@@ -84,6 +85,7 @@
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import jenkins.model.ModelObjectWithChildren;
@@ -287,11 +289,13 @@ protected void initViews(List<View> views) throws IOException {
}

@Override
@SuppressWarnings("deprecation")
public void addAction(Action a) {
super.getActions().add(a);
}

@Override
@SuppressWarnings("deprecation")
public void replaceAction(Action a) {
// CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
List<Action> old = new ArrayList<Action>(1);
@@ -305,6 +309,48 @@ public void replaceAction(Action a) {
addAction(a);
}

/**
* Remove an action.
*
* @param a an action to remove (if {@code null} then this will be a no-op)
* @return {@code true} if this actions changed as a result of the call
* @since FIXME
*/
// @Override // TODO uncomment once baseline has JENKINS-39404
@SuppressWarnings("deprecation")
public boolean removeAction(@Nullable Action a) {
if (a == null) {
return false;
}
// CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
return super.getActions().removeAll(Collections.singleton(a));
}

/**
* Removes any actions of the specified type.
*
* @param clazz the type of actions to remove
* @return {@code true} if this actions changed as a result of the call
* @since FIXME
*/
// @Override // TODO uncomment once baseline has JENKINS-39404
@SuppressWarnings({"ConstantConditions","deprecation"})
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public boolean removeActions(@Nonnull Class<? extends Action> clazz) {
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 a : current) {
if (clazz.isInstance(a)) {
old.add(a);
}
}
return current.removeAll(old);
}

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

0 comments on commit 1fa3195

Please sign in to comment.