Skip to content

Commit a993097

Browse files
author
R. Tyler Croy
committed
Merge pull request #72 from rtyler/jrubyexec-path-fixes
Jrubyexec path fixes
2 parents 77e8ac8 + 6349c91 commit a993097

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ apply from: 'gradle/integration-tests.gradle'
1414

1515

1616
group = 'com.github.jruby-gradle'
17-
version = '0.1.3'
17+
version = '0.1.4'
1818
archivesBaseName = 'jruby-gradle-plugin'
1919

2020
if (System.env.RELEASE != '1') {

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class JRubyExec extends JavaExec {
3030
}
3131

3232
proj.tasks.withType(JRubyExec) { t ->
33-
if(t.jrubyConfigurationName != proj.configurations.jrubyExec) {
34-
proj.dependencies.add(t.jrubyConfigurationName,"org.jruby:jruby-complete:${t.jrubyVersion}")
33+
if (t.jrubyConfigurationName != proj.configurations.jrubyExec) {
34+
proj.dependencies.add(t.jrubyConfigurationName,
35+
"org.jruby:jruby-complete:${t.jrubyVersion}")
3536
}
3637
}
3738
}
@@ -78,16 +79,18 @@ class JRubyExec extends JavaExec {
7879
script=fName
7980
break
8081
case String:
81-
script=new File(fName)
82+
script = new File(fName)
8283
break
8384
default:
84-
script=new File(fName.toString())
85+
script = new File(fName.toString())
8586
}
8687
}
8788

8889
/** Returns a list of script arguments
8990
*/
90-
List<String> scriptArgs() {CollectionUtils.stringize(this.scriptArgs)}
91+
List<String> scriptArgs() {
92+
CollectionUtils.stringize(this.scriptArgs)
93+
}
9194

9295
/** Set arguments for script
9396
*
@@ -99,7 +102,9 @@ class JRubyExec extends JavaExec {
99102

100103
/** Returns a list of jruby arguments
101104
*/
102-
List<String> jrubyArgs() {CollectionUtils.stringize(this.jrubyArgs)}
105+
List<String> jrubyArgs() {
106+
CollectionUtils.stringize(this.jrubyArgs)
107+
}
103108

104109
/** Set arguments for jruby
105110
*
@@ -109,6 +114,17 @@ class JRubyExec extends JavaExec {
109114
this.jrubyArgs.addAll(args as List)
110115
}
111116

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+
112128
/** Setting the {@code jruby-complete} version allows for tasks to be run using different versions of JRuby.
113129
* This is useful for comparing the results of different version or running with a gem that is only
114130
* compatible with a specific version or when running a script with a different version that what will
@@ -117,7 +133,7 @@ class JRubyExec extends JavaExec {
117133
* @param version String in the form '1.7.13'
118134
*/
119135
void setJrubyVersion(final String version) {
120-
if(version == project.jruby.execVersion) {
136+
if (version == project.jruby.execVersion) {
121137
jrubyConfigurationName = JRUBYEXEC_CONFIG
122138
} else {
123139
final String cfgName= 'jrubyExec$$' + name
@@ -129,17 +145,18 @@ class JRubyExec extends JavaExec {
129145

130146
@Override
131147
void exec() {
132-
if(configuration == null && jrubyConfigurationName == JRUBYEXEC_CONFIG) {
148+
if (configuration == null && jrubyConfigurationName == JRUBYEXEC_CONFIG) {
133149
configuration = JRUBYEXEC_CONFIG
134150
}
135151

136152
GemUtils.OverwriteAction overwrite = project.gradle.startParameter.refreshDependencies ? GemUtils.OverwriteAction.OVERWRITE : GemUtils.OverwriteAction.SKIP
137153
def jrubyCompletePath = project.configurations.getByName(jrubyConfigurationName)
138154
File gemDir = tmpGemDir()
139155
gemDir.mkdirs()
140-
environment 'GEM_HOME' : gemDir
156+
environment 'GEM_HOME' : gemDir,
157+
'PATH' : getComputedPATH(configuration, System.env.PATH)
141158

142-
if(configuration != null) {
159+
if (configuration != null) {
143160
GemUtils.extractGems(
144161
project,
145162
jrubyCompletePath,
@@ -174,7 +191,7 @@ class JRubyExec extends JavaExec {
174191

175192
@Override
176193
JavaExec setMain(final String mainClassName) {
177-
if(mainClassName == 'org.jruby.Main') {
194+
if (mainClassName == 'org.jruby.Main') {
178195
super.setMain(mainClassName)
179196
} else {
180197
throw notAllowed("Setting main class for jruby to ${mainClassName} is not a valid operation")
@@ -208,7 +225,7 @@ class JRubyExec extends JavaExec {
208225

209226
private File tmpGemDir() {
210227
String ext = FileUtils.toSafeFileName(jrubyConfigurationName)
211-
if(configuration && configuration!=jrubyConfigurationName) {
228+
if (configuration && configuration != jrubyConfigurationName) {
212229
ext= ext + "-${FileUtils.toSafeFileName(configuration)}"
213230
}
214231
new File( project.buildDir, "tmp/${ext}").absoluteFile

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)