From 5c9d4f5db8f202f3332cf0ad4d9672d53ed8e44e Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 1 Nov 2024 16:45:25 +0900 Subject: [PATCH 1/4] [DO-NOT-MERGE] Experiment a special prefix for Custom Operator --- .../drools/drl/ast/descr/OperatorDescr.java | 13 ++++++- .../drl/parser/antlr4/DRLExprParserTest.java | 2 +- .../drl/parser/antlr4/MiscDRLParserTest.java | 34 +++++++++++++++++-- .../drl/parser/antlr4/ParserTestUtils.java | 7 ++++ .../drl/parser/antlr4/DRL6Expressions.g4 | 5 ++- .../org/drools/drl/parser/antlr4/DRLLexer.g4 | 2 ++ .../org/drools/mvel/parser/TokenTypes.java | 1 + .../src/main/javacc/mvel.jj | 2 ++ .../CustomOperatorOnlyDrlTest.java | 3 +- .../integrationtests/CustomOperatorTest.java | 23 +++++++++---- .../mvel/integrationtests/Misc2Test.java | 16 ++++----- .../src/test/resources/logback-test.xml | 2 ++ pom.xml | 1 + 13 files changed, 87 insertions(+), 24 deletions(-) diff --git a/drools-drl/drools-drl-ast/src/main/java/org/drools/drl/ast/descr/OperatorDescr.java b/drools-drl/drools-drl-ast/src/main/java/org/drools/drl/ast/descr/OperatorDescr.java index 561bebe19a0..aa052e8632f 100644 --- a/drools-drl/drools-drl-ast/src/main/java/org/drools/drl/ast/descr/OperatorDescr.java +++ b/drools-drl/drools-drl-ast/src/main/java/org/drools/drl/ast/descr/OperatorDescr.java @@ -26,6 +26,9 @@ public class OperatorDescr extends BaseDescr { private static final long serialVersionUID = 520l; + // prefix for custom operators which are not built-in + public static final String CUSTOM_OPERATOR_PREFIX = "##"; + private String operator; private boolean negated; private List parameters; @@ -55,7 +58,15 @@ public String getOperator() { } public void setOperator( String operator ) { - this.operator = operator != null ? operator.trim() : null; + this.operator = operator != null ? trimOperator(operator) : null; + } + + private String trimOperator(String operator) { + operator = operator.trim(); + if (operator.startsWith(CUSTOM_OPERATOR_PREFIX)) { + operator = operator.substring(CUSTOM_OPERATOR_PREFIX.length()); + } + return operator; } public boolean isNegated() { diff --git a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/DRLExprParserTest.java b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/DRLExprParserTest.java index 0baeac61ff1..eb64a8351bb 100644 --- a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/DRLExprParserTest.java +++ b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/DRLExprParserTest.java @@ -458,7 +458,7 @@ void noViableAlt() { assertThat(exception.getColumn()).isEqualTo(2); assertThat(exception.getOffset()).isEqualTo(2); assertThat(exception.getMessage()) - .isEqualToIgnoringCase("[ERR 101] Line 1:2 no viable alternative at input 'a'"); + .isEqualToIgnoringCase("[ERR 101] Line 1:2 no viable alternative at input '~a'"); } else { assertThat(parser.hasErrors()).isFalse(); } diff --git a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java index 3fc2cdbca39..56fbfe11152 100644 --- a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java +++ b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java @@ -74,8 +74,8 @@ import org.drools.drl.parser.DroolsParserException; import org.drools.drl.parser.impl.Operator; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -95,6 +95,14 @@ void setUp() { parser = ParserTestUtils.getParser(); } + private static boolean isNewParser() { + return DrlParser.ANTLR4_PARSER_ENABLED; + } + + private static boolean isOldParser() { + return !DrlParser.ANTLR4_PARSER_ENABLED; + } + private String readResource(final String filename) { Path path; try { @@ -4411,8 +4419,9 @@ void traitExtendsMultiple() { .containsExactlyInAnyOrder("com.sample.ParentTrait", "UncleTrait", "org.test.GrandParentTrait"); } + @EnabledIf("isOldParser") @Test - void pluggableEvaluator() { + void pluggableEvaluatorOldParser() { final String source = "package org.drools\n" + "rule R\n" + "when\n" + @@ -4431,6 +4440,27 @@ void pluggableEvaluator() { .containsExactly("$c : core", "this not isA t.x.E.class", "this isA t.x.D.class"); } + @EnabledIf("isNewParser") + @Test + void pluggableEvaluatorNewParser() { + final String source = "package org.drools\n" + + "rule R\n" + + "when\n" + + " $t : Thing( $c : core, this not ##isA t.x.E.class, this ##isA t.x.D.class )\n" + + "then\n" + + " list.add( \"E\" ); \n" + + " don( $t, E.class ); \n" + + "end\n"; + + Operator.addOperatorToRegistry("isA", false); + Operator.addOperatorToRegistry("isA", true); + + PatternDescr pattern = (PatternDescr) parseAndGetFirstRuleDescr(source).getLhs().getDescrs().get(0); + assertThat(pattern.getConstraint().getDescrs()) + .extracting(Object::toString) + .containsExactly("$c : core", "this not ##isA t.x.E.class", "this ##isA t.x.D.class"); + } + @Test void namedConsequenceDo() { final String text = diff --git a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/ParserTestUtils.java b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/ParserTestUtils.java index 3419eab65e5..90f5c500fa0 100644 --- a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/ParserTestUtils.java +++ b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/ParserTestUtils.java @@ -55,6 +55,13 @@ public static void enableOldParser() { DrlParser.ANTLR4_PARSER_ENABLED = false; } + /** + * Enables the new parser. Just for quick testing purposes. + */ + public static void enableNewParser() { + DrlParser.ANTLR4_PARSER_ENABLED = true; + } + public static List javaKeywords() { return javaKeywords; } diff --git a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 index 063e4ed48cf..0324d1c657e 100644 --- a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 +++ b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 @@ -1000,12 +1000,11 @@ in_key ; operator_key - // IDENTIFIER is required to accept custom operators. We need to keep this semantic predicate for custom operators - : {(helper.isPluggableEvaluator(false))}? id=IDENTIFIER { helper.emit($id, DroolsEditorType.KEYWORD); } + : DRL_CUSTOM_OPERATOR_PREFIX {(helper.isPluggableEvaluator(false))}? id=IDENTIFIER { helper.emit($id, DroolsEditorType.KEYWORD); } | op=builtInOperator { helper.emit($op.token, DroolsEditorType.KEYWORD); } ; neg_operator_key - : {(helper.isPluggableEvaluator(true))}? id=IDENTIFIER { helper.emit($id, DroolsEditorType.KEYWORD); } + : DRL_CUSTOM_OPERATOR_PREFIX {(helper.isPluggableEvaluator(true))}? id=IDENTIFIER { helper.emit($id, DroolsEditorType.KEYWORD); } | op=builtInOperator { helper.emit($op.token, DroolsEditorType.KEYWORD); } ; diff --git a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 index 2c05b4dc38b..68081f9d62a 100644 --- a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 +++ b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 @@ -125,6 +125,8 @@ DRL_CALENDARS : 'calendars'; DRL_TIMER : 'timer'; DRL_DURATION : 'duration'; +DRL_CUSTOM_OPERATOR_PREFIX : '##' ; + ///////////////// // LEXER ///////////////// diff --git a/drools-model/drools-mvel-parser/src/main/java/org/drools/mvel/parser/TokenTypes.java b/drools-model/drools-mvel-parser/src/main/java/org/drools/mvel/parser/TokenTypes.java index fc5805813d3..7a478ed270c 100644 --- a/drools-model/drools-mvel-parser/src/main/java/org/drools/mvel/parser/TokenTypes.java +++ b/drools-model/drools-mvel-parser/src/main/java/org/drools/mvel/parser/TokenTypes.java @@ -213,6 +213,7 @@ public static JavaToken.Category getCategory(int kind) { case COMMA: case DOT: case AT: + case CUSTOM_OPERATOR_PREFIX: return JavaToken.Category.SEPARATOR; case MVEL_STARTS_WITH: case MVEL_ENDS_WITH: diff --git a/drools-model/drools-mvel-parser/src/main/javacc/mvel.jj b/drools-model/drools-mvel-parser/src/main/javacc/mvel.jj index d4752e980d5..3312b597e06 100644 --- a/drools-model/drools-mvel-parser/src/main/javacc/mvel.jj +++ b/drools-model/drools-mvel-parser/src/main/javacc/mvel.jj @@ -425,6 +425,7 @@ TOKEN : | < MVEL_ENDS_WITH: "str[endsWith]" > | < MVEL_LENGTH: "str[length]" > | < DOT_DOT_SLASH: "../" > +| < CUSTOM_OPERATOR_PREFIX: "##" > | < HASHMARK: "#" > | < EXCL_DOT: "!." > | < PASSIVE_OOPATH: "?/" > @@ -6419,6 +6420,7 @@ Expression PointFreeExpr(): { negated = true; } )* ( + [ ] operator = SimpleName() temporalLiteralArguments = TemporalLiteralArguments() ( diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorOnlyDrlTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorOnlyDrlTest.java index d6835f92ab5..bde8fa83768 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorOnlyDrlTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorOnlyDrlTest.java @@ -26,6 +26,7 @@ import org.drools.base.base.ValueResolver; import org.drools.base.base.ValueType; import org.drools.compiler.rule.builder.EvaluatorDefinition; +import org.drools.drl.parser.DrlParser; import org.drools.drl.parser.impl.Operator; import org.drools.base.rule.accessor.Evaluator; import org.drools.base.rule.accessor.FieldValue; @@ -74,7 +75,7 @@ public void testCustomOperatorCombiningConstraints(KieBaseTestConfiguration kieB "when\n" + " gnId : GN()\n" + " la : t547147( )\n" + - " v1717 : Tra48( gnId.gNo == gNo, name F_str[startsWith] la.c547148 || postCode F_str[contains] la.c547149 )\n" + + " v1717 : Tra48( gnId.gNo == gNo, name ##F_str[startsWith] la.c547148 || postCode ##F_str[contains] la.c547149 )\n" + "then\n" + "end\n"; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorTest.java index 0161f772935..7d5e1094fe6 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CustomOperatorTest.java @@ -27,6 +27,8 @@ import org.drools.base.base.ValueResolver; import org.drools.base.base.ValueType; import org.drools.compiler.rule.builder.EvaluatorDefinition; +import org.drools.core.reteoo.ReteDumper; +import org.drools.drl.parser.DrlParser; import org.drools.drl.parser.impl.Operator; import org.drools.base.rule.accessor.Evaluator; import org.drools.base.rule.accessor.FieldValue; @@ -58,7 +60,16 @@ public static Stream parameters() { public void testCustomOperatorUsingCollections(KieBaseTestConfiguration kieBaseTestConfiguration) { String constraints = " $alice : Person(name == \"Alice\")\n" + - " $bob : Person(name == \"Bob\", addresses supersetOf $alice.addresses)\n"; + " $bob : Person(name == \"Bob\", addresses ##supersetOf $alice.addresses)\n"; + customOperatorUsingCollections(kieBaseTestConfiguration, constraints); + } + + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCustomOperatorUsingCollectionsWithNot(KieBaseTestConfiguration kieBaseTestConfiguration) { + String constraints = + " $alice : Person(name == \"Alice\")\n" + + " $bob : Person(name == \"Bob\", $alice.addresses not ##supersetOf this.addresses)\n"; customOperatorUsingCollections(kieBaseTestConfiguration, constraints); } @@ -67,8 +78,8 @@ public void testCustomOperatorUsingCollections(KieBaseTestConfiguration kieBaseT public void testNoOperatorInstancesCreatedAtRuntime(KieBaseTestConfiguration kieBaseTestConfiguration) { String constraints = " $alice : Person(name == \"Alice\")\n" + - " $bob : Person(name == \"Bob\", addresses supersetOf $alice.addresses)\n" + - " Person(name == \"Bob\", addresses supersetOf $alice.addresses)\n"; + " $bob : Person(name == \"Bob\", addresses ##supersetOf $alice.addresses)\n" + + " Person(name == \"Bob\", addresses ##supersetOf $alice.addresses)\n"; customOperatorUsingCollections(kieBaseTestConfiguration, constraints); @@ -81,7 +92,7 @@ public void testCustomOperatorUsingCollectionsInverted(KieBaseTestConfiguration // DROOLS-6983 String constraints = " $bob : Person(name == \"Bob\")\n" + - " $alice : Person(name == \"Alice\", $bob.addresses supersetOf this.addresses)\n"; + " $alice : Person(name == \"Alice\", $bob.addresses ##supersetOf this.addresses)\n"; customOperatorUsingCollections(kieBaseTestConfiguration, constraints); } @@ -201,7 +212,7 @@ public boolean evaluateCachedRight(final ValueResolver reteEvaluator, final Vari } public boolean evaluateAll(final Collection leftCollection, final Collection rightCollection) { - return rightCollection.containsAll(leftCollection); + return getOperator().isNegated() ^ rightCollection.containsAll(leftCollection); } } @@ -212,7 +223,7 @@ public void testCustomOperatorOnKieModule(KieBaseTestConfiguration kieBaseTestCo "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + " $alice : Person(name == \"Alice\")\n" + - " $bob : Person(name == \"Bob\", addresses supersetOf $alice.addresses)\n" + + " $bob : Person(name == \"Bob\", addresses ##supersetOf $alice.addresses)\n" + "then\n" + "end\n"; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java index 980e59288cb..eae3a79dcfc 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java @@ -19,7 +19,6 @@ package org.drools.mvel.integrationtests; import java.io.Serializable; -import java.io.StringReader; import java.math.BigDecimal; import java.net.URL; import java.net.URLClassLoader; @@ -43,28 +42,24 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.drools.base.base.ValueResolver; -import org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl; -import org.drools.compiler.builder.impl.KnowledgeBuilderImpl; -import org.kie.api.runtime.ClassObjectFilter; import org.drools.base.InitialFact; import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ValueResolver; +import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.rule.accessor.Salience; +import org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl; import org.drools.core.common.DefaultFactHandle; import org.drools.core.common.InternalAgenda; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.Memory; import org.drools.core.common.NodeMemories; -import org.drools.base.definitions.InternalKnowledgePackage; -import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.impl.InternalRuleBase; -import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.ObjectTypeNodeId; import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.SegmentMemory; -import org.drools.base.rule.accessor.Salience; import org.drools.core.reteoo.TupleImpl; import org.drools.drl.ast.descr.PackageDescr; import org.drools.drl.ast.descr.PatternDescr; @@ -113,6 +108,7 @@ import org.kie.api.event.rule.MatchCancelledEvent; import org.kie.api.event.rule.MatchCreatedEvent; import org.kie.api.io.ResourceType; +import org.kie.api.runtime.ClassObjectFilter; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.KieSessionConfiguration; @@ -8836,7 +8832,7 @@ public void testKieHelperKieModuleModel() throws Exception { "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + " $alice : Person(name == \"Alice\")\n" + - " $bob : Person(name == \"Bob\", addresses supersetOf $alice.addresses)\n" + + " $bob : Person(name == \"Bob\", addresses ##supersetOf $alice.addresses)\n" + "then\n" + "end\n"; diff --git a/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml b/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml index 715224c2777..bbf35398692 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml +++ b/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml @@ -36,6 +36,8 @@ + + diff --git a/pom.xml b/pom.xml index 82960af5a91..867e70181ee 100644 --- a/pom.xml +++ b/pom.xml @@ -316,6 +316,7 @@ enableNewParser + true enableNewParser From ab5b3f66674cd07bdb12ed4f3a18031db6a5baf2 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 1 Nov 2024 18:12:57 +0900 Subject: [PATCH 2/4] - confirm new parser enabled --- .../src/test/resources/logback-test.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml b/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml index bbf35398692..348aa20cc6f 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml +++ b/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml @@ -34,7 +34,7 @@ - + From e8f6a1c5da4409e40fc8336118f19a6cbea3ecb5 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 1 Nov 2024 19:06:51 +0900 Subject: [PATCH 3/4] fix trait --- .../factmodel/traits/LegacyTraitTest.java | 2 +- .../TraitFieldsAndLegacyClassesTest.java | 37 ++++++++++--------- .../factmodel/traits/TraitMapCoreTest.java | 8 ++-- .../TraitTypeGenerationTest.java | 4 +- .../src/test/resources/logback-test.xml | 2 + 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java index 47f7e41b0d7..4c1dc9afc9c 100644 --- a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java +++ b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LegacyTraitTest.java @@ -241,7 +241,7 @@ public void traitWithMixedInterfacesExtendingEachOther(VirtualPropertyMode mode) "rule 'Bar Don'" + "when " + - " $b : BarImpl(this isA Foo.class, this not isA Foo2.class)\n" + + " $b : BarImpl(this ##isA Foo.class, this not ##isA Foo2.class)\n" + " String()\n" + "then " + " list.add(3); " + diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitFieldsAndLegacyClassesTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitFieldsAndLegacyClassesTest.java index 0ecf89bd251..f45e8d07070 100644 --- a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitFieldsAndLegacyClassesTest.java +++ b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitFieldsAndLegacyClassesTest.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.List; +import org.drools.drl.parser.DrlParser; import org.drools.traits.compiler.CommonTraitTest; import org.drools.traits.compiler.ReviseTraitTestWithPRAlwaysCategory; import org.drools.traits.core.factmodel.TraitFactoryImpl; @@ -182,7 +183,7 @@ public void testTraitFieldUpdate1(VirtualPropertyMode mode) { "rule \"test parent and child traits\" \n" + "when\n" + - " $p : ParentTrait( $c : child isA ChildTrait.class )\n" + + " $p : ParentTrait( $c : child ##isA ChildTrait.class )\n" + "then\n" + " //shed ( $p , ParentTrait.class );\n"+ " list.add(\"correct\");\n"+ @@ -270,7 +271,7 @@ public void testTraitFieldUpdate2(VirtualPropertyMode mode) { "when\n" + " $c : Child( gender == \"male\" )\n" + " $p : Parent( name == \"parent\" )\n" + - " ParentTrait( child not isA ChildTrait.class )\n" + + " ParentTrait( child not ##isA ChildTrait.class )\n" + " ChildTrait()\n"+ "then\n" + " " + @@ -282,7 +283,7 @@ public void testTraitFieldUpdate2(VirtualPropertyMode mode) { "rule \"test parent and child traits\" \n" + "when\n" + - " $p : ParentTrait( child isA ChildTrait.class )\n" + + " $p : ParentTrait( child ##isA ChildTrait.class )\n" + "then\n" + " //shed ( $p , ParentTrait.class );\n"+ " list.add(\"correct\");\n"+ @@ -369,7 +370,7 @@ public void testTraitFieldUpdate3(VirtualPropertyMode mode) { "when\n" + " Child( gender == \"male\" )\n" + " $p : Parent( name == \"parent\" )\n" + - " ParentTrait( child not isA ChildTrait.class )\n" + + " ParentTrait( child not ##isA ChildTrait.class )\n" + " $c : ChildTrait()\n"+ //<<<<< "then\n" + " $p.setChild((Child)$c.getCore());\n"+ //<<<<< @@ -379,7 +380,7 @@ public void testTraitFieldUpdate3(VirtualPropertyMode mode) { "rule \"test parent and child traits\" \n" + "when\n" + - " $p : ParentTrait( child isA ChildTrait.class )\n" + + " $p : ParentTrait( child ##isA ChildTrait.class )\n" + "then\n" + " //shed ( $p , ParentTrait.class );\n"+ " list.add(\"correct\");\n"+ @@ -448,7 +449,7 @@ public void testTraitFieldUpdate4(VirtualPropertyMode mode) { "rule \"trait child\" \n" + "when\n" + - " $p : Parent( $c := child not isA ChildTrait )\n"+ + " $p : Parent( $c := child not ##isA ChildTrait )\n"+ " $c := Child( gender == \"male\" )\n" + "then\n" + " ChildTrait c = don ( $c , ChildTrait.class );\n" + @@ -460,7 +461,7 @@ public void testTraitFieldUpdate4(VirtualPropertyMode mode) { "rule \"test parent and a child trait\" \n" + "when\n" + - " $p : Parent( child isA ChildTrait.class ) \n" + //<<<<< + " $p : Parent( child ##isA ChildTrait.class ) \n" + //<<<<< "then\n" + " list.add(\"correct\");\n"+ "end\n"+ @@ -545,7 +546,7 @@ public void testTraitFieldUpdate5(VirtualPropertyMode mode) { "rule \"test parent and child traits\" \n" + "\n" + "when\n" + - " $p : ParentTrait( $c : child isA ChildTrait.class ) \n" + //<<<<< + " $p : ParentTrait( $c : child ##isA ChildTrait.class ) \n" + //<<<<< "then\n" + " list.add(\"correct\");\n"+ "end\n"+ @@ -627,14 +628,14 @@ public void testTraitFieldUpdate6(VirtualPropertyMode mode) { "" + "rule \"Side effect\" \n" + "when \n" + - " $p : Parent( child isA ChildTrait ) \n" + + " $p : Parent( child ##isA ChildTrait ) \n" + "then \n" + " list.add(\"correct2\");\n"+ "end \n"+ "rule \"test parent and child traits\" \n" + "\n" + "when\n" + - " $p : ParentTrait( child isA ChildTrait.class )\n" + + " $p : ParentTrait( child ##isA ChildTrait.class )\n" + "then\n" + " //shed ( $p , ParentTrait.class );\n"+ " list.add(\"correct\");\n"+ @@ -720,7 +721,7 @@ public void testTraitFieldUpdate7(VirtualPropertyMode mode) { "\n" + "when\n" + // " $c : Child( $gender := gender )\n"+ - " $p : ParentTrait( child isA ChildTrait )\n" + //<<<<< + " $p : ParentTrait( child ##isA ChildTrait )\n" + //<<<<< "then\n" + " list.add(\"correct\");\n"+ "end\n"+ @@ -805,7 +806,7 @@ public void testTraitFieldUpdate8(VirtualPropertyMode mode) { "rule \"test parent and child traits\" \n" + "\n" + "when\n" + - " $p : ParentTrait( child isA ChildTrait.class )\n" + + " $p : ParentTrait( child ##isA ChildTrait.class )\n" + "then\n" + " //shed ( $p , ParentTrait.class );\n"+ " list.add(\"correct\");\n"+ @@ -885,8 +886,8 @@ public void testTraitFieldUpdate9(VirtualPropertyMode mode) { "rule \"trait and assign the child\" \n" + "\n" + "when\n" + - " $c : Child( gender == \"male\", this not isA ChildTrait )\n" + - " $p : Parent( this isA ParentTrait )\n" + + " $c : Child( gender == \"male\", this not ##isA ChildTrait )\n" + + " $p : Parent( this ##isA ParentTrait )\n" + "then\n" + " ChildTrait c = don ( $c , ChildTrait.class );\n"+ //<<<<<< " modify($p){\n"+ @@ -897,7 +898,7 @@ public void testTraitFieldUpdate9(VirtualPropertyMode mode) { "rule \"test parent and child traits\" \n" + "\n" + "when\n" + - " $p : ParentTrait( child isA ChildTrait.class, child.gender == \"male\" )\n" + //<<<<< + " $p : ParentTrait( child ##isA ChildTrait.class, child.gender == \"male\" )\n" + //<<<<< "then\n" + " //shed ( $p , ParentTrait.class );\n"+ " list.add(\"correct\");\n"+ @@ -978,8 +979,8 @@ public void testTraitFieldUpdate10(VirtualPropertyMode mode) { "rule \"trait and assign the child\" \n" + "\n" + "when\n" + - " $c : Child( gender == \"male\", this not isA ChildTrait )\n" + - " $p : Parent( this isA ParentTrait )\n" + + " $c : Child( gender == \"male\", this not ##isA ChildTrait )\n" + + " $p : Parent( this ##isA ParentTrait )\n" + "then\n" + " ChildTrait c = don ( $c , ChildTrait.class );\n"+ //<<<<<< " modify($p){\n"+ @@ -1103,7 +1104,7 @@ public void testTraitTwoParentOneChild(VirtualPropertyMode mode) { "rule \"test three traits\" \n" + "\n" + "when\n" + - " $p : FatherTrait( this isA ParentTrait, this isA GrandParentTrait )\n" + //<<<<< + " $p : FatherTrait( this ##isA ParentTrait, this ##isA GrandParentTrait )\n" + //<<<<< "then\n" + " list.add(\"correct\");\n"+ "end\n"+ diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitMapCoreTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitMapCoreTest.java index d4d9cae880c..eb7e5114915 100644 --- a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitMapCoreTest.java +++ b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitMapCoreTest.java @@ -234,7 +234,7 @@ public void testMapCore2( ) { "rule Last \n" + "salience -99 \n" + "when \n" + - " $m : Map( this not isA StudentMap.class )\n" + + " $m : Map( this not ##isA StudentMap.class )\n" + "then \n" + " $m.put( \"final\", true );" + "\n" + @@ -451,7 +451,7 @@ public void testDrools216(){ "salience 1\n" + "no-loop\n" + "when\n" + - " $map : Map($stu : this[\"worker\"] isA Student.class)\n" + + " $map : Map($stu : this[\"worker\"] ##isA Student.class)\n" + "then\n" + " Object obj = don( $map , Worker.class );\n" + " list.add(\"worker is donned\");\n" + @@ -536,7 +536,7 @@ public void testDrools217(){ "salience 1\n" + "no-loop\n" + "when\n" + - " $map : Map($stu : this[\"worker\"], $stu isA Student.class)\n" + + " $map : Map($stu : this[\"worker\"], $stu ##isA Student.class)\n" + "then\n" + " Object obj = don( $map , Worker.class );\n" + " list.add(\"worker is donned\");\n" + @@ -629,7 +629,7 @@ public void testDrools218(){ "no-loop\n" + "when\n" + " $map : Map($stu : this[\"worker\"])\n" + - " Map($stu isA Student.class, this == $map)\n" + + " Map($stu ##isA Student.class, this == $map)\n" + "then\n" + " Object obj = don( $map , Worker.class );\n" + " list.add(\"worker is donned\");\n" + diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/integrationtests/TraitTypeGenerationTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/integrationtests/TraitTypeGenerationTest.java index 51d42a2f5c4..dc8e1e9f5fe 100644 --- a/drools-traits/src/test/java/org/drools/traits/compiler/integrationtests/TraitTypeGenerationTest.java +++ b/drools-traits/src/test/java/org/drools/traits/compiler/integrationtests/TraitTypeGenerationTest.java @@ -171,7 +171,7 @@ public void testIsAWith2KContainers() { "\n" + "rule \"create student\" \n" + " when\n" + - " $student : Person( age < 26, this not isA Student )\n" + + " $student : Person( age < 26, this not ##isA Student )\n" + " then\n" + " Student s = don( $student, Student.class );\n" + " s.setSchool(\"Masaryk University\");\n" + @@ -181,7 +181,7 @@ public void testIsAWith2KContainers() { "rule \"found student\"\n" + " salience 10\n" + " when\n" + - " student : Person( this isA Student )\n" + + " student : Person( this ##isA Student )\n" + " then\n" + " students.add(student);\n" + "end"; diff --git a/drools-traits/src/test/resources/logback-test.xml b/drools-traits/src/test/resources/logback-test.xml index e5cd63021d0..d0e0e079b57 100644 --- a/drools-traits/src/test/resources/logback-test.xml +++ b/drools-traits/src/test/resources/logback-test.xml @@ -34,6 +34,8 @@ + + From 715be071b5739ee27fceb5a512f4b61149d07d3b Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 1 Nov 2024 19:07:04 +0900 Subject: [PATCH 4/4] fix GHA --- .github/workflows/pr-downstream.yml | 1 + .github/workflows/pr-drools.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-downstream.yml b/.github/workflows/pr-downstream.yml index 575f4ec6dfe..fbccd515f42 100644 --- a/.github/workflows/pr-downstream.yml +++ b/.github/workflows/pr-downstream.yml @@ -33,6 +33,7 @@ on: jobs: kogito-downstream-build: + if: false concurrency: group: pr-${{ matrix.job_name }}_${{ matrix.os }}_${{ matrix.java-version }}_${{ matrix.maven-version }}_${{ github.head_ref }} cancel-in-progress: true diff --git a/.github/workflows/pr-drools.yml b/.github/workflows/pr-drools.yml index d1f5f77b4f7..ed666b8d8a9 100644 --- a/.github/workflows/pr-drools.yml +++ b/.github/workflows/pr-drools.yml @@ -61,7 +61,7 @@ jobs: - name: Build Chain uses: apache/incubator-kie-kogito-pipelines/.ci/actions/build-chain@main env: - BUILD_MVN_OPTS_CURRENT: '-Dfull -Dreproducible' + BUILD_MVN_OPTS_CURRENT: '-Dfull -Dreproducible -DenableNewParser' MAVEN_OPTS: "-Dfile.encoding=UTF-8" with: definition-file: https://raw.githubusercontent.com/${GROUP:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/pull-request-config.yaml