summaryrefslogtreecommitdiff
path: root/module/ri-engine
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-06 21:01:33 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-06 21:01:33 +0100
commitede2372547db659e7b0e9cfd3b531ff542018229 (patch)
tree433dcb7d2bf84c6cc0ee30d92c32c6220dc53641 /module/ri-engine
parent149cf9efadb1da64b9ee716ac9bee1ac0c0e1329 (diff)
downloadrules-sandbox-ede2372547db659e7b0e9cfd3b531ff542018229.tar.gz
rules-sandbox-ede2372547db659e7b0e9cfd3b531ff542018229.tar.bz2
rules-sandbox-ede2372547db659e7b0e9cfd3b531ff542018229.tar.xz
rules-sandbox-ede2372547db659e7b0e9cfd3b531ff542018229.zip
Generating Wireguard files too.
Diffstat (limited to 'module/ri-engine')
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java10
-rw-r--r--module/ri-engine/src/main/resources/META-INF/kmodule.xml7
-rw-r--r--module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl (renamed from module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl)5
3 files changed, 18 insertions, 4 deletions
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
index 3c7c755..cc085c0 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/TemplateEngine.java
@@ -2,6 +2,7 @@ package io.trygvis.rules.engine;
import ch.qos.logback.core.util.FileUtil;
import com.hubspot.jinjava.Jinjava;
+import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
@@ -18,6 +19,15 @@ public class TemplateEngine {
this.basedir = basedir;
}
+ public void clean() {
+ try {
+ System.out.println("Cleaning gen!");
+ FileUtils.deleteDirectory(basedir);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public void template(String name, String output, Map<String, Object> params) throws IOException {
var template = Files.readString(Path.of("j2", name + ".j2"));
String renderedTemplate = jinjava.render(template, params);
diff --git a/module/ri-engine/src/main/resources/META-INF/kmodule.xml b/module/ri-engine/src/main/resources/META-INF/kmodule.xml
index ffba357..79c5e79 100644
--- a/module/ri-engine/src/main/resources/META-INF/kmodule.xml
+++ b/module/ri-engine/src/main/resources/META-INF/kmodule.xml
@@ -3,6 +3,9 @@
xmlns="http://www.drools.org/xsd/kmodule"
xsi:schemaLocation="http://www.drools.org/xsd/kmodule https://www.drools.org/xsd/kmodule_7_1.xsd">
- <kbase name="engine" packages="io.trygvis.rules.dba,io.trygvis.rules.engine,io.trygvis.rules.machine,io.trygvis.rules.terraform">
- </kbase>
+ <kbase name="all" packages="io.trygvis.rules.*"/>
+ <kbase name="engine" packages="io.trygvis.rules.engine"/>
+ <kbase name="dba" packages="io.trygvis.rules.dba"/>
+ <kbase name="machine" packages="io.trygvis.rules.machine"/>
+ <kbase name="terraform" packages="io.trygvis.rules.terraform"/>
</kmodule>
diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl
index a933bd9..267cc4a 100644
--- a/module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl
+++ b/module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl
@@ -5,12 +5,13 @@ import org.apache.commons.io.FileSystem
import org.apache.commons.io.FileUtils
import java.io.File
+global io.trygvis.rules.engine.TemplateEngine te;
+
rule "Clean directories"
agenda-group "init"
when
not(KeyValue(key == "rm-gen"));
then
- System.out.println("Cleaning gen!");
- FileUtils.deleteDirectory(new File("gen"));
+ te.clean();
insert(new KeyValue("rm-gen", null));
end