Script line number tracking, bug fix in cmd reading

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2016-10-19 13:40:27 -04:00
parent 80d10d7d85
commit 1a207c8100
4 changed files with 35 additions and 2 deletions

View File

@ -1,3 +1,11 @@
## Version 1.2.6
* in script command failure report improved
### Bug fixes
* command line reading now succeed to parse last argument if it is a string
## Version 1.1.0
* Parsing quoted string as one argument

View File

@ -98,8 +98,8 @@ public class GCLCConstants {
inString = startIndex == index - 1;
}
}
final String arg = cmd.substring(startIndex, cmd.length());
if (!arg.isEmpty()) {
if (startIndex < cmd.length()) {
final String arg = cmd.substring(startIndex, cmd.length());
args.add(arg);
}
return args;

View File

@ -92,7 +92,9 @@ public class ScriptExecution extends Command {
for (int i = 1; i < args.length; i++) {
params[i - 1] = args[i];
}
int lineNo = -1;
while ((cmd = reader.readLine()) != null) {
lineNo++;
if (cmd.startsWith(" ") || cmd.startsWith("\t")) { //$NON-NLS-1$ //$NON-NLS-2$
reader.close();
fReader.close();
@ -106,7 +108,17 @@ public class ScriptExecution extends Command {
String cmdLine = MessageFormat.format(cmd, params);
List<String> ps = GCLCConstants.splitCommand(cmdLine);
String command = ps.remove(0);
try {
application.executeSub(command, ps.toArray(new String[0]));
} catch (CommandRunException e) {
// TODO: handle exception
throw new CommandRunException(
CommandRunExceptionType.EXECUTION,
MessageFormat.format(
"The script could not complete due to command failure at line {0} ({1})",
lineNo, e.getLocalizedMessage()),
e, this);
}
}
} catch (CommandParsingException e) {
throw new CommandRunException("Invalid command in script (" + //$NON-NLS-1$

View File

@ -129,6 +129,19 @@ public class GCLCConstantsTest {
assertTrue(res.get(2).equals("some"));
assertTrue(res.get(3).equals("arguments"));
try {
res = GCLCConstants
.splitCommand("aCommand with \"some arguments\"");
} catch (CommandParsingException e) {
fail("Unable to parse command ending with string argument " + //$NON-NLS-1$
e.getLocalizedMessage());
return;
}
assertTrue(res.size() == 3);
assertTrue(res.get(0).equals("aCommand"));
assertTrue(res.get(1).equals("with"));
assertTrue(res.get(2).equals("some arguments"));
// Wrong lines?
try {
res = GCLCConstants