Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 04d4ba55f64a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 869a3218ab64
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Apr 26, 2015

  1. Added uri:classloader handling to RubyInstanceConfig.getScriptSource.…

    … This is to support Warbler's runnable feature
    jkutner committed Apr 26, 2015
    3
    Copy the full SHA
    208abc2 View commit details
  2. Merge pull request #2876 from jkutner/master

    Added uri:classloader handling to RubyInstanceConfig.getScriptSource.
    mkristian committed Apr 26, 2015
    Copy the full SHA
    869a321 View commit details
Showing with 29 additions and 21 deletions.
  1. +6 −1 core/src/main/java/org/jruby/RubyInstanceConfig.java
  2. +23 −20 core/src/main/java/org/jruby/util/URLResource.java
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@
import org.jruby.util.KCode;
import org.jruby.util.NormalizedFile;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.URLResource;
import org.jruby.util.FileResource;
import org.jruby.util.cli.ArgumentProcessor;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;
@@ -391,6 +393,9 @@ public InputStream getScriptSource() {
stream = new URL("jar:" + script).openStream();
} else if (script.startsWith("classpath:")) {
stream = getScriptSourceFromJar(script);
} else if (script.startsWith("uri:classloader:")) {
FileResource urlResource = URLResource.create(loader, script);
stream = urlResource.inputStream();
} else {
File file = JRubyFile.create(getCurrentDirectory(), getScriptFileName());
if (isXFlag()) {
@@ -1405,7 +1410,7 @@ public String getProfilingService() {
public void setProfilingService( String service ) {
this.profilingService = service;
}

private static ClassLoader setupLoader() {
ClassLoader loader = RubyInstanceConfig.class.getClassLoader();

43 changes: 23 additions & 20 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -40,11 +40,11 @@ public class URLResource extends AbstractFileResource {
URLResource(String uri, URL url, String[] files) {
this(uri, url, null, null, files);
}

URLResource(String uri, ClassLoader cl, String pathname, String[] files) {
this(uri, null, cl, pathname, files);
}

private URLResource(String uri, URL url, ClassLoader cl, String pathname, String[] files) {
this.uri = uri;
this.list = files;
@@ -53,7 +53,7 @@ private URLResource(String uri, URL url, ClassLoader cl, String pathname, String
this.pathname = pathname;
this.fileStat = new JarFileStat(this);
}

@Override
public String absolutePath()
{
@@ -129,7 +129,7 @@ public FileStat stat() {
public FileStat lstat() {
return stat(); // URLs don't have symbolic links, so lstat == stat
}

@Override
public JRubyFile hackyGetJRubyFile() {
return JRubyNonExistentFile.NOT_EXIST;
@@ -149,20 +149,23 @@ public Channel openChannel( ModeFlags flags, int perm ) throws ResourceException
return Channels.newChannel(inputStream());
}

public static FileResource create(ClassLoader cl, String pathname) {
try
{
pathname = new URI(pathname.replaceFirst("^/*", "/")).normalize().getPath().replaceAll("^/([.][.]/)*", "");
} catch (URISyntaxException e) {
pathname = pathname.replaceAll("^[.]?/*", "");
}
URL url = cl.getResource(pathname);
String[] files = listClassLoaderFiles(cl, pathname);
return new URLResource(URI_CLASSLOADER + pathname,
cl,
url == null ? null : pathname,
files);
}

public static FileResource createClassloaderURI(Ruby runtime, String pathname) {
ClassLoader cl = runtime.getJRubyClassLoader();
try
{
pathname = new URI(pathname.replaceFirst("^/*", "/")).normalize().getPath().replaceAll("^/([.][.]/)*", "");
} catch (URISyntaxException e) {
pathname = pathname.replaceAll("^[.]?/*", "");
}
URL url = cl.getResource(pathname);
String[] files = listClassLoaderFiles(cl, pathname);
return new URLResource(URI_CLASSLOADER + pathname,
cl,
url == null ? null : pathname,
files);
return create(runtime.getJRubyClassLoader(), pathname);
}

public static FileResource create(Ruby runtime, String pathname)
@@ -176,7 +179,7 @@ public static FileResource create(Ruby runtime, String pathname)
}
return createRegularURI(pathname);
}

private static FileResource createRegularURI(String pathname) {
URL url;
try
@@ -185,7 +188,7 @@ private static FileResource createRegularURI(String pathname) {
// and make file:/a protocol to be file:///a so the second replace does not apply
pathname = pathname.replaceFirst( "file:/([^/])", "file:///$1" );
pathname = pathname.replaceFirst( ":/([^/])", "://$1" );

url = new URL(pathname);
// we do not want to deal with those url here like this though they are valid url/uri
if (url.getProtocol().startsWith("http")){
@@ -311,5 +314,5 @@ public static URL getResourceURL(Ruby runtime, String location)
throw new RuntimeException("BUG in " + URLResource.class);
}
}

}