@@ -26,16 +26,6 @@ public ConfigLoader(@Named("configDir") String configDir) {
26
26
this .configDir = configDir ;
27
27
}
28
28
29
- public JsonNode load (String fileName ) {
30
- String filePath = configDir + File .separator + fileName ;
31
- try (InputStream fileStream = new FileInputStream (filePath )) {
32
- logger .debug ("Loading config from path {}" , filePath );
33
- return objectMapper .reader ().readTree (fileStream );
34
- } catch (IOException e ) {
35
- throw new ConfigException (String .format ("Error loading config %s" , fileName ), e );
36
- }
37
- }
38
-
39
29
/**
40
30
* Get a config, modified for the specified profile
41
31
*
@@ -44,26 +34,43 @@ public JsonNode load(String fileName) {
44
34
* @return Combined config for profile
45
35
*/
46
36
public JsonNode getProfileConfig (String configName , String profileName ) {
47
- // TODO: check if that profile even exists
48
37
JsonNode mainConfig = load (configName );
49
- File f = new File (configDir + File .separator + profileName + File .separator + configName );
38
+ if (profileName .equals ("empty" )) {
39
+ return mainConfig ;
40
+ }
41
+ File file = new File (configDir + File .separator + profileName + File .separator + configName );
42
+ File folder = new File (configDir + File .separator + profileName );
50
43
// check if we should just use default config
51
- if (profileName .equals ("empty" ) || !f .exists ()) {
44
+ if (!file .exists ()) {
45
+ logger .info ("No profile config file exists for {}, using base config" , configName );
46
+ return mainConfig ;
47
+ } else if (!folder .exists ()) {
48
+ logger .warn ("No such profile as {} found, base config will be used." , profileName );
52
49
return mainConfig ;
53
50
} else {
54
51
JsonNode profileConfig = load (profileName + File .separator + configName );
55
52
return mergeNodes (mainConfig , profileConfig );
56
53
}
57
54
}
58
55
56
+ private JsonNode load (String fileName ) {
57
+ String filePath = configDir + File .separator + fileName ;
58
+ try (InputStream fileStream = new FileInputStream (filePath )) {
59
+ logger .debug ("Loading config from path {}" , filePath );
60
+ return objectMapper .reader ().readTree (fileStream );
61
+ } catch (IOException e ) {
62
+ throw new ConfigException (String .format ("Error loading config %s" , fileName ), e );
63
+ }
64
+ }
65
+
59
66
/**
60
67
* Combine two JsonNodes
61
68
*
62
69
* @param mainNode Node to merge into
63
70
* @param updateNode Node to merge with
64
71
* @return Combined node
65
72
*/
66
- public static JsonNode mergeNodes (JsonNode mainNode , JsonNode updateNode ) {
73
+ private JsonNode mergeNodes (JsonNode mainNode , JsonNode updateNode ) {
67
74
Iterator <String > fieldNames = updateNode .fieldNames ();
68
75
while (fieldNames .hasNext ()) {
69
76
String fieldName = fieldNames .next ();
0 commit comments