Implement loading of DSL rules
This commit is contained in:
parent
c00b71e2ba
commit
1304755c25
@ -21,6 +21,7 @@ import it.cavallium.warppi.math.MathContext;
|
|||||||
import it.cavallium.warppi.math.functions.Expression;
|
import it.cavallium.warppi.math.functions.Expression;
|
||||||
import it.cavallium.warppi.math.functions.Variable;
|
import it.cavallium.warppi.math.functions.Variable;
|
||||||
import it.cavallium.warppi.math.functions.Variable.V_TYPE;
|
import it.cavallium.warppi.math.functions.Variable.V_TYPE;
|
||||||
|
import it.cavallium.warppi.math.rules.dsl.RulesDsl;
|
||||||
import it.cavallium.warppi.math.solver.MathSolver;
|
import it.cavallium.warppi.math.solver.MathSolver;
|
||||||
import it.cavallium.warppi.util.Error;
|
import it.cavallium.warppi.util.Error;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
@ -38,7 +39,10 @@ public class RulesManager {
|
|||||||
for (final RuleType val : RuleType.values()) {
|
for (final RuleType val : RuleType.values()) {
|
||||||
RulesManager.rules[val.ordinal()] = new ObjectArrayList<>();
|
RulesManager.rules[val.ordinal()] = new ObjectArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
loadDslRules();
|
||||||
|
|
||||||
boolean compiledSomething = false;
|
boolean compiledSomething = false;
|
||||||
InputStream defaultRulesList;
|
InputStream defaultRulesList;
|
||||||
try {
|
try {
|
||||||
@ -148,12 +152,40 @@ public class RulesManager {
|
|||||||
if (cacheFileStream != null) {
|
if (cacheFileStream != null) {
|
||||||
cacheFileStream.close();
|
cacheFileStream.close();
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException | IOException e) {
|
} catch (URISyntaxException | IOException | RuntimeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Engine.getPlatform().exit(1);
|
Engine.getPlatform().exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void loadDslRules() throws IOException {
|
||||||
|
final StorageUtils storageUtils = Engine.getPlatform().getStorageUtils();
|
||||||
|
|
||||||
|
final File dslRulesPath = storageUtils.get("rules/dsl/");
|
||||||
|
if (!dslRulesPath.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final File file : storageUtils.walk(dslRulesPath)) {
|
||||||
|
if (!file.toString().endsWith(".rules")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Engine.getPlatform().getConsoleUtils().out().println(
|
||||||
|
ConsoleUtils.OUTPUTLEVEL_NODEBUG,
|
||||||
|
"RulesManager",
|
||||||
|
"Found DSL rules file: " + file.getAbsolutePath()
|
||||||
|
);
|
||||||
|
|
||||||
|
final String source;
|
||||||
|
try (final InputStream resource = storageUtils.getResourceStream(file.toString())) {
|
||||||
|
source = storageUtils.read(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
RulesDsl.makeRules(source).forEach(RulesManager::addRule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Rule compileJavaRule(final String scriptFile, final File tDir) throws IOException, URISyntaxException,
|
public static Rule compileJavaRule(final String scriptFile, final File tDir) throws IOException, URISyntaxException,
|
||||||
InstantiationException, IllegalAccessException, ClassNotFoundException {
|
InstantiationException, IllegalAccessException, ClassNotFoundException {
|
||||||
final InputStream resource = Engine.getPlatform().getStorageUtils().getResourceStream(scriptFile);
|
final InputStream resource = Engine.getPlatform().getStorageUtils().getResourceStream(scriptFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user