public ConfigurationLoader withProperties(Properties properties) { this.properties = PropertiesBuilder.newBuilder().withProperties(properties).build(); return this; }
public ConfigurationLoader withFile(String path) { properties = PropertiesBuilder.newBuilder().withFile(path).build(); return this; }
public static PropertiesBuilder newBuilder() { return new PropertiesBuilder(); }
public PropertiesBuilder withFile(String file) { return withFile(new File(file)); }
private Properties replace(Properties properties) { for (Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); properties.setProperty(key, composite(value, properties)); } return properties; }
public Properties build() { try { Properties properties = new Properties(); properties.load(inputStream); return replace(properties); } catch (Exception e) { throw new RuntimeException(e); } }
public PropertiesBuilder withProperties(Properties properties) { try { Path temporaryFile = Files.createTempFile(UUID.randomUUID().toString(), ".properties"); Path fileWithContent = Files.write(temporaryFile, properties.entrySet().stream().map(entry -> { return entry.getKey() + "=" + entry.getValue(); }).collect(Collectors.toList())); return withFile(fileWithContent.toFile()); } catch (Exception e) { throw new RuntimeException(e); } }
private String composite(String value, Properties properties) { Matcher matcher = Pattern.compile("\\$([\\w]*)").matcher(value); if (matcher.find()) { String property = matcher.group(1); String currentValue = (String) properties.get(property); String composite = matcher.replaceFirst(composite(currentValue, properties)); if (composite.contains("$")) { return composite(composite, properties); } else { return composite; } } else { return value; } } }
public ConfigurationLoader withProperties(Properties properties) { this.properties = PropertiesBuilder.newBuilder().withProperties(properties).build(); return this; }
public ConfigurationLoader withFile(String path) { properties = PropertiesBuilder.newBuilder().withFile(path).build(); return this; }
@Produces @ApplicationProperties public Properties getInstance(InjectionPoint injectionPoint) { Annotated annotated = injectionPoint.getAnnotated(); ApplicationProperties applicationProperties = annotated.getAnnotation(ApplicationProperties.class); Properties properties = new Properties(); try { properties.load(findOrBuild(applicationProperties.name(),properties(applicationProperties.defaults()))); } catch (IOException ioException) { logger.error("Could not load application properties " + applicationProperties.name(), ioException); } return PropertiesBuilder.newBuilder().withProperties(properties).build(); }
@Produces @ApplicationProperties public Properties getInstance(InjectionPoint injectionPoint) { Annotated annotated = injectionPoint.getAnnotated(); ApplicationProperties applicationProperties = annotated.getAnnotation(ApplicationProperties.class); Properties properties = new Properties(); try { properties.load(findOrBuild(applicationProperties.name(),properties(applicationProperties.defaults()))); } catch (IOException ioException) { logger.error("Could not load application properties " + applicationProperties.name(), ioException); } return PropertiesBuilder.newBuilder().withProperties(properties).build(); }