From ede2372547db659e7b0e9cfd3b531ff542018229 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 6 Jan 2021 21:01:33 +0100 Subject: Generating Wireguard files too. --- .../java/io/trygvis/rules/engine/TemplateEngine.java | 10 ++++++++++ .../ri-engine/src/main/resources/META-INF/kmodule.xml | 7 +++++-- .../main/resources/io/trygvis/rules/engine/default.drl | 16 ---------------- .../src/main/resources/io/trygvis/rules/engine/init.drl | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 18 deletions(-) delete mode 100644 module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl create mode 100644 module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl (limited to 'module/ri-engine') 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 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"> - - + + + + + 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/default.drl deleted file mode 100644 index a933bd9..0000000 --- a/module/ri-engine/src/main/resources/io/trygvis/rules/engine/default.drl +++ /dev/null @@ -1,16 +0,0 @@ -package io.trygvis.rules.engine; - -import java.util.Map -import org.apache.commons.io.FileSystem -import org.apache.commons.io.FileUtils -import java.io.File - -rule "Clean directories" - agenda-group "init" -when - not(KeyValue(key == "rm-gen")); -then - System.out.println("Cleaning gen!"); - FileUtils.deleteDirectory(new File("gen")); - insert(new KeyValue("rm-gen", null)); -end diff --git a/module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl b/module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl new file mode 100644 index 0000000..267cc4a --- /dev/null +++ b/module/ri-engine/src/main/resources/io/trygvis/rules/engine/init.drl @@ -0,0 +1,17 @@ +package io.trygvis.rules.engine; + +import java.util.Map +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 + te.clean(); + insert(new KeyValue("rm-gen", null)); +end -- cgit v1.2.3