in gshell-commands/gshell-builtin/src/main/java/org/apache/geronimo/gshell/commands/builtin/SourceAction.java [60:99]
public Object execute(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 no content: {}", file.getName());
return Result.FAILURE;
}
log.debug("Sourcing file: {}", file.getName());
BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContent().getInputStream()));
try {
String line;
while ((line = reader.readLine()) != null) {
String tmp = line.trim();
// Ignore empty lines and comments
if (tmp.length() == 0 || tmp.startsWith("#")) {
continue;
}
executor.execute(ShellContextHolder.get(), line);
}
}
finally {
reader.close();
file.close();
}
return Result.SUCCESS;
}