JAMES-1982 Cli should not double output
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b547e70f Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b547e70f Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b547e70f Branch: refs/heads/master Commit: b547e70f38390b8e865470348089771a87716984 Parents: 4321bcc Author: benwa <btell...@linagora.com> Authored: Sat Apr 1 10:25:45 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Mon Apr 3 18:09:32 2017 +0700 ---------------------------------------------------------------------- .../java/org/apache/james/cli/ServerCmd.java | 39 ++++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/b547e70f/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java index 402b0d2..af882ed 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java @@ -86,24 +86,8 @@ public class ServerCmd { * @param args Command-line arguments. */ public static void main(String[] args) { - try { - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); - CommandLine cmd = parseCommandLine(args); - JmxConnection jmxConnection = new JmxConnection(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd)); - CmdType cmdType = new ServerCmd( - new JmxDataProbe().connect(jmxConnection), - new JmxMailboxProbe().connect(jmxConnection), - new JmxQuotaProbe().connect(jmxConnection), - new JmxSieveProbe().connect(jmxConnection) - ) - .executeCommandLine(cmd); - stopWatch.split(); - print(new String[] { Joiner.on(' ') - .join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.getSplitTime(), "ms.")}, - System.out); - stopWatch.stop(); + doMain(args); System.exit(0); } catch (JamesCliException e) { failWithMessage(e.getMessage()); @@ -115,7 +99,25 @@ public class ServerCmd { LOG.error("Error on command: {}", e); failWithMessage("Error " + e.getClass() + " while executing command:" + e.getMessage()); } + } + public static void doMain(String[] args) throws Exception { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + CommandLine cmd = parseCommandLine(args); + JmxConnection jmxConnection = new JmxConnection(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd)); + CmdType cmdType = new ServerCmd( + new JmxDataProbe().connect(jmxConnection), + new JmxMailboxProbe().connect(jmxConnection), + new JmxQuotaProbe().connect(jmxConnection), + new JmxSieveProbe().connect(jmxConnection) + ) + .executeCommandLine(cmd); + stopWatch.split(); + print(new String[] { Joiner.on(' ') + .join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.getSplitTime(), "ms.")}, + System.out); + stopWatch.stop(); } private final DataProbe probe; @@ -321,9 +323,6 @@ public class ServerCmd { private static void print(Iterable<String> data, PrintStream out) { if (data != null) { - for (String u : data) { - out.println(u); - } out.println(Joiner.on('\n').join(data)); } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org