Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for JRUBY-4825: __FILE__ is not expanded when it is used from wit…

…hin a a compiled ruby script used as the main class of an executable jar
  • Loading branch information...
commit 2b166c98a430fc1b25988179ed0a06d79b4dd080 1 parent ff530c4
@headius headius authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 src/org/jruby/compiler/impl/StandardASMCompiler.java
View
11 src/org/jruby/compiler/impl/StandardASMCompiler.java
@@ -37,6 +37,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -65,6 +66,7 @@
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
import org.objectweb.asm.util.CheckClassAdapter;
import org.objectweb.asm.util.TraceClassVisitor;
@@ -479,6 +481,15 @@ public void endScript(boolean generateLoad, boolean generateMain) {
method.dup();
method.invokespecial(getClassname(), "<init>", sig(Void.TYPE));
+ // set filename for the loaded script class (JRUBY-4825)
+ method.dup();
+ method.ldc(Type.getType("L" + getClassname() + ";"));
+ method.invokevirtual(p(Class.class), "getClassLoader", sig(ClassLoader.class));
+ method.ldc(getClassname() + ".class");
+ method.invokevirtual(p(ClassLoader.class), "getResource", sig(URL.class, String.class));
+ method.invokevirtual(p(Object.class), "toString", sig(String.class));
+ method.invokevirtual(p(AbstractScript.class), "setFilename", sig(void.class, String.class));
+
// instance config for the script run
method.newobj(p(RubyInstanceConfig.class));
method.dup();
Please sign in to comment.
Something went wrong with that request. Please try again.