Skip to content

Commit 26938a8

Browse files
committed
Alias env vars. Pick them up for cucumber.properties.
1 parent d4b114a commit 26938a8

File tree

9 files changed

+28
-11
lines changed

9 files changed

+28
-11
lines changed

History.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## [1.1.8-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.7...master)
2+
3+
* [Core] Environment variables/properties are aliased. Example: `HELLO_THERE` == `hello.there` (Aslak Hellesøy)
4+
* [Core] The `cucumber-jvm.properties` file is no longer picked up. Use `cucumber.properties` instead (Aslak Hellesøy)
25
* [Core] Make standrd out non-buffered ([#721](https://github.com/cucumber/cucumber-jvm/pull/721) danielhodder)
36
* [Core] Allow empty doc string and data table entries after token replacement from scenario outlines ([#712](https://github.com/cucumber/cucumber-jvm/issues/712), [#709](https://github.com/cucumber/cucumber-jvm/pull/709), [#713](https://github.com/cucumber/cucumber-jvm/pull/713) Leon Poon, Björn Rasmusson)
47
* [Guice] New scenario scope for Guice. Non-backwards compatible ([#683](https://github.com/cucumber/cucumber-jvm/pull/683) jakecollins)

android/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1.7-SNAPSHOT" package="cucumber.api.android">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1.7" package="cucumber.api.android">
33
</manifest>

core/src/main/java/cucumber/runtime/Env.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ public Env(String bundleName, Properties properties) {
3434
}
3535

3636
public String get(String key) {
37-
String value = System.getenv(asEnvKey(key));
37+
String result = get0(asEnvKey(key));
38+
if (result == null) {
39+
result = get0(asPropertyKey(key));
40+
}
41+
return result;
42+
}
43+
44+
private String get0(String key) {
45+
String value = System.getenv(key);
3846
if (value == null) {
3947
value = properties.getProperty(key);
4048
if (value == null && bundleName != null) {
@@ -55,4 +63,8 @@ public String get(String key, String defaultValue) {
5563
private static String asEnvKey(String key) {
5664
return key.replace('.', '_').toUpperCase();
5765
}
66+
67+
private static String asPropertyKey(String key) {
68+
return key.replace('_', '.').toLowerCase();
69+
}
5870
}

core/src/main/java/cucumber/runtime/RuntimeOptions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public RuntimeOptions(Env env, List<String> argv) {
6767
}
6868

6969
public RuntimeOptions(FormatterFactory formatterFactory, List<String> argv) {
70-
this(new Env("cucumber-jvm"), formatterFactory, argv);
70+
this(new Env("cucumber"), formatterFactory, argv);
7171
}
7272

7373
public RuntimeOptions(Env env, FormatterFactory formatterFactory, List<String> argv) {

core/src/test/java/cucumber/runtime/EnvTest.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ public void returns_null_for_absent_key() {
2323
@Test
2424
public void looks_up_value_from_system_properties() {
2525
try {
26-
System.setProperty("EnvTest", "from-props");
27-
assertEquals("from-props", env.get("EnvTest"));
26+
System.setProperty("env.test", "from-props");
27+
assertEquals("from-props", env.get("env.test"));
28+
assertEquals("from-props", env.get("ENV_TEST"));
2829
} finally {
29-
System.getProperties().remove("EnvTest");
30+
System.getProperties().remove("env.test");
3031
}
3132
}
3233

3334
@Test
3435
public void looks_up_value_from_resource_bundle() {
35-
assertEquals("from-bundle", env.get("EnvTest"));
36+
assertEquals("from-bundle", env.get("env.test"));
37+
assertEquals("from-bundle", env.get("ENV_TEST"));
3638
}
3739
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
EnvTest=from-bundle
1+
env.test=from-bundle

jruby/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ These values can be defined in any of the three places:
1616

1717
* In an Environment variable
1818
* In a System property (for example `-DRUBY_VERSION=1.9`
19-
* In a `cucumber-jvm.properties` properties file on your `CLASSPATH`.
19+
* In a `cucumber.properties` properties file on your `CLASSPATH`.
2020

21-
Sample cucumber-jvm.properties file:
21+
Sample `cucumber.properties` file:
2222

2323
```
2424
GEM_PATH=${basedir}/src/test/gems

jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.Set;
3434

3535
public class JRubyBackend implements Backend {
36-
private static final Env env = new Env("cucumber-jvm");
36+
private static final Env env = new Env("cucumber");
3737
private final SnippetGenerator snippetGenerator = new SnippetGenerator(new JRubySnippet());
3838
private final ScriptingContainer jruby = new ScriptingContainer();
3939
private final ResourceLoader resourceLoader;

0 commit comments

Comments
 (0)