Skip to content

Commit b550f55

Browse files
committed
Fixes #293, environment variables not passed on to javaexec, and method missing errors for some invocations of environment
1 parent 97898e2 commit b550f55

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

jruby-gradle-base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyExecExtensionIntegrationSpec.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,30 @@ class JRubyExecExtensionIntegrationSpec extends Specification {
138138
new File(project.buildDir, customGemDir).exists()
139139

140140
}
141+
142+
def "Running a script that requires environment variables"() {
143+
// This tests that the passthrough invocation
144+
// happens for overloaded versions of environment
145+
// and that the environment variables are passed
146+
// on to the script
147+
given:
148+
final String envVarName = 'TEST_ENV_VAR'
149+
final String envVarValue = 'Test Value'
150+
final Map envVarMap = [TEST_A: 'A123', TEST_B: 'B123']
151+
152+
when:
153+
project.with {
154+
jrubyexec {
155+
environment envVarName, envVarValue
156+
environment envVarMap
157+
script "${TEST_SCRIPT_DIR}/envVars.rb"
158+
standardOutput output
159+
}
160+
}
161+
162+
then:
163+
outputBuffer =~ /TEST_ENV_VAR=Test Value/
164+
outputBuffer =~ /TEST_A=A123/
165+
outputBuffer =~ /TEST_B=B123/
166+
}
141167
}

jruby-gradle-base-plugin/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class JRubyExecDelegate implements JRubyExecTraits {
7070
proxy.passthrough.each { item ->
7171
Object k = item.keySet()[0]
7272
Object v = item.values()[0]
73-
"${k}" v
73+
invokeMethod("${k}", v)
7474
}
7575
main 'org.jruby.Main'
7676
// just keep this even if it does not exists
@@ -81,7 +81,14 @@ class JRubyExecDelegate implements JRubyExecTraits {
8181
args item.toString()
8282
}
8383

84-
setEnvironment proxy.getPreparedEnvironment(System.env)
84+
// Start with System.env then add from environment,
85+
// which will add the user settings and
86+
// overwrite any overlapping entries
87+
final env = [:]
88+
env << System.env
89+
env << environment
90+
91+
setEnvironment proxy.getPreparedEnvironment(env)
8592
}
8693
}
8794

jruby-gradle-base-plugin/src/test/groovy/com/github/jrubygradle/internal/JRubyExecDelegateSpec.groovy

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class JRubyExecDelegateSpec extends Specification {
7676
def "When just passing arbitrary javaexec, expect them to be stored"() {
7777
given:
7878
def cl = {
79+
environment 'XYZ', '123'
7980
executable '/path/to/file'
8081
jvmArgs '-x'
8182
jvmArgs '-y','-z'
@@ -84,12 +85,14 @@ class JRubyExecDelegateSpec extends Specification {
8485
cl.call()
8586

8687
expect:
87-
jred.valuesAt(0) == '/path/to/file'
88-
jred.valuesAt(1) == '-x'
89-
jred.valuesAt(2) == ['-y','-z']
90-
jred.keyAt(0) == 'executable'
91-
jred.keyAt(1) == 'jvmArgs'
88+
jred.valuesAt(0) == ['XYZ', '123']
89+
jred.valuesAt(1) == '/path/to/file'
90+
jred.valuesAt(2) == '-x'
91+
jred.valuesAt(3) == ['-y','-z']
92+
jred.keyAt(0) == 'environment'
93+
jred.keyAt(1) == 'executable'
9294
jred.keyAt(2) == 'jvmArgs'
95+
jred.keyAt(3) == 'jvmArgs'
9396

9497
}
9598

0 commit comments

Comments
 (0)