JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-5073

Unable to run scripts using -S if they aren't in the primary jruby.jar

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: JRuby 1.5.2
    • Fix Version/s: None
    • Component/s: Miscellaneous
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      0

      Description

      I am attempting to create a gem called Jarbler. One of my goals is to make it very simple to take Gemfile's and set them up to be embedded in a jar.

      Unfortunately, the "-S script" command line doesn't want to let me run my commands. Even trying Nick Sieger's Gem in a Jar fails.

      After reviewing the code, I thought putting them in my own jar, in the path: /META-INF/jruby.home/bin would solve the problem, however jruby.home is resolved down to a jar:// style path for the primary jar.

      I have modified the RubyInstanceConfig to stop trying to be smart and to just use classpath:/META-INF/jruby.home/ when nothing is configured.

      All tests pass. The issue is resolved.

      Changeset: http://github.com/ericanderson/jruby/commit/523da7926974b32263bbc26b5402cddac56c8eca

        Activity

        Hide
        Hiro Asari added a comment -

        Eric, could you add a test case, please?

        Show
        Hiro Asari added a comment - Eric, could you add a test case, please?
        Hide
        Eric Anderson added a comment -

        Sure, I will provide two tests:

        1. Ensure that the existing scripts that jruby bundles are still executable
        2. Ensure that other scripts on the classpath (separate jar) are executable as well
        Show
        Eric Anderson added a comment - Sure, I will provide two tests: Ensure that the existing scripts that jruby bundles are still executable Ensure that other scripts on the classpath (separate jar) are executable as well
        Hide
        Eric Anderson added a comment -

        The test code for this project has me very lost. Perhaps you could point me in the general direction for where I would add this test?

        Show
        Eric Anderson added a comment - The test code for this project has me very lost. Perhaps you could point me in the general direction for where I would add this test?
        Hide
        Hiro Asari added a comment -

        Eric,

        if (true) return "classpath:/META-INF/jruby.home";
        

        This makes little sense, since there is code following this line.

        So, for brevity, it would look something like:

        diff --git a/src/org/jruby/RubyInstanceConfig.java b/src/org/jruby/RubyInstanceConfig.java
        index 5445ca6..7527e6a 100644
        --- a/src/org/jruby/RubyInstanceConfig.java
        +++ b/src/org/jruby/RubyInstanceConfig.java
        @@ -819,27 +819,7 @@ public class RubyInstanceConfig {
                         // verify it if it's there
                         jrubyHome = verifyHome(jrubyHome);
                     } else {
        -                try {
        -                    // try loading from classloader resources
        -                    URI jrubyHomeURI = getClass().getResource("/META-INF/jruby.home").toURI();
        -                    String scheme = jrubyHomeURI.getScheme();
        -                    String path = jrubyHomeURI.getSchemeSpecificPart();
        -                    if ("jar".equals(scheme) && path.startsWith("file:")) {
        -                        // special case for jar:file (most typical case)
        -                        jrubyHome = path;
        -                    } else {
        -                        jrubyHome = "classpath:/META-INF/jruby.home";
        -                        return jrubyHome;
        -                    }
        -                } catch (Exception e) {}
        -
        -                if (jrubyHome != null) {
        -                    // verify it if it's there
        -                    jrubyHome = verifyHome(jrubyHome);
        -                } else {
        -                    // otherwise fall back on system temp location
        -                    jrubyHome = SafePropertyAccessor.getProperty("java.io.tmpdir");
        -                }
        +                return "classpath:/META-INF/jruby.home";
                     }
                 }
                 return jrubyHome;
        

        However…

        The case that apparently gets dropped with your patch is on line 829, when the scheme is jar and the path starts with file:. How does that work?

        Show
        Hiro Asari added a comment - Eric, if (true) return "classpath:/META-INF/jruby.home"; This makes little sense, since there is code following this line. So, for brevity, it would look something like: diff --git a/src/org/jruby/RubyInstanceConfig.java b/src/org/jruby/RubyInstanceConfig.java index 5445ca6..7527e6a 100644 --- a/src/org/jruby/RubyInstanceConfig.java +++ b/src/org/jruby/RubyInstanceConfig.java @@ -819,27 +819,7 @@ public class RubyInstanceConfig { // verify it if it's there jrubyHome = verifyHome(jrubyHome); } else { - try { - // try loading from classloader resources - URI jrubyHomeURI = getClass().getResource("/META-INF/jruby.home").toURI(); - String scheme = jrubyHomeURI.getScheme(); - String path = jrubyHomeURI.getSchemeSpecificPart(); - if ("jar".equals(scheme) && path.startsWith("file:")) { - // special case for jar:file (most typical case) - jrubyHome = path; - } else { - jrubyHome = "classpath:/META-INF/jruby.home"; - return jrubyHome; - } - } catch (Exception e) {} - - if (jrubyHome != null) { - // verify it if it's there - jrubyHome = verifyHome(jrubyHome); - } else { - // otherwise fall back on system temp location - jrubyHome = SafePropertyAccessor.getProperty("java.io.tmpdir"); - } + return "classpath:/META-INF/jruby.home"; } } return jrubyHome; However… The case that apparently gets dropped with your patch is on line 829, when the scheme is jar and the path starts with file: . How does that work?
        Hide
        Charles Oliver Nutter added a comment -

        Eric: Thanks for looking into this! Can you answer Hiro's question above, so we can try to get your patch incorporated?

        Show
        Charles Oliver Nutter added a comment - Eric: Thanks for looking into this! Can you answer Hiro's question above, so we can try to get your patch incorporated?
        Hide
        Eric Anderson added a comment -

        Yup.

        So, the if statement was just to short java's compiler while I made sure my change worked.

        Basically, you don't need to search into the exact jar to get a URL for the script you're looking for. jrubyHome can just be that location in the classpath.

        Show
        Eric Anderson added a comment - Yup. So, the if statement was just to short java's compiler while I made sure my change worked. Basically, you don't need to search into the exact jar to get a URL for the script you're looking for. jrubyHome can just be that location in the classpath.
        Hide
        Charles Oliver Nutter added a comment -

        So I believe we need to keep the code and drop the "if (true)", since Eric was just using it to test his fixes. I'm for rolling it into 1.5.4 (and master, of course).

        Show
        Charles Oliver Nutter added a comment - So I believe we need to keep the code and drop the "if (true)", since Eric was just using it to test his fixes. I'm for rolling it into 1.5.4 (and master, of course).
        Hide
        Charles Oliver Nutter added a comment -

        So here's the patch I came up with. Eliminates the "cleverness" and goes straight to classpath: URL if there's no jruby home set. Ideally "classpath:" URL should cover anything in classpath, so the file/jar stuff isn't needed. Right?

        Not sure if there's something I'm breaking with this...

        https://gist.github.com/663018

        Show
        Charles Oliver Nutter added a comment - So here's the patch I came up with. Eliminates the "cleverness" and goes straight to classpath: URL if there's no jruby home set. Ideally "classpath:" URL should cover anything in classpath, so the file/jar stuff isn't needed. Right? Not sure if there's something I'm breaking with this... https://gist.github.com/663018
        Hide
        Nick Sieger added a comment -

        It does break the new "test-jar-complete" ant target I made. The pre-installed rake is not found in the complete jar.

        I think we need to keep the existing behavior, but perhaps add some logic to allow -S to be smarter about bin scripts in jars.

        Show
        Nick Sieger added a comment - It does break the new "test-jar-complete" ant target I made. The pre-installed rake is not found in the complete jar. I think we need to keep the existing behavior, but perhaps add some logic to allow -S to be smarter about bin scripts in jars.

          People

          • Assignee:
            Nick Sieger
            Reporter:
            Eric Anderson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: