Skip to content

Commit

Permalink
Can pass configuration using system properties
Browse files Browse the repository at this point in the history
For example, one can run:

    mvn test -Dnotifier.anybar.port=1740

to change port used by AnyBar to indicate build status.
  • Loading branch information
jcgay committed Apr 26, 2015
1 parent f1bbee8 commit 351c771
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Properties;

import static fr.jcgay.maven.notifier.ConfigurationParser.ConfigurationProperties.Property.IMPLEMENTATION;
Expand Down Expand Up @@ -144,6 +145,13 @@ private static class ConfiguredProperties {
public Properties properties() {
Properties result = new Properties();
result.putAll(properties);

for (Map.Entry<Object, Object> property : System.getProperties().entrySet()) {
if (property.getKey().toString().startsWith("notifier.")) {
result.put(property.getKey(), property.getValue());
}
}

String overrideImplementation = System.getProperty(NOTIFY_WITH.key());
if (overrideImplementation != null) {
result.put(IMPLEMENTATION.key(), overrideImplementation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ class ConfigurationParserTest {

assertThat(result[IMPLEMENTATION.key()]).isEqualTo('snarl')
}

@Test
void 'should use configuration passed by system property'() {

System.setProperty('notifier.anybar.port', '1111')
System.setProperty('notifier.anybar.host', 'localhost')

def result = ConfigurationParser.readProperties(getClass().getResource('/anybar.properties'))

assertThat result['notifier.anybar.port'] isEqualTo '1111'
assertThat result['notifier.anybar.host'] isEqualTo 'localhost'
}
}
2 changes: 2 additions & 0 deletions src/test/resources/anybar.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
notifier.anybar.port=1738
notifier.anybar.host=192.168.1.1

0 comments on commit 351c771

Please sign in to comment.