Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the JRubyExec script argument optional provided jrubyArgs is present #63

Merged
merged 1 commit into from
Oct 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/groovy/com/github/jrubygradle/JRubyExec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class JRubyExec extends JavaExec {
/** Script to execute.
*
*/
@InputFile
File script

/** Configuration to copy gems from. If {@code jRubyVersion} has not been set, {@code jRubyExec} will used as
Expand Down Expand Up @@ -158,8 +157,15 @@ class JRubyExec extends JavaExec {
@Override
List<String> getArgs() {
def cmdArgs = []

if ((script == null) && (jrubyArgs.size() == 0)) {
throw new TaskInstantiationException('Cannot instantiate a JRubyExec instance without either `script` or `jrubyArgs` set')
}
cmdArgs.addAll(jrubyArgs)
cmdArgs.add(script.absolutePath)

if (script != null) {
cmdArgs.add(script.absolutePath)
}
cmdArgs.addAll(scriptArgs)
cmdArgs as List<String>
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/groovy/com/github/jrubygradle/JRubyExecSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,24 @@ class JRubyExecSpec extends Specification {
execTask.getArgs() == ['-j1','-j2','-j3',new File(TEST_SCRIPT_DIR,'helloWorld.rb').absolutePath,'-s1','-s2','-s3']
}

def "Properly handle the lack of a `script` argument"() {
when:
project.configure(execTask) {
jrubyArgs '-S', 'rspec'
}

then:
execTask.getArgs() == ['-S', 'rspec']
}

def "Error when `script` is empty and there is no `jrubyArgs`"() {
when:
project.configure(execTask) {
}
execTask.getArgs()

then: "An exception should be thrown"
thrown(TaskInstantiationException)
}

}