Permalink
Browse files

Merge pull request #130 from akiellor/bin-scripts

Enable running binscripts from classpath.
  • Loading branch information...
2 parents e35a5cf + f0ed17b commit 248afa3bff9ab54fa151f9042725983a4c477332 @nicksieger nicksieger committed Mar 24, 2012
@@ -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();
Binary file not shown.
@@ -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

0 comments on commit 248afa3

Please sign in to comment.