/** * Look for all the properties file with the specific name into the classpath and call * {@link #readProperties(URL)}. */ public void readAllPropertiesFileFromClassPath(@Nonnull String resourceName) { List<URL> resources = findResources(resourceName); resources.forEach(url -> readProperties(url)); }
/** * Read a {@link Properties} from the source and loads it's content to the map detecting conflicting definition * os same property (throws a Exception). */ public void readProperties(@Nonnull File source) { if (source.exists()) { readProperties(() -> PropertiesUtils.load(source, "UTF-8"), PropertySource.of(source)); } }
/** * Read a {@link Properties} from the source and loads it's content to the map detecting conflicting definition * os same property (throws a Exception). If multiple files are found and they define the same property, then a * exception is launched. */ public void readProperties(@Nonnull URL source) { readProperties(() -> PropertiesUtils.load(source, "UTF-8"), PropertySource.of(source)); }
private PropertyMap readPropertiesFilesOverrides(PropertyMap newProperties) { File confDir = findConfDir(); if (confDir == null) { return newProperties; } PropertyMap props = new PropertyMap(newProperties); for (String name : PROPERTIES_FILES_NAME) { props.readProperties(new File(confDir, name)); } return props; }
private void readProperties(@Nonnull ISupplierEx<Properties, Exception> propertiesLoader, @Nonnull PropertySource<?> source) { if (LOGGER.isInfoEnabled()) { LOGGER.info(" Lendo arquivo de propriedades {}", source); } try { Properties properties = Objects.requireNonNull(propertiesLoader.get()); readProperties(properties, source); } catch (Exception e) { SingularPropertyException e2 = new SingularPropertyException("Fail to read properties file", e); e2.add("source", source); throw e2; } }
/** * Copia as propriedades do arquivo para as properties internas. As propriedades previamente existentes serão * sobrepostas. Esse método é utilizado para testes unitários com difererentes contextos. */ @VisibleForTesting public synchronized void reloadAndOverrideWith(URL propertiesURL) { reload(); PropertyMap p = new PropertyMap(getProperties()); p.readProperties(propertiesURL); propertyMap = p; }