From 42bc10b1dbd91d67b74774313cd4869ac3ce8d56 Mon Sep 17 00:00:00 2001 From: Stephan Pelikan Date: Mon, 21 Oct 2024 16:55:11 +0200 Subject: [PATCH] Add support for additional classpath locations of property-yaml files (#21) --- ...WorkflowModulePropertiesConfiguration.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/vanillabp/springboot/modules/WorkflowModulePropertiesConfiguration.java b/src/main/java/io/vanillabp/springboot/modules/WorkflowModulePropertiesConfiguration.java index 43bc844..2ef743e 100644 --- a/src/main/java/io/vanillabp/springboot/modules/WorkflowModulePropertiesConfiguration.java +++ b/src/main/java/io/vanillabp/springboot/modules/WorkflowModulePropertiesConfiguration.java @@ -1,6 +1,8 @@ package io.vanillabp.springboot.modules; import io.vanillabp.springboot.utils.CaseUtils; +import java.util.LinkedList; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; @@ -14,9 +16,6 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import java.util.LinkedList; -import java.util.List; - @AutoConfigurationPackage @AutoConfigureBefore(PropertyPlaceholderAutoConfiguration.class) @ConditionalOnBean(WorkflowModuleProperties.class) @@ -68,10 +67,11 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon private static boolean addYaml( final LinkedList resources, - final String filename) { - + final String directory, + final String formatedWorkflowModuleId) { + final var defaultsYaml = new ClassPathResource( - "/config/" + filename + ".yaml"); + directory + formatedWorkflowModuleId + ".yaml"); if (defaultsYaml.exists()) { logger.debug("Adding yaml-file: {}", defaultsYaml.getDescription()); resources.add(defaultsYaml); @@ -79,7 +79,7 @@ private static boolean addYaml( } final var defaultsYml = new ClassPathResource( - "/config/" + filename + ".yml"); + directory + formatedWorkflowModuleId + ".yml"); if (defaultsYml.exists()) { logger.debug("Adding yaml-file: {}", defaultsYml.getDescription()); resources.add(defaultsYml); @@ -90,4 +90,24 @@ private static boolean addYaml( } + private static boolean addYaml( + final LinkedList resources, + final String formatedWorkflowModuleId) { + + if (addYaml(resources, "", formatedWorkflowModuleId)) { + return true; + } + if (addYaml(resources, "config/", formatedWorkflowModuleId)) { + return true; + } + if (addYaml(resources, formatedWorkflowModuleId + "/", formatedWorkflowModuleId)) { + return true; + } + if (addYaml(resources, formatedWorkflowModuleId + "/config/", formatedWorkflowModuleId)) { + return true; + } + return false; + + } + }