Skip to content

Commit d5568ae

Browse files
authored
Merge pull request #141 from scalecube/feature/advanced-system-props
Enhanced SystemEnvironmentConfigSource config soucece
2 parents 55c3cce + bb0775f commit d5568ae

File tree

13 files changed

+68
-57
lines changed

13 files changed

+68
-57
lines changed

config-examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.scalecube</groupId>
66
<artifactId>scalecube-config-parent</artifactId>
7-
<version>0.3.15-SNAPSHOT</version>
7+
<version>0.4.0-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

config-examples/src/main/java/io/scalecube/config/examples/PredicateOrderingConfigExample.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.scalecube.config.ConfigRegistrySettings;
55
import io.scalecube.config.StringConfigProperty;
66
import io.scalecube.config.source.ClassPathConfigSource;
7+
import io.scalecube.config.source.SystemPropertiesConfigSource;
78
import java.nio.file.Path;
89
import java.util.function.Predicate;
910

@@ -17,19 +18,41 @@ public class PredicateOrderingConfigExample {
1718
*/
1819
public static void main(String[] args) {
1920
Predicate<Path> propsPredicate = path -> path.toString().endsWith(".props");
21+
Predicate<Path> rootPredicate =
22+
propsPredicate.and(path -> path.toString().contains("config.props"));
2023
Predicate<Path> firstPredicate = propsPredicate.and(path -> path.toString().contains("order1"));
2124
Predicate<Path> secondPredicate =
2225
propsPredicate.and(path -> path.toString().contains("order2"));
26+
Predicate<Path> customSysPredicate =
27+
propsPredicate.and(path -> path.toString().contains("customSys"));
28+
29+
// Emulate scenario where sys.foo was also given from system properties
30+
// System.setProperty("sys.foo", "sys foo from java system properties");
2331

2432
ConfigRegistry configRegistry =
2533
ConfigRegistry.create(
2634
ConfigRegistrySettings.builder()
35+
.addLastSource("sysProps", new SystemPropertiesConfigSource())
36+
.addLastSource(
37+
"customSysProps",
38+
new SystemPropertiesConfigSource(new ClassPathConfigSource(customSysPredicate)))
2739
.addLastSource(
28-
"classpath", new ClassPathConfigSource(firstPredicate, secondPredicate))
40+
"classpath",
41+
new ClassPathConfigSource(firstPredicate, secondPredicate, rootPredicate))
2942
.build());
3043

3144
StringConfigProperty orderedProp1 = configRegistry.stringProperty("orderedProp1");
45+
String foo = configRegistry.stringValue("foo", null);
46+
String bar = configRegistry.stringValue("bar", null);
47+
String sysFoo = configRegistry.stringValue("sys.foo", null);
3248

33-
System.out.println("### Matched by first predicate orderedProp1=" + orderedProp1.value().get());
49+
System.out.println(
50+
"### Matched by first predicate: orderedProp1=" + orderedProp1.value().get());
51+
System.out.println("### Regardeless of predicates: foo=" + foo + ", bar=" + bar);
52+
System.out.println(
53+
"### Custom system property: sysFoo="
54+
+ sysFoo
55+
+ ", System.getProperty(sysFoo)="
56+
+ System.getProperty("sys.foo"));
3457
}
3558
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
prop1=from_classpath
1+
foo=foo
2+
bar=bar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sys.foo=very cool custom system property

config-http-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.scalecube</groupId>
66
<artifactId>scalecube-config-parent</artifactId>
7-
<version>0.3.15-SNAPSHOT</version>
7+
<version>0.4.0-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

config-mongo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.scalecube</groupId>
66
<artifactId>scalecube-config-parent</artifactId>
7-
<version>0.3.15-SNAPSHOT</version>
7+
<version>0.4.0-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

config-vault/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.scalecube</groupId>
77
<artifactId>scalecube-config-parent</artifactId>
8-
<version>0.3.15-SNAPSHOT</version>
8+
<version>0.4.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>config-vault</artifactId>

config/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.scalecube</groupId>
66
<artifactId>scalecube-config-parent</artifactId>
7-
<version>0.3.15-SNAPSHOT</version>
7+
<version>0.4.0-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

config/src/main/java/io/scalecube/config/source/ClassPathConfigSource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.jar.JarEntry;
2929
import java.util.jar.JarFile;
3030

31-
public class ClassPathConfigSource extends FilteredPathConfigSource {
31+
public final class ClassPathConfigSource extends FilteredPathConfigSource {
3232
private final ClassLoader classLoader;
3333

3434
private Map<String, ConfigProperty> loadedConfig;
@@ -67,8 +67,7 @@ public Map<String, ConfigProperty> loadConfig() {
6767
}
6868

6969
Collection<Path> pathCollection = new ArrayList<>();
70-
getClassPathEntries(classLoader)
71-
.stream()
70+
getClassPathEntries(classLoader).stream()
7271
.filter(uri -> uri.getScheme().equals("file"))
7372
.forEach(
7473
uri -> {

config/src/main/java/io/scalecube/config/source/DirectoryConfigSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.function.Predicate;
2020
import java.util.stream.Collectors;
2121

22-
public class DirectoryConfigSource extends FilteredPathConfigSource {
22+
public final class DirectoryConfigSource extends FilteredPathConfigSource {
2323
private final Path basePath;
2424

2525
/**

0 commit comments

Comments
 (0)