File tree Expand file tree Collapse file tree 4 files changed +45
-7
lines changed
jruby-gradle-base-plugin/src
groovy/com/github/jrubygradle
main/groovy/com/github/jrubygradle/internal
test/groovy/com/github/jrubygradle/internal Expand file tree Collapse file tree 4 files changed +45
-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
1
+ puts ENV . map { |k , v | "#{ k } =#{ v } " } . join ( "\n " )
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ class JRubyExecDelegate implements JRubyExecTraits {
55
55
56
56
private final List passthrough = []
57
57
58
+ @SuppressWarnings (' VariableName' )
58
59
static Object jrubyexecDelegatingClosure = { Project project , Closure cl ->
59
60
JRubyExecDelegate proxy = new JRubyExecDelegate ()
60
61
proxy. project = project
@@ -70,7 +71,7 @@ class JRubyExecDelegate implements JRubyExecTraits {
70
71
proxy. passthrough. each { item ->
71
72
Object k = item. keySet()[0 ]
72
73
Object v = item. values()[0 ]
73
- " ${ k} " v
74
+ invokeMethod( " ${ k} " , v)
74
75
}
75
76
main ' org.jruby.Main'
76
77
// just keep this even if it does not exists
@@ -81,7 +82,14 @@ class JRubyExecDelegate implements JRubyExecTraits {
81
82
args item. toString()
82
83
}
83
84
84
- setEnvironment proxy. getPreparedEnvironment(System . env)
85
+ // Start with System.env then add from environment,
86
+ // which will add the user settings and
87
+ // overwrite any overlapping entries
88
+ final env = [:]
89
+ env << System . env
90
+ env << environment
91
+
92
+ setEnvironment proxy. getPreparedEnvironment(env)
85
93
}
86
94
}
87
95
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