diff --git a/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java b/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java index db6f32ba99c82b153269157f03557a6ed6a4e238..495d31c80133586b0604e58c3c0e28e61fea9982 100644 --- a/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java +++ b/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java @@ -30,6 +30,7 @@ import hudson.Util; import hudson.cli.CLICommand; import hudson.cli.CloneableCLICommand; import hudson.model.Hudson; +import hudson.remoting.Channel; import hudson.security.CliAuthenticator; import org.acegisecurity.Authentication; import org.acegisecurity.context.SecurityContext; @@ -107,6 +108,11 @@ public class CLIRegisterer extends ExtensionFinder { @Override public int main(List args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { + this.stdout = stdout; + this.stderr = stderr; + this.locale = locale; + this.channel = Channel.current(); + CmdLineParser parser = new CmdLineParser(null); try { SecurityContext sc = SecurityContextHolder.getContext(); diff --git a/test/src/test/java/hudson/model/listeners/ItemListenerTest.java b/test/src/test/java/hudson/model/listeners/ItemListenerTest.java index 768f148e9e7170379ba5163759b106cc99a68502..20bfcddd818c6a0d058c81ea0e5a7cae40d5c477 100644 --- a/test/src/test/java/hudson/model/listeners/ItemListenerTest.java +++ b/test/src/test/java/hudson/model/listeners/ItemListenerTest.java @@ -23,14 +23,14 @@ */ package hudson.model.listeners; -import hudson.cli.CreateJobCommand; +import hudson.cli.CLI; import hudson.model.Item; +import org.jvnet.hudson.test.HudsonTestCase; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import java.util.Collections; -import java.util.Locale; -import org.jvnet.hudson.test.HudsonTestCase; +import java.util.Arrays; /** * Tests for ItemListener events. @@ -53,14 +53,13 @@ public class ItemListenerTest extends HudsonTestCase { ItemListener.all().add(0, listener); } - public void testOnCreatedviaCLI() { - CreateJobCommand cmd = new CreateJobCommand(); + public void testOnCreatedViaCLI() throws Exception { ByteArrayOutputStream buf = new ByteArrayOutputStream(); PrintStream out = new PrintStream(buf); - cmd.main(Collections.singletonList("testJob"), Locale.ENGLISH, + new CLI(getURL()).execute(Arrays.asList("create-job","testJob"), new ByteArrayInputStream(("" + "").getBytes()), - out, out); + out, out); out.flush(); assertNotNull("job should be created: " + buf, hudson.getItem("testJob")); assertEquals("onCreated event should be triggered: " + buf, "C", events.toString());