Skip to content

Commit b781452

Browse files
committed
Fixed failing unittests for project.jrubyexec. Updated README.
1 parent 49fe463 commit b781452

File tree

4 files changed

+72
-32
lines changed

4 files changed

+72
-32
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,27 @@ class JRubyExec extends JavaExec {
169169
*/
170170
@Override
171171
List<String> getArgs() {
172-
def cmdArgs = []
173-
174-
boolean useBinPath = jrubyArgs.contains('-S')
175-
cmdArgs.addAll(jrubyArgs)
176-
177-
if(script!=null && !useBinPath) {
178-
if(!script.exists()) {
179-
throw new InvalidUserDataException("${script} does not exist")
180-
}
181-
cmdArgs.add(script.absolutePath)
182-
} else if(script!=null && useBinPath ) {
183-
if(script.isAbsolute() && !script.exists()) {
184-
throw new InvalidUserDataException("${script} does not exist")
185-
}
186-
cmdArgs.add(script.toString())
187-
} else if(script==null && jrubyArgs.size() == 0 ) {
188-
throw new InvalidUserDataException('Cannot instantiate a JRubyExec instance without either `script` or `jrubyArgs` set')
189-
}
190-
cmdArgs.addAll(scriptArgs)
191-
cmdArgs as List<String>
172+
JRubyExecUtils.buildArgs(jrubyArgs,script,scriptArgs)
173+
// def cmdArgs = []
174+
//
175+
// boolean useBinPath = jrubyArgs.contains('-S')
176+
// cmdArgs.addAll(jrubyArgs)
177+
//
178+
// if(script!=null && !useBinPath) {
179+
// if(!script.exists()) {
180+
// throw new InvalidUserDataException("${script} does not exist")
181+
// }
182+
// cmdArgs.add(script.absolutePath)
183+
// } else if(script!=null && useBinPath ) {
184+
// if(script.isAbsolute() && !script.exists()) {
185+
// throw new InvalidUserDataException("${script} does not exist")
186+
// }
187+
// cmdArgs.add(script.toString())
188+
// } else if(script==null && jrubyArgs.size() == 0 ) {
189+
// throw new InvalidUserDataException('Cannot instantiate a JRubyExec instance without either `script` or `jrubyArgs` set')
190+
// }
191+
// cmdArgs.addAll(scriptArgs)
192+
// cmdArgs as List<String>
192193
}
193194

194195
@Override

src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ class JRubyExecDelegate {
7777
/** buildArgs creates a list of arguments to pass to the JVM
7878
*/
7979
List<String> buildArgs() {
80-
def cmdArgs = []
81-
cmdArgs.addAll(jrubyArgs)
82-
cmdArgs.add(script.absolutePath)
83-
cmdArgs.addAll(scriptArgs)
84-
cmdArgs as List<String>
80+
JRubyExecUtils.buildArgs(jrubyArgs,script,scriptArgs)
8581
}
8682

8783
@PackageScope
@@ -117,7 +113,6 @@ class JRubyExecDelegate {
117113
cl2.delegate = proxy
118114
cl2.call()
119115

120-
proxy.validate()
121116
File gemDir=new File(project.jruby.gemInstallDir)
122117
Configuration config = project.configurations.getByName(JRUBYEXEC_CONFIG)
123118
GemUtils.OverwriteAction overwrite = project.gradle.startParameter.refreshDependencies ? GemUtils.OverwriteAction.OVERWRITE : GemUtils.OverwriteAction.SKIP

src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.github.jrubygradle.internal
22

3+
import groovy.transform.CompileStatic
4+
import org.gradle.api.InvalidUserDataException
35
import org.gradle.api.artifacts.Configuration
46
import org.gradle.api.file.FileCollection
57

68
/**
79
* @author Schalk W. Cronjé.
810
*/
11+
@CompileStatic
912
class JRubyExecUtils {
1013

1114
/** Extract a list of files from a configuration that is suitable for a jruby classpath
@@ -32,7 +35,29 @@ class JRubyExecUtils {
3235
* @return Returns the classpath as a File or null if the jar was not found
3336
*/
3437
static FileCollection jrubyJar(FileCollection fc) {
35-
fc.filter { File f -> it.name.startsWith('jruby-complete-') }
38+
fc.filter { File f -> f.name.startsWith('jruby-complete-') }
3639
}
3740

41+
static List<String> buildArgs( List<Object> jrubyArgs, File script, List<Object> scriptArgs ) {
42+
def cmdArgs = []
43+
44+
boolean useBinPath = jrubyArgs.contains('-S')
45+
cmdArgs.addAll(jrubyArgs)
46+
47+
if(script!=null && !useBinPath) {
48+
if(!script.exists()) {
49+
throw new InvalidUserDataException("${script} does not exist")
50+
}
51+
cmdArgs.add(script.absolutePath)
52+
} else if(script!=null && useBinPath ) {
53+
if(script.isAbsolute() && !script.exists()) {
54+
throw new InvalidUserDataException("${script} does not exist")
55+
}
56+
cmdArgs.add(script.toString())
57+
} else if(script==null && jrubyArgs.size() == 0 ) {
58+
throw new InvalidUserDataException('Cannot instantiate a JRubyExec instance without either `script` or `jrubyArgs` set')
59+
}
60+
cmdArgs.addAll(scriptArgs)
61+
cmdArgs as List<String>
62+
}
3863
}

src/test/groovy/com/github/jrubygradle/internal/JRubyExecDelegateSpec.groovy

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import spock.lang.IgnoreIf
66
import spock.lang.Specification
77

88
import static org.gradle.api.logging.LogLevel.LIFECYCLE
9+
import org.gradle.api.InvalidUserDataException
910

1011
// ===============================================
1112
// *** DO NOT CAll jrubyexec IN THIS UNITTEST ***
@@ -33,8 +34,8 @@ class JRubyExecDelegateSpec extends Specification {
3334
def "When just passing script, scriptArgs, jrubyArgs, expect local properties to be updated"() {
3435
given:
3536
def cl = {
36-
script '/path/to/file'
37-
jrubyArgs 'c','d'
37+
script 'path/to/file'
38+
jrubyArgs 'c','d','-S'
3839
scriptArgs '-x'
3940
scriptArgs '-y','-z'
4041
jrubyArgs 'a','b'
@@ -44,10 +45,28 @@ class JRubyExecDelegateSpec extends Specification {
4445

4546
expect:
4647
jred.passthrough.size() == 0
47-
jred.script == '/path/to/file'
48+
jred.script == 'path/to/file'
4849
jred.scriptArgs == ['-x','-y','-z']
49-
jred.jrubyArgs == ['c','d','a','b']
50-
jred.buildArgs() == ['c','d','a','b','/path/to/file','-x','-y','-z']
50+
jred.jrubyArgs == ['c','d','-S','a','b']
51+
jred.buildArgs() == ['c','d','-S','a','b','path/to/file','-x','-y','-z']
52+
}
53+
54+
def "When passing absolute file and absolute file, expect check for existence to be executed"() {
55+
given:
56+
def cl = {
57+
script '/path/to/file'
58+
jrubyArgs 'c','d','-S'
59+
scriptArgs '-x'
60+
scriptArgs '-y','-z'
61+
jrubyArgs 'a','b'
62+
}
63+
cl.delegate = jred
64+
cl.call()
65+
when:
66+
jred.buildArgs()
67+
68+
then:
69+
thrown(InvalidUserDataException)
5170
}
5271

5372
def "When just passing arbitrary javaexec, expect them to be stored"() {

0 commit comments

Comments
 (0)