diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index cdf98e5083f828e0263da8428c514090615f7e3c..2b7b5b12b43556590b5855fd3c4f533ec399f6d5 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1046,6 +1046,8 @@ public abstract class AbstractProject

,R extends A return Collections.unmodifiableList(actions); } + // TODO implement addAction, addOrReplaceAction, removeAction, removeActions, replaceActions + /** * Gets the {@link Node} where this project was last built on. * diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 3b87e42f239a1c0fff0f5c1799d6237645b5f751..bed7b0f7d57ef3fccfe7bd96ead9e02dcfc9d854 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -25,6 +25,7 @@ */ package hudson.model; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.EnvVars; import hudson.Extension; import hudson.Launcher.ProcStarter; @@ -268,6 +269,18 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces return Collections.unmodifiableList(result); } + @SuppressWarnings({"ConstantConditions","deprecation"}) + @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") + @Override + public void addAction(@Nonnull Action a) { + if (a == null) { + throw new IllegalArgumentException("Action must be non-null"); + } + super.getActions().add(a); + } + + // TODO implement addOrReplaceAction, removeAction, removeActions, replaceActions + /** * This is where the log from the remote agent goes. * The method also creates a log directory if required. diff --git a/core/src/main/java/hudson/model/labels/LabelAtom.java b/core/src/main/java/hudson/model/labels/LabelAtom.java index 91c1f3bd7707fba23c0fa8cd6edb438c77cf236e..3a6e6b44b2bff60b3e21e6a8a72bb6fbd63223d6 100644 --- a/core/src/main/java/hudson/model/labels/LabelAtom.java +++ b/core/src/main/java/hudson/model/labels/LabelAtom.java @@ -106,6 +106,8 @@ public class LabelAtom extends Label implements Saveable { return Collections.unmodifiableList(actions); } + // TODO implement addAction, addOrReplaceAction, removeAction, removeActions, replaceActions + protected void updateTransientActions() { Vector ta = new Vector(); diff --git a/test/src/test/java/hudson/model/ComputerTest.java b/test/src/test/java/hudson/model/ComputerTest.java index 8b8937a01c7eee61bb3311cf1864d7b32874eedf..4661566d3ddbc44b04fd4528917af7c2642ea9b3 100644 --- a/test/src/test/java/hudson/model/ComputerTest.java +++ b/test/src/test/java/hudson/model/ComputerTest.java @@ -31,7 +31,6 @@ import static org.junit.Assert.*; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.html.HtmlForm; -import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.xml.XmlPage; import java.io.File; @@ -40,7 +39,6 @@ import jenkins.model.Jenkins; import hudson.slaves.DumbSlave; import hudson.slaves.OfflineCause; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Issue; @@ -114,4 +112,17 @@ public class ComputerTest { assertThat(content, not(containsString("ApiTokenProperty"))); assertThat(content, not(containsString("apiToken"))); } + + @Issue("JENKINS-42969") + @Test + public void addAction() throws Exception { + Computer c = j.createSlave().toComputer(); + class A extends InvisibleAction {} + assertEquals(0, c.getActions(A.class).size()); + c.addAction(new A()); + assertEquals(1, c.getActions(A.class).size()); + c.addAction(new A()); + assertEquals(2, c.getActions(A.class).size()); + } + }