From 939e8714f0e5de4cc3f25efc85beabf67e2a14c7 Mon Sep 17 00:00:00 2001 From: Sven Selberg Date: Wed, 10 Jan 2018 10:32:12 +0100 Subject: [PATCH 1/2] [SSH] Extract task name creation to method in BaseCommand Command line is not the best task description for all commands. The "review" command command line are f.i. more often than not multiline. This allows sub command to override task description. Change-Id: I2bc42010fa91e94ea079f0e759c8ab049a61f462 --- .../com/google/gerrit/sshd/BaseCommand.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java index bc465ec89f..e38c0802f5 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java @@ -369,6 +369,22 @@ public abstract class BaseCommand implements Command { } } + protected String getTaskDescription() { + StringBuilder m = new StringBuilder(); + m.append(context.getCommandLine()); + return m.toString(); + } + + private String getTaskName() { + StringBuilder m = new StringBuilder(); + m.append(getTaskDescription()); + if (user.isIdentifiedUser()) { + IdentifiedUser u = user.asIdentifiedUser(); + m.append(" (").append(u.getAccount().getUserName()).append(")"); + } + return m.toString(); + } + private final class TaskThunk implements CancelableRunnable, ProjectRunnable { private final CommandRunnable thunk; private final String taskName; @@ -376,14 +392,7 @@ public abstract class BaseCommand implements Command { private TaskThunk(final CommandRunnable thunk) { this.thunk = thunk; - - StringBuilder m = new StringBuilder(); - m.append(context.getCommandLine()); - if (user.isIdentifiedUser()) { - IdentifiedUser u = user.asIdentifiedUser(); - m.append(" (").append(u.getAccount().getUserName()).append(")"); - } - this.taskName = m.toString(); + this.taskName = getTaskName(); } @Override From 9dd0e0855aa53ba46834c94102dd0de772da7f70 Mon Sep 17 00:00:00 2001 From: Sven Selberg Date: Thu, 11 Jan 2018 12:16:24 +0100 Subject: [PATCH 2/2] SSH commands: Set task name for ReviewCommand Task name is otherwise set to the command line which in ReviewCommands case can be a multi line string which leads to pretty unreadable and bordering on unparseable "loglines" like: [2018-01-10 09:59:17,619] [SSH gerrit review 12345,4 --message 'Build: http://jenkins.company.com/job/JOB_NAME/job/identifier/182/ : UNSTABLE http://jenkins.company.com/job/JOB_NAME/job/other/13677/ : SUCCESS'\ --verified -1 --code-review 0 (jenkins)] WARN : Change-Id: I74a0ff062b38a1980c4781e8e79a368bf028c549 --- .../java/com/google/gerrit/sshd/commands/ReviewCommand.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java index ca69b5477d..dfe1638b38 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java @@ -281,6 +281,11 @@ public class ReviewCommand extends SshCommand { } } + @Override + protected String getTaskDescription() { + return "gerrit review"; + } + private void applyReview(PatchSet patchSet, final ReviewInput review) throws RestApiException { gApi.changes() .id(patchSet.getId().getParentKey().get())