diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-02-05 10:51:24 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-02-05 10:51:24 +0100 |
commit | d160783762ec58cdd0be781d7662865379363156 (patch) | |
tree | d09c205c255a844f359f3d99bf8212e717af1283 /src | |
parent | ba6bd2c40a22a4a9cf2307ceec0f71e4fbdc842c (diff) | |
download | rules-sandbox-d160783762ec58cdd0be781d7662865379363156.tar.gz rules-sandbox-d160783762ec58cdd0be781d7662865379363156.tar.bz2 rules-sandbox-d160783762ec58cdd0be781d7662865379363156.tar.xz rules-sandbox-d160783762ec58cdd0be781d7662865379363156.zip |
ninja, better logging.
Diffstat (limited to 'src')
4 files changed, 49 insertions, 39 deletions
diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java index 7dc24ad..b2ed790 100644 --- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java +++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import org.drools.core.common.DefaultFactHandle; +import org.drools.core.common.InternalFactHandle; import org.drools.core.factmodel.GeneratedFact; import org.kie.api.KieBase; import org.kie.api.runtime.KieContainer; @@ -233,8 +233,9 @@ public class DbIo { FileUtil.createMissingParentDirectories(file); var facts = new TreeMap<Class<?>, FactCollection<Object>>(Comparator.comparing(Class::getName)); + logger.info("The fact database has {} entries", factHandles.size()); for (var handle : factHandles) { - if (handle instanceof DefaultFactHandle h) { + if (handle instanceof InternalFactHandle h) { var obj = h.getObject(); if (!filter.apply(obj)) { continue; @@ -249,9 +250,13 @@ public class DbIo { } collection.values.add(obj); + } else { + logger.warn("Not a known FactHandle type when dumping fact: {}", handle.toExternalForm()); } } + logger.info("Outputting {} facts", facts.size()); + var objects = new ArrayList<DbObject2>(facts.size()); for (var e : facts.entrySet()) { var name = e.getKey().getName(); diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java index f2247d3..4c32087 100644 --- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java +++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java @@ -110,7 +110,6 @@ public class Engine implements Closeable { logger.info("Loaded {} objects", allObjects.size()); for (var object : allObjects) { - logger.info("object = " + object); session.insert(object); } diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java index 9e9d5f9..fa32e51 100644 --- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java +++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java @@ -122,7 +122,7 @@ public class NinjaCommand implements Callable<Integer> { out.println(" output_state=--output-state %s".formatted(dbDir.resolve(output.name + ".yaml"))); if (!output.includes.isEmpty()) { var str = output.includes.stream() - .map(s -> "--output-include=" + s) + .map(s -> "--output-include='" + s + "'") .collect(Collectors.joining(" $\n ", "\n ", "")); out.println(" output_includes=$%s".formatted(str)); diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java index 35f30cd..9b57e4f 100644 --- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java +++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java @@ -39,44 +39,50 @@ public class RunCommand implements Callable<Integer> { agendaGroups = new String[]{"init", "generate"}; } + if (outputIncludes == null) { + outputIncludes = new String[0]; + } + try (var engine = new Engine(name, input, generatedOutput, agendaGroups, module)) { - engine.io.dump(outputState, engine.session.getFactHandles(), (Object o) -> - { - if (outputIncludes == null || outputIncludes.length == 0) { - return true; - } - - var name = o.getClass().getName(); - var simpleName = o.getClass().getSimpleName(); - - for (var i : outputIncludes) { - var ok = false; - if (i.startsWith("*")) { - i = i.substring(1); - - if (i.endsWith("*")) { - i = i.substring(1, i.length() - 2); - ok = name.contains(i); - } else { - ok = name.startsWith(i) || simpleName.startsWith(i); - } - } else if (i.endsWith("*")) { - i = i.substring(0, i.length() - 2); - ok = name.startsWith(i) || simpleName.startsWith(i); - } else { - ok = name.equals(i) || simpleName.equals(i); - } - - if (ok) { - return true; - } - } - - return false; - } - ); + System.out.println("outputIncludes.length = " + outputIncludes.length); + engine.io.dump(outputState, engine.session.getFactHandles(), this::filter); } return 0; } + + private Boolean filter(Object o) { + if (outputIncludes.length == 0) { + return true; + } + + var name = o.getClass().getName(); + var simpleName = o.getClass().getSimpleName(); + var packageName = o.getClass().getPackageName(); + + for (var i : outputIncludes) { + var ok = false; + if (i.startsWith("*")) { + i = i.substring(1); + + if (i.endsWith("*")) { + i = i.substring(1, i.length() - 2); + ok = name.contains(i); + } else { + ok = name.endsWith(i) || simpleName.endsWith(i) || packageName.endsWith(i); + } + } else if (i.endsWith("*")) { + i = i.substring(0, i.length() - 2); + ok = name.startsWith(i) || simpleName.startsWith(i) || packageName.startsWith(i); + } else { + ok = name.equals(i) || simpleName.equals(i) || packageName.equals(i); + } + + if (ok) { + return true; + } + } + + return false; + } } |