use of com.bluenimble.platform.icli.mgm.commands.mgm.MacroSourceCommand in project serverless by bluenimble.
the class BlueNimble method loadScripts.
private void loadScripts(File scripts) {
if (!scripts.exists() || !scripts.isDirectory()) {
scripts.mkdir();
return;
}
File[] folders = scripts.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory();
}
});
for (File fld : folders) {
String ctx = fld.getName();
if (GlobalContext.equals(ctx)) {
ctx = Tool.ROOT_CTX;
} else {
ToolContext toolContext = getContext(ctx);
if (toolContext == null) {
addContext(new ToolContextImpl(ctx));
}
}
File[] files = fld.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isFile() && (f.getName().endsWith(MacroExt) || f.getName().endsWith(ScriptExt));
}
});
String name = null;
for (File f : files) {
name = f.getName().substring(0, f.getName().lastIndexOf(Lang.DOT));
try {
Command c = null;
if (f.getName().endsWith(MacroExt)) {
c = new MacroSourceCommand(ctx, name, f);
} else if (f.getName().endsWith(ScriptExt)) {
c = new ScriptSourceCommand(ctx, name, f);
}
if (c != null) {
addCommand(c);
}
} catch (Exception e) {
System.out.println("ERROR: Can't load command " + name + ". Cause: " + e.getMessage());
}
}
}
}
Aggregations