1
1
/**********************************************************************
2
2
* Copyright (c) 2012 Ericsson
4
4
* All rights reserved. This program and the accompanying materials are
5
5
* made available under the terms of the Eclipse Public License v1.0 which
6
6
* accompanies this distribution, and is available at
7
7
* http://www.eclipse.org/legal/epl-v10.html
10
10
* Bernd Hufmann - Initial API and implementation
11
11
**********************************************************************/
12
12
package org.eclipse.linuxtools.internal.lttng2.stubs.shells;
29
29
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.CommandResult;
30
30
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandResult;
32
@SuppressWarnings("javadoc")
32
33
public class LTTngToolsFileShell extends TestCommandShell {
34
35
// ------------------------------------------------------------------------
44
45
private final static String OUTPUT_KEY = "<COMMAND_OUTPUT>"; //$NON-NLS-1$
45
46
private final static String OUTPUT_END_KEY = "</COMMAND_OUTPUT>"; //$NON-NLS-1$
46
47
private final static String COMMENT_KEY = "#.*"; //$NON-NLS-1$
48
49
private final static Pattern LTTNG_LIST_SESSION_PATTERN = Pattern.compile("lttng\\s+list\\s+(.+)"); //$NON-NLS-1$
49
50
private final static String LTTNG_LIST_PROVIDER_PATTERN = "lttng\\s+list\\s+(-u|-k)"; //$NON-NLS-1$
54
55
private String fScenariofile;
55
56
private String fScenario;
57
private Map<String, Map<String, ICommandResult>> fScenarioMap = new HashMap<String, Map<String, ICommandResult>>();
58
private Map<String, Integer> fSessionNameMap = new HashMap<String, Integer>();
58
private final Map<String, Map<String, ICommandResult>> fScenarioMap = new HashMap<String, Map<String, ICommandResult>>();
59
private final Map<String, Integer> fSessionNameMap = new HashMap<String, Integer>();
61
62
* Parse a scenario file with the format:
71
72
* </COMMAND_RESULT>
75
76
* </COMMAND_OUTPUT>
79
80
* Where: ScenarioName - is the scenario name
80
81
* Command - the command line string
81
82
* CommandResult - the result integer of the command (0 for success, 1 for failure)
82
83
* ComandOutput - the command output string (multi-line possible)
84
85
* Note: 1) There can be many scenarios per file
85
86
* 2) There can be many (Command-CommandResult-CommandOutput) triples per scenario
86
87
* 3) Lines starting with # will be ignored (comments)
88
89
* @param scenariofile - path to scenario file
89
90
* @throws Exception
91
92
public synchronized void loadScenarioFile(String scenariofile) throws Exception {
92
93
fScenariofile = scenariofile;
95
96
Collection<Map<String, ICommandResult>> values = fScenarioMap.values();
96
97
for (Iterator<Map<String, ICommandResult>> iterator = values.iterator(); iterator.hasNext();) {
97
Map<String, ICommandResult> map = (Map<String, ICommandResult>) iterator.next();
98
Map<String, ICommandResult> map = iterator.next();
100
101
fScenarioMap.clear();
102
103
// load from file
105
106
FileInputStream fstream = new FileInputStream(fScenariofile);
107
108
// Get the object of DataInputStream
108
109
DataInputStream in = new DataInputStream(fstream);
109
110
BufferedReader br = new BufferedReader(new InputStreamReader(in));
112
113
// Read File Line by Line
114
// Temporary map for generating instance numbers for lttng list <session> commands.
115
// Temporary map for generating instance numbers for lttng list <session> commands.
115
116
// The numbers are per scenario.
116
117
Map<String, Integer> tmpSessionNameMap = new HashMap<String, Integer>();
117
118
while ((strLine = br.readLine()) != null) {
183
184
result = Integer.parseInt(strLine);
184
185
} else if (OUTPUT_END_KEY.equals(strLine)) {
185
186
// Save output/result in command map
186
commandMap.put(input, new CommandResult(result, output.toArray(new String[output.size()])));
187
if (output != null) {
188
commandMap.put(input, new CommandResult(result, output.toArray(new String[output.size()])));
187
190
inOutput = false;
188
191
} else if (OUTPUT_KEY.equals(strLine)) {
189
192
// first line of output
253
260
result.setResult(1);
257
264
// ------------------------------------------------------------------------
258
265
// Helper methods
259
266
// ------------------------------------------------------------------------
260
private boolean isComment(String line) {
267
private static boolean isComment(String line) {
261
268
if (line == null) {
262
269
throw new RuntimeException("line is null"); //$NON-NLS-1$