Package: SessionCommandExecutor

SessionCommandExecutor

nameinstructionbranchcomplexitylinemethod
SessionCommandExecutor(CommandSession)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
execute(String, LinePrinter)
M: 62 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
printList(LinePrinter, List)
M: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * This file is part of the Virgo Web Server.
3: *
4: * Copyright (c) 2010 VMware Inc.
5: * All rights reserved. This program and the accompanying materials
6: * are made available under the terms of the Eclipse Public License v1.0
7: * which accompanies this distribution, and is available at
8: * http://www.eclipse.org/legal/epl-v10.html
9: *
10: * Contributors:
11: * SpringSource, a division of VMware - initial API and implementation and/or initial documentation
12: *******************************************************************************/
13:
14: package org.eclipse.virgo.shell.internal;
15:
16: import java.io.IOException;
17: import java.util.List;
18:
19: import org.eclipse.virgo.shell.CommandExecutor;
20: import org.eclipse.virgo.shell.LinePrinter;
21:
22: /**
23: * Implementation of {@link CommandExecutor} that uses a {@link CommandSession} to execute commands.
24: * <p />
25: *
26: * <strong>Concurrent Semantics</strong><br />
27: * thread-safe
28: *
29: * @author Steve Powell
30: */
31: public class SessionCommandExecutor implements CommandExecutor {
32:
33: private final static String EXIT_COMMAND = "exit";
34:
35: private final CommandSession commandSession;
36:
37: SessionCommandExecutor(CommandSession commandSession) {
38: this.commandSession = commandSession;
39: }
40:
41: /**
42: * {@inheritDoc}
43: */
44: public boolean execute(String commandLine, LinePrinter linePrinter) throws IOException {
45:• if (commandLine!=null) {
46: commandLine = commandLine.trim();
47:• if (commandLine.length()>0) {
48:• if (EXIT_COMMAND.equalsIgnoreCase(commandLine)) {
49: return false;
50: } else {
51: try {
52: List<String> executionResult = this.commandSession.execute(commandLine);
53:• if (executionResult == null) {
54: linePrinter.println(String.format("Null result returned for '%s'", commandLine));
55: } else {
56: printList(linePrinter, executionResult);
57: }
58: } catch (Exception e) {
59: linePrinter.println(String.format("%s while executing command '%s': '%s'", e.getClass().getName(), commandLine,
60: e.getMessage()));
61: }
62: }
63: }
64: }
65: return true;
66: }
67:
68: private static void printList(LinePrinter linePrinter, List<String> executionResult) throws IOException {
69: linePrinter.println();
70:• for (String line : executionResult) {
71: linePrinter.println(line);
72: }
73: }
74: }