Skip to content

Commit 6349c91

Browse files
author
R. Tyler Croy
committed
Refactor the PATH computation to be a bit more testable
1 parent 38e32c1 commit 6349c91

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/main/groovy/com/github/jrubygradle/JRubyExec.groovy

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ class JRubyExec extends JavaExec {
114114
this.jrubyArgs.addAll(args as List)
115115
}
116116

117+
/** Return the computed `PATH` for the task
118+
*
119+
*/
120+
String getComputedPATH(String configuration, String originalPath) {
121+
File path = new File([project.buildDir,
122+
'tmp',
123+
configuration,
124+
'bin'].join(File.separator))
125+
return path.absolutePath + File.pathSeparatorChar + originalPath
126+
}
127+
117128
/** Setting the {@code jruby-complete} version allows for tasks to be run using different versions of JRuby.
118129
* This is useful for comparing the results of different version or running with a gem that is only
119130
* compatible with a specific version or when running a script with a different version that what will
@@ -141,13 +152,9 @@ class JRubyExec extends JavaExec {
141152
GemUtils.OverwriteAction overwrite = project.gradle.startParameter.refreshDependencies ? GemUtils.OverwriteAction.OVERWRITE : GemUtils.OverwriteAction.SKIP
142153
def jrubyCompletePath = project.configurations.getByName(jrubyConfigurationName)
143154
File gemDir = tmpGemDir()
144-
File path = new File([project.buildDir,
145-
'tmp',
146-
configuration,
147-
'bin'].join(File.separator))
148155
gemDir.mkdirs()
149156
environment 'GEM_HOME' : gemDir,
150-
'PATH' : path.absolutePath + File.pathSeparatorChar + environment.PATH
157+
'PATH' : getComputedPATH(configuration, System.env.PATH)
151158

152159
if (configuration != null) {
153160
GemUtils.extractGems(

src/test/groovy/com/github/jrubygradle/JRubyExecSpec.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,16 @@ class JRubyExecSpec extends Specification {
164164
thrown(InvalidUserDataException)
165165
}
166166

167+
def "Properly set the PATH in the Exec envirionment"() {
168+
given:
169+
project.configurations.maybeCreate('foo')
170+
171+
when:
172+
project.configure(execTask) {
173+
configuration 'foo'
174+
}
175+
176+
then:
177+
execTask.getComputedPATH('foo', System.env.PATH).contains('foo')
178+
}
167179
}

0 commit comments

Comments
 (0)