You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "gitgabrio (via GitHub)" <gi...@apache.org> on 2026/04/15 14:15:02 UTC

[PR] [incubator-kie-issues#2163] Implement property retrieval from YAML files [incubator-kie-drools]

gitgabrio opened a new pull request, #6662:
URL: https://github.com/apache/incubator-kie-drools/pull/6662

   <!--
   Fixes https://github.com/apache/incubator-kie-issues/issues/2163
   
   This PR:
   1. introduce snakeyaml library for yml parsing
   2. implement yaml parsing for property retrieval
   3. implement related unit tests
   
   <details>
   <summary>
   How to replicate CI configuration locally?
   </summary>
   
   Build Chain tool does "simple" maven build(s), the builds are just Maven commands, but because the repositories relates and depends on each other and any change in API or class method could affect several of those repositories there is a need to use [build-chain tool](https://github.com/kiegroup/github-action-build-chain) to handle cross repository builds and be sure that we always use latest version of the code for each repository.
    
   [build-chain tool](https://github.com/kiegroup/github-action-build-chain) is a build tool which can be used on command line locally or in Github Actions workflow(s), in case you need to change multiple repositories and send multiple dependent pull requests related with a change you can easily reproduce the same build by executing it on Github hosted environment or locally in your development environment. See [local execution](https://github.com/kiegroup/github-action-build-chain#local-execution) details to get more information about it.
   </details>
   
   <details>
   <summary>
   How to retest this PR or trigger a specific build:
   </summary>
   
   - for <b>pull request and downstream checks</b>  
     - Push a new commit to the PR. An empty commit would be enough.
   
   - for a <b>full downstream build</b>
     - for <b>github actions</b> job: add the label `run_fdb`
   
   - for <b>Jenkins PR check only</b>
     - If you are an ASF committer for KIE podling, login to Jenkins (https://ci-builds.apache.org/job/KIE/job/drools/), go to the specific PR job, and click on `Build Now` button.
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] [incubator-kie-issues#2163] Implement property retrieval from YAML files [incubator-kie-drools]

Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio merged PR #6662:
URL: https://github.com/apache/incubator-kie-drools/pull/6662


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] [incubator-kie-issues#2163] Implement property retrieval from YAML files [incubator-kie-drools]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6662:
URL: https://github.com/apache/incubator-kie-drools/pull/6662#discussion_r3091665893


##########
drools-model/drools-codegen-common/src/main/java/org/drools/codegen/common/context/AbstractDroolsModelBuildContext.java:
##########
@@ -81,11 +83,62 @@ protected static Properties load(File... resourcePaths) {
             } catch (IOException ioe) {
                 LOGGER.debug("Unable to load '" + APPLICATION_PROPERTIES_FILE_NAME + "'.");
             }
+            File ymlFile = new File(resourcePath, APPLICATION_PROPERTIES_YML_FILE_NAME);
+            loadYmlProperties(ymlFile, applicationProperties);
+            ymlFile = new File(resourcePath, APPLICATION_PROPERTIES_YAML_FILE_NAME);
+            loadYmlProperties(ymlFile, applicationProperties);
         }
-
         return applicationProperties;
     }
 
+    protected static void loadYmlProperties(File ymlFile, Properties applicationProperties) {
+        Map<String, String> ymlMap  = loadYmlStringMap(ymlFile);
+        if (ymlMap != null) {
+            applicationProperties.putAll(ymlMap);
+        }
+    }
+
+    protected static Map<String, String> loadYmlStringMap(File ymlFile) {
+        TreeMap<String, Object> ymlMap = loadYmlMap(ymlFile);
+        if (ymlMap != null) {
+            return convertYamlObjectToMap(ymlMap);
+        } else {
+            return null;
+        }
+    }
+
+    protected static TreeMap<String, Object> loadYmlMap(File ymlFile) {
+        if (ymlFile.exists() && ymlFile.isFile() && ymlFile.canRead()) {
+            Yaml yaml = new Yaml();
+            try {
+                return yaml.loadAs(new FileReader(ymlFile, StandardCharsets.UTF_8), TreeMap.class);
+            } catch (IOException e) {

Review Comment:
   `loadYmlMap` creates a `FileReader` without closing it. This can leak file descriptors across repeated loads. Use try-with-resources around the `FileReader` (and keep the YAML load inside it) so the reader is always closed, including on success and on exceptions. Also consider catching SnakeYAML parse exceptions (e.g., `YAMLException`) here so a malformed YAML doesn't unexpectedly crash property loading (the `.properties` path logs+continues).
   



##########
drools-model/drools-codegen-common/src/test/java/org/drools/codegen/common/context/AbstractDroolsModelBuildContextTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.codegen.common.context;
+
+import org.drools.util.FileUtils;
+import org.junit.jupiter.api.Test;

Review Comment:
   Unused import `org.junit.jupiter.api.Test` (the class uses `@ParameterizedTest` only). Removing it avoids noise and keeps the test file tidy.
   



##########
drools-model/drools-codegen-common/src/main/java/org/drools/codegen/common/context/AbstractDroolsModelBuildContext.java:
##########
@@ -81,11 +83,62 @@ protected static Properties load(File... resourcePaths) {
             } catch (IOException ioe) {
                 LOGGER.debug("Unable to load '" + APPLICATION_PROPERTIES_FILE_NAME + "'.");
             }
+            File ymlFile = new File(resourcePath, APPLICATION_PROPERTIES_YML_FILE_NAME);
+            loadYmlProperties(ymlFile, applicationProperties);
+            ymlFile = new File(resourcePath, APPLICATION_PROPERTIES_YAML_FILE_NAME);
+            loadYmlProperties(ymlFile, applicationProperties);
         }
-
         return applicationProperties;
     }
 
+    protected static void loadYmlProperties(File ymlFile, Properties applicationProperties) {
+        Map<String, String> ymlMap  = loadYmlStringMap(ymlFile);
+        if (ymlMap != null) {
+            applicationProperties.putAll(ymlMap);
+        }
+    }
+
+    protected static Map<String, String> loadYmlStringMap(File ymlFile) {
+        TreeMap<String, Object> ymlMap = loadYmlMap(ymlFile);
+        if (ymlMap != null) {
+            return convertYamlObjectToMap(ymlMap);
+        } else {
+            return null;
+        }
+    }
+
+    protected static TreeMap<String, Object> loadYmlMap(File ymlFile) {
+        if (ymlFile.exists() && ymlFile.isFile() && ymlFile.canRead()) {
+            Yaml yaml = new Yaml();
+            try {
+                return yaml.loadAs(new FileReader(ymlFile, StandardCharsets.UTF_8), TreeMap.class);
+            } catch (IOException e) {
+                LOGGER.debug("Unable to load '{}'.", ymlFile.getName(), e);
+            }
+        } else {
+            LOGGER.debug("Unable to load '{}'.", ymlFile.getName());
+        }
+        return null;
+    }
+
+    protected static Map<String, String> convertYamlObjectToMap(TreeMap<String, Object> toConvert) {
+        Map<String, String> toReturn = new HashMap<>();
+        convertYamlObjectToMap(toConvert, new StringBuilder(), toReturn);
+        return toReturn;
+    }
+
+    protected static void convertYamlObjectToMap(Map<String, Object> toRead, StringBuilder builder, Map<String, String> toPopulate) {
+        toRead.forEach((key, value) -> {
+            if (value instanceof Map) {
+                StringBuilder newBuilder = new StringBuilder(builder);
+                convertYamlObjectToMap((Map<String, Object>) value, newBuilder.append(key).append("."), toPopulate);
+            } else {
+                String property = builder.toString() + key;
+                toPopulate.put(property, value.toString());

Review Comment:
   `convertYamlObjectToMap` calls `value.toString()` unconditionally. If the YAML contains an explicit null (e.g. `someKey:`) SnakeYAML will return `null` and this will throw `NullPointerException` (and `Properties` also can't store null values). Handle `null` explicitly (e.g., skip the entry or map it to an empty string) so YAML with nulls doesn't crash property loading.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org