@Test public void loadPropertiesOneFileOneSection() { Map<String, String> p = load(f("system-properties-1.ini"), "section1"); assertEquals("value1", p.get("section1.foo-key1")); assertEquals("value2", p.get("section1.foo-key2")); assertEquals("value3", p.get("section1.foo-key3")); assertEquals("value1", p.get("section1.foo-bar-key1")); assertNull(p.get("section1.foo-key4")); }
public void load() { if (withCommon) { load(new FileWithSections(SystemProperties.CONF_FILE_COMMON)); } files.forEach(this::load); if (withAtLeastOneOf) { try { loadMutuallyAlternativeFilesInEntryOrder(mutuallyAlternativeFiles); } catch (FileNotFoundException e) { log.error("Configuration loading failed", e); } } if (withAddOn) { try { Path addOnDir = Paths.get(SystemProperties.CONF_FILE_ADDON_PATH); loadFilesInOrder(addOnDir, ADDON_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load addon configuration", e); } } if (withOverrides) { try { Path overrideDir = Paths.get(SystemProperties.getConfPath(), "conf.d"); loadFilesInOrder(overrideDir, OVERRIDE_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load override configuration", e); } } if (withLocal) { load(new FileWithSections(SystemProperties.CONF_FILE_USER_LOCAL)); } optionalLocalFiles.forEach(f -> { if (Files.isReadable(Paths.get(f.getName()))) { load(f); } }); log.debug("Loaded properties:\n{}", loadedProperties); }
SystemPropertiesLoader { public void load() { if (withCommon) { load(new FileWithSections(SystemProperties.CONF_FILE_COMMON)); } files.forEach(this::load); if (withAtLeastOneOf) { try { loadMutuallyAlternativeFilesInEntryOrder(mutuallyAlternativeFiles); } catch (FileNotFoundException e) { log.error("Configuration loading failed", e); } } if (withAddOn) { try { Path addOnDir = Paths.get(SystemProperties.CONF_FILE_ADDON_PATH); loadFilesInOrder(addOnDir, ADDON_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load addon configuration", e); } } if (withOverrides) { try { Path overrideDir = Paths.get(SystemProperties.getConfPath(), "conf.d"); loadFilesInOrder(overrideDir, OVERRIDE_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load override configuration", e); } } if (withLocal) { load(new FileWithSections(SystemProperties.CONF_FILE_USER_LOCAL)); } optionalLocalFiles.forEach(f -> { if (Files.isReadable(Paths.get(f.getName()))) { load(f); } }); log.debug("Loaded properties:\n{}", loadedProperties); } }
SystemPropertiesLoader { public void load() { if (withCommon) { load(new FileWithSections(SystemProperties.CONF_FILE_COMMON)); } files.forEach(this::load); if (withAtLeastOneOf) { try { loadMutuallyAlternativeFilesInEntryOrder(mutuallyAlternativeFiles); } catch (FileNotFoundException e) { log.error("Configuration loading failed", e); } } if (withAddOn) { try { Path addOnDir = Paths.get(SystemProperties.CONF_FILE_ADDON_PATH); loadFilesInOrder(addOnDir, ADDON_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load addon configuration", e); } } if (withOverrides) { try { Path overrideDir = Paths.get(SystemProperties.getConfPath(), "conf.d"); loadFilesInOrder(overrideDir, OVERRIDE_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load override configuration", e); } } if (withLocal) { load(new FileWithSections(SystemProperties.CONF_FILE_USER_LOCAL)); } optionalLocalFiles.forEach(f -> { if (Files.isReadable(Paths.get(f.getName()))) { load(f); } }); log.debug("Loaded properties:\n{}", loadedProperties); } protected  SystemPropertiesLoader(String prefix); }
SystemPropertiesLoader { public void load() { if (withCommon) { load(new FileWithSections(SystemProperties.CONF_FILE_COMMON)); } files.forEach(this::load); if (withAtLeastOneOf) { try { loadMutuallyAlternativeFilesInEntryOrder(mutuallyAlternativeFiles); } catch (FileNotFoundException e) { log.error("Configuration loading failed", e); } } if (withAddOn) { try { Path addOnDir = Paths.get(SystemProperties.CONF_FILE_ADDON_PATH); loadFilesInOrder(addOnDir, ADDON_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load addon configuration", e); } } if (withOverrides) { try { Path overrideDir = Paths.get(SystemProperties.getConfPath(), "conf.d"); loadFilesInOrder(overrideDir, OVERRIDE_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load override configuration", e); } } if (withLocal) { load(new FileWithSections(SystemProperties.CONF_FILE_USER_LOCAL)); } optionalLocalFiles.forEach(f -> { if (Files.isReadable(Paths.get(f.getName()))) { load(f); } }); log.debug("Loaded properties:\n{}", loadedProperties); } protected  SystemPropertiesLoader(String prefix); static SystemPropertiesLoader create(); static SystemPropertiesLoader create(String prefix); SystemPropertiesLoader withCommon(); SystemPropertiesLoader withoutOverrides(); SystemPropertiesLoader withLocal(); SystemPropertiesLoader withAddOn(); SystemPropertiesLoader withCommonAndLocal(); SystemPropertiesLoader with(String fileName,
            String... sectionNames); SystemPropertiesLoader withLocalOptional(String fileName,
                                       String... sectionNames); SystemPropertiesLoader withAtLeastOneOf(String... filePaths); void load(); }
SystemPropertiesLoader { public void load() { if (withCommon) { load(new FileWithSections(SystemProperties.CONF_FILE_COMMON)); } files.forEach(this::load); if (withAtLeastOneOf) { try { loadMutuallyAlternativeFilesInEntryOrder(mutuallyAlternativeFiles); } catch (FileNotFoundException e) { log.error("Configuration loading failed", e); } } if (withAddOn) { try { Path addOnDir = Paths.get(SystemProperties.CONF_FILE_ADDON_PATH); loadFilesInOrder(addOnDir, ADDON_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load addon configuration", e); } } if (withOverrides) { try { Path overrideDir = Paths.get(SystemProperties.getConfPath(), "conf.d"); loadFilesInOrder(overrideDir, OVERRIDE_GLOB, LOADING_ORDER_COMPARATOR); } catch (IOException e) { log.error("Cannot load override configuration", e); } } if (withLocal) { load(new FileWithSections(SystemProperties.CONF_FILE_USER_LOCAL)); } optionalLocalFiles.forEach(f -> { if (Files.isReadable(Paths.get(f.getName()))) { load(f); } }); log.debug("Loaded properties:\n{}", loadedProperties); } protected  SystemPropertiesLoader(String prefix); static SystemPropertiesLoader create(); static SystemPropertiesLoader create(String prefix); SystemPropertiesLoader withCommon(); SystemPropertiesLoader withoutOverrides(); SystemPropertiesLoader withLocal(); SystemPropertiesLoader withAddOn(); SystemPropertiesLoader withCommonAndLocal(); SystemPropertiesLoader with(String fileName,
            String... sectionNames); SystemPropertiesLoader withLocalOptional(String fileName,
                                       String... sectionNames); SystemPropertiesLoader withAtLeastOneOf(String... filePaths); void load();  }