From f0ed17b76ca6b2f375c9157bbb9ffd97582e5232 Mon Sep 17 00:00:00 2001 From: Andrew Kiellor Date: Sun, 18 Mar 2012 18:58:48 -0700 Subject: [PATCH] Enable running binscripts from classpath. --- src/org/jruby/util/cli/ArgumentProcessor.java | 15 ++++++++++----- test/dir with spaces/testgem.jar | Bin 2875 -> 4167 bytes test/test_jar_complete.rb | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/org/jruby/util/cli/ArgumentProcessor.java b/src/org/jruby/util/cli/ArgumentProcessor.java index f47d3e58f6d..2af19cec6e9 100644 --- a/src/org/jruby/util/cli/ArgumentProcessor.java +++ b/src/org/jruby/util/cli/ArgumentProcessor.java @@ -28,18 +28,20 @@ ***** END LICENSE BLOCK *****/ package org.jruby.util.cli; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import org.jruby.CompatVersion; +import org.jruby.Ruby; import org.jruby.RubyInstanceConfig; import org.jruby.exceptions.MainExitException; import org.jruby.util.JRubyFile; import org.jruby.util.KCode; import org.jruby.util.SafePropertyAccessor; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * Encapsulated logic for processing JRuby's command-line arguments. * @@ -496,6 +498,9 @@ private String resolveScript(String scriptName) { } catch (Exception e) { // keep going, try PATH } + if(Ruby.getClassLoader().getResourceAsStream("bin/" + scriptName) != null){ + return "classpath:bin/" + scriptName; + } try { Object pathObj = config.getEnvironment().get("PATH"); String path = pathObj.toString(); diff --git a/test/dir with spaces/testgem.jar b/test/dir with spaces/testgem.jar index 5f212dff57780b585dc9be2fac40b80419775cb4..728de2fe759e37314ab194904400fc17731dec61 100644 GIT binary patch literal 4167 zcmcImdpy&7AD_!qZV@GgLnN1N#+Z~O4xV95Gfqm*%q%qIT1`AU9629L zxRld65`}qIIF86V)k(KWu_(#&`!=1S02jO4;4TKh!&ZuM$K?o-YG|$ZG;$#)&{g zn2^=&fltAuDGY(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%Y?Da;R?B<7{KBXXi+~a?`Sf zk%8eYFq#6q8JR>FP$L)?d!PtL1t`&tt`#XRfCeH1TObFfbz&wD8%QS?!{mvqVlF`c zAc5ULHY@@W?gB+2QbaL`Bk5pZxDSp{Br|1DT^$7Ef}#{|sf0AL{t}=xIFjM=Vgka* z3K*udfMOfT0s&M9oB+!kKvDy$tC6Ez5yjBIU`>;OsY4q%96?@1ifRTa6iufm$McF! z1||(8$7q340s=?_0~8}&Kpi#t0>3DVY7aJWx)2NSW(CIs4=@|B19O8MI1>W^sFtm< diff --git a/test/test_jar_complete.rb b/test/test_jar_complete.rb index 409930a0c2d..5a7beb9d8bb 100644 --- a/test/test_jar_complete.rb +++ b/test/test_jar_complete.rb @@ -111,4 +111,10 @@ def test_script_with__FILE__constant_in_jar_with_spaces output = jruby_complete(complete_jar, %{-e "require '_file_constant_'"}).chomp assert output =~ /#{tmp}/, "'#{output}' does not match '#{tmp}'" end + + def test_binscripts_can_be_run_from_classpath + output = `java -cp \"#{COMPLETE_JAR}:test/dir with spaces/testgem.jar\" org.jruby.Main -S testgem` + + assert output == "Testing... 1.. 2.. 3..\n" + end end