File tree Expand file tree Collapse file tree 3 files changed +43
-7
lines changed
jruby-gradle-base-plugin/src
integTest/groovy/com/github/jrubygradle
main/groovy/com/github/jrubygradle/internal
test/groovy/com/github/jrubygradle/internal Expand file tree Collapse file tree 3 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -138,4 +138,30 @@ class JRubyExecExtensionIntegrationSpec extends Specification {
138
138
new File (project. buildDir, customGemDir). exists()
139
139
140
140
}
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
+ }
141
167
}
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ class JRubyExecDelegate implements JRubyExecTraits {
70
70
proxy. passthrough. each { item ->
71
71
Object k = item. keySet()[0 ]
72
72
Object v = item. values()[0 ]
73
- " ${ k} " v
73
+ invokeMethod( " ${ k} " , v)
74
74
}
75
75
main ' org.jruby.Main'
76
76
// just keep this even if it does not exists
@@ -81,7 +81,14 @@ class JRubyExecDelegate implements JRubyExecTraits {
81
81
args item. toString()
82
82
}
83
83
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)
85
92
}
86
93
}
87
94
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ class JRubyExecDelegateSpec extends Specification {
76
76
def " When just passing arbitrary javaexec, expect them to be stored" () {
77
77
given :
78
78
def cl = {
79
+ environment ' XYZ' , ' 123'
79
80
executable ' /path/to/file'
80
81
jvmArgs ' -x'
81
82
jvmArgs ' -y' ,' -z'
@@ -84,12 +85,14 @@ class JRubyExecDelegateSpec extends Specification {
84
85
cl. call()
85
86
86
87
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'
92
94
jred. keyAt(2 ) == ' jvmArgs'
95
+ jred. keyAt(3 ) == ' jvmArgs'
93
96
94
97
}
95
98
You can’t perform that action at this time.
0 commit comments