use of org.btrplace.btrpsl.ScriptBuilderException in project scheduler by btrplace.
the class PathBasedIncludes method getScripts.
/**
* Get the script associated to a given identifier by browsing the given paths.
* The first script having a matching identifier is selected, whatever the parsing process result will be
*
* @param name the identifier of the script
* @return the script if found
* @throws org.btrplace.btrpsl.ScriptBuilderException if the builder was not able to parse the looked script
*/
@Override
public List<Script> getScripts(String name) throws ScriptBuilderException {
List<Script> scripts = new ArrayList<>();
if (!name.endsWith(".*")) {
String toSearch = name.replaceAll("\\.", File.separator) + Script.EXTENSION;
for (File path : paths) {
File f = new File(path.getPath() + File.separator + toSearch);
if (f.exists()) {
scripts.add(builder.build(f));
break;
}
}
} else {
// We need to consolidate the errors in allEx and rethrow it at the end if necessary
ScriptBuilderException allEx = null;
String base = name.substring(0, name.length() - 2).replaceAll("\\.", File.separator);
for (File path : paths) {
File f = new File(path.getPath() + File.separator + base);
File[] files = f.listFiles();
if (f.isDirectory() && files != null) {
for (File sf : files) {
if (sf.getName().endsWith(Script.EXTENSION)) {
try {
scripts.add(builder.build(sf));
} catch (ScriptBuilderException ex) {
if (allEx == null) {
allEx = ex;
} else {
allEx.getErrorReporter().getErrors().addAll(ex.getErrorReporter().getErrors());
}
}
}
}
}
}
if (allEx != null) {
throw allEx;
}
}
return scripts;
}
use of org.btrplace.btrpsl.ScriptBuilderException in project scheduler by btrplace.
the class ImportStatement method go.
@Override
@SuppressWarnings("squid:S1166")
public BtrpOperand go(BtrPlaceTree parent) {
String id = scriptId();
List<Script> res;
try {
res = includes.getScripts(id);
script.getDependencies().addAll(res);
} catch (ScriptBuilderException e) {
int nb = e.getErrorReporter().getErrors().size();
return ignoreError(Integer.toString(nb) + " error(s) imported through '" + id + "'");
}
if (res.isEmpty()) {
return ignoreError(getChild(0).getToken(), "Unable to locate '" + id + "'");
}
if (id.endsWith(".*")) {
// Prepare the global variable.
BtrpSet global = new BtrpSet(1, BtrpOperand.Type.VM);
global.setLabel("$".concat(id.substring(0, id.length() - 2)));
if (global.size() > 0 && !symTable.declareImmutable(global.label(), global)) {
return ignoreError("Unable to add variable '" + global.label() + "'");
}
}
for (Script v : res) {
for (BtrpOperand op : v.getImportables(script.id())) {
String fqn = v.fullyQualifiedSymbolName(op.label());
if (!symTable.declareImmutable(fqn, op)) {
return ignoreError("Unable to import '" + fqn + "': already declared");
}
}
}
return IgnorableOperand.getInstance();
}
Aggregations