Skip to content

Commit

Permalink
Add support for additional classpath locations of property-yaml files (
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanpelikan committed Oct 21, 2024
1 parent 9abde56 commit 42bc10b
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -68,18 +67,19 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon

private static boolean addYaml(
final LinkedList<Resource> 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);
return true;
}

final var defaultsYml = new ClassPathResource(
"/config/" + filename + ".yml");
directory + formatedWorkflowModuleId + ".yml");
if (defaultsYml.exists()) {
logger.debug("Adding yaml-file: {}", defaultsYml.getDescription());
resources.add(defaultsYml);
Expand All @@ -90,4 +90,24 @@ private static boolean addYaml(

}

private static boolean addYaml(
final LinkedList<Resource> 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;

}

}

0 comments on commit 42bc10b

Please sign in to comment.