@Override public AppSettings load() { Properties p = loadPropertiesFile(homeDir); p.putAll(CommandLineParser.parseArguments(cliArguments)); p.setProperty(PATH_HOME.getKey(), homeDir.getAbsolutePath()); p = ConfigurationUtils.interpolateVariables(p, System.getenv()); // the difference between Properties and Props is that the latter // supports decryption of values, so it must be used when values // are accessed Props props = new Props(p); completeDefaults(props); Arrays.stream(consumers).forEach(c -> c.accept(props)); return new AppSettingsImpl(props); }
@Test public void shouldInterpolateVariables() { Properties input = new Properties(); input.setProperty("hello", "world"); input.setProperty("url", "${env:SONAR_JDBC_URL}"); input.setProperty("do_not_change", "${SONAR_JDBC_URL}"); Map<String, String> variables = Maps.newHashMap(); variables.put("SONAR_JDBC_URL", "jdbc:h2:mem"); Properties output = ConfigurationUtils.interpolateVariables(input, variables); assertThat(output).hasSize(3); assertThat(output.getProperty("hello")).isEqualTo("world"); assertThat(output.getProperty("url")).isEqualTo("jdbc:h2:mem"); assertThat(output.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}"); // input is not changed assertThat(input).hasSize(3); assertThat(input.getProperty("hello")).isEqualTo("world"); assertThat(input.getProperty("url")).isEqualTo("${env:SONAR_JDBC_URL}"); assertThat(input.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}"); }
@Override public AppSettings load() { Properties p = loadPropertiesFile(homeDir); p.putAll(CommandLineParser.parseArguments(cliArguments)); p.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); p = ConfigurationUtils.interpolateVariables(p, System.getenv()); // the difference between Properties and Props is that the latter // supports decryption of values, so it must be used when values // are accessed Props props = new Props(p); ProcessProperties.completeDefaults(props); Arrays.stream(consumers).forEach(c -> c.accept(props)); return new AppSettingsImpl(props); }