in gshell-commands/gshell-bsf/src/main/java/org/apache/geronimo/gshell/commands/bsf/ScriptAction.java [149:187]
private Object exec(final CommandContext context) throws Exception {
assert context != null;
IO io = context.getIo();
FileObject cwd = fileSystemAccess.getCurrentDirectory(context.getVariables());
FileObject file = fileSystemAccess.resolveFile(cwd, path);
if (!file.exists()) {
io.error("File not found: {}", file.getName());
return Result.FAILURE;
}
else if (!file.getType().hasContent()) {
io.error("File has not content: {}", file.getName());
return Result.FAILURE;
}
else if (!file.isReadable()) {
io.error("File is not readable: {}", file.getName());
return Result.FAILURE;
}
if (language == null) {
language = detectLanguage(file);
}
BSFEngine engine = createEngine(context);
byte[] bytes = FileUtil.getContent(file);
String script = new String(bytes);
log.info("Evaluating file ({}): {}", language, path);
try {
return engine.eval(file.getName().getBaseName(), 1, 1, script);
}
finally {
engine.terminate();
file.close();
}
}