diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-28 15:52:17 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-28 15:52:17 +0100 |
commit | d167fc9b40a83187c657f3a048f19ac56f529af3 (patch) | |
tree | 2a8fb8e64e3348a9e60727b5fc9d8cc3ec14faa7 | |
parent | 0ae7ecd47fd76921e8e1137739497578fe703354 (diff) | |
download | rules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.tar.gz rules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.tar.bz2 rules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.tar.xz rules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.zip |
Better main().
* More than one input database.
* Only creating templating engine if the rules require it.
-rwxr-xr-x | engine | 10 | ||||
-rw-r--r-- | module/ri-engine/pom.xml | 2 | ||||
-rw-r--r-- | module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java | 27 | ||||
-rw-r--r-- | module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java | 2 | ||||
-rw-r--r-- | module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java | 2 | ||||
-rw-r--r-- | module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java | 2 | ||||
-rw-r--r-- | pom.xml | 9 |
7 files changed, 36 insertions, 18 deletions
@@ -5,7 +5,17 @@ set -euo pipefail basedir="$(dirname $0)" jar="$(echo $basedir/module/ri-engine/target/ri-engine-*-fat.jar)" +if [[ ! -r engine_completion ]] +then + echo "Generating completion script" + java --enable-preview \ + -cp "$jar" \ + picocli.AutoComplete \ + io.trygvis.rules.engine.Main +fi + exec java \ --enable-preview \ + --add-opens java.base/java.lang=ALL-UNNAMED \ -jar "$jar" \ "${@}" diff --git a/module/ri-engine/pom.xml b/module/ri-engine/pom.xml index c667145..01a72cc 100644 --- a/module/ri-engine/pom.xml +++ b/module/ri-engine/pom.xml @@ -169,7 +169,7 @@ <executable>java</executable> <arguments> <argument>-Dpicocli.autocomplete.systemExitOnError</argument> - <argument>--enable-preview</argument> + <argument>${java.preview}</argument> <argument>-cp</argument> <classpath/> <argument>picocli.AutoComplete</argument> diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java index 4a49ca2..fbb79aa 100644 --- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java +++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java @@ -29,7 +29,7 @@ public class Engine implements Closeable { public final DbIo io; public final KieSession session; - public Engine(String name, File database, File output, String[] agendaGroups, File[] modules) throws IOException { + public Engine(String name, File[] databases, File output, String[] agendaGroups, File[] modules) throws IOException { logger.info("Getting KieServices"); var services = KieServices.Factory.get(); @@ -85,20 +85,29 @@ public class Engine implements Closeable { session.addEventListener((AgendaEventListener) l); session.addEventListener((RuleRuntimeEventListener) l); - session.setGlobal("te", new JinjavaTemplateEngine(templateLoader, output)); + var te = session.getGlobals().get("te"); + if (te != null) { + session.setGlobal("te", new JinjavaTemplateEngine(templateLoader, output)); + } logger.info("Loading data"); io = new DbIo(container, kieBase); - var objects = io.load(database); - if (objects.isEmpty()) { - logger.warn("Did not load any objects, something is wrong"); - return; - } + List<Object> allObjects = new ArrayList<>(); + for (File database : databases) { + var objects = io.load(database); - logger.info("Loaded {} objects", objects.size()); + if (objects.isEmpty()) { + logger.warn("Did not load any objects, something is wrong"); + return; + } + + logger.info("Loaded {} objects from {}", objects.size(), objects.size()); + allObjects.addAll(objects); + } + logger.info("Loaded {} objects", allObjects.size()); - for (var object : objects) { + for (var object : allObjects) { logger.info("object = " + object); session.insert(object); } diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java index 203a9b0..f61acbe 100644 --- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java +++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java @@ -15,7 +15,7 @@ public class RunCommand implements Callable<Integer> { public String name; @Option(names = {"-i", "--input"}) - public File input; + public File[] input; @Option(names = {"--output-state"}) public File outputState; diff --git a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java index 17b7950..37e8787 100644 --- a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java +++ b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java @@ -10,7 +10,7 @@ class AcmeAppsTestMain { public static void main(String[] args) throws Exception { var c = new RunCommand(); c.name = "acme-apps"; - c.input = new File("acme.yaml"); + c.input = new File[]{new File("acme.yaml")}; c.outputState = new File("out/acme/apps.yaml"); c.agendaGroups = new String[]{"init", "generate"}; c.generatedOutput = new File("acme-apps"); diff --git a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java index 2bb5513..4d88e39 100644 --- a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java +++ b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java @@ -10,7 +10,7 @@ class AcmeWireguardTestMain { public static void main(String[] args) throws Exception { var c = new RunCommand(); c.name = "acme-wireguard"; - c.input = new File("acme.yaml"); + c.input = new File[]{new File("acme.yaml")}; c.outputState = new File("out/acme/wireguard.yaml"); c.agendaGroups = new String[]{"init", "generate"}; c.generatedOutput = new File("acme-wireguard"); @@ -17,8 +17,9 @@ <version.drools>7.48.0.Final</version.drools> <version.springboot>2.3.1.RELEASE</version.springboot> <version.picocli>4.6.1</version.picocli> - <java.version>15</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <java.version>16</java.version> + <java.preview><!--enable-preview--></java.preview> </properties> <dependencyManagement> @@ -86,9 +87,7 @@ <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> - <compilerArgs> - <arg>--enable-preview</arg> - </compilerArgs> + <compilerArgs>${java.preview}</compilerArgs> <encoding>UTF-8</encoding> <release>${java.version}</release> <source>${java.version}</source> @@ -100,7 +99,7 @@ <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> - <argLine>--enable-preview</argLine> + <argLine>${java.preview}</argLine> </configuration> </plugin> <plugin> |