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: 92c0796c53c1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 43051c56cc8b
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Dec 4, 2014

  1. Copy the full SHA
    a46ce8e View commit details
  2. Clean up imports.

    headius committed Dec 4, 2014
    Copy the full SHA
    43051c5 View commit details
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.net.URL;

import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig.CompileMode;
import org.jruby.RubyRuntimeAdapter;
@@ -63,6 +65,7 @@
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.IAccessor;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.LoadService;
import org.jruby.runtime.scope.ManyVarsDynamicScope;

/**
@@ -125,7 +128,14 @@ public EmbedEvalUnit parse(PathType type, String filename, int... lines) {
istream = new FileInputStream(absolutePath);
break;
case CLASSPATH:
istream = container.getProvider().getRuntime().getJRubyClassLoader().getResourceAsStream(filename);
URL loc = container.getProvider().getRuntime().getJRubyClassLoader().getResource(filename);
filename = LoadService.classpathFilenameFromURL(filename, loc, true);
try {
istream = loc.openStream();
} catch (IOException ioe) {
// should not happen
throw new ParseFailedException(ioe);
}
break;
}
return parse(istream, filename, lines);
48 changes: 29 additions & 19 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Original file line number Diff line number Diff line change
@@ -43,9 +43,7 @@
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -68,7 +66,6 @@
import org.jruby.ext.rbconfig.RbConfigLibrary;
import org.jruby.platform.Platform;
import org.jruby.runtime.Block;
import org.jruby.runtime.Constants;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.JRubyFile;
import org.jruby.util.log.Logger;
@@ -1559,7 +1556,7 @@ protected LoadServiceResource findFileInClasspath(String name) {
}

/* Directories and unavailable resources are not able to open a stream. */
protected boolean isRequireable(URL loc) {
protected static boolean isRequireable(URL loc) {
if (loc != null) {
if (loc.getProtocol().equals("file") && new java.io.File(getPath(loc)).isDirectory()) {
return false;
@@ -1619,28 +1616,41 @@ protected LoadServiceResource getClassPathResource(ClassLoader classLoader, Stri
}

if (loc != null) { // got it
String path = "classpath:/" + name;
// special case for typical jar:file URLs, but only if the name didn't have
// the classpath scheme explicitly
if (!isClasspathScheme &&
(loc.getProtocol().equals("jar") || loc.getProtocol().equals("file"))
&& isRequireable(loc)) {
path = getPath(loc);
// On windows file: urls converted to names will return /C:/foo from
// getPath versus C:/foo. Since getPath is used in a million places
// putting the newFile.getPath broke some file with-in Jar loading.
// So I moved it to only this site.
if (Platform.IS_WINDOWS && loc.getProtocol().equals("file")) {
path = new File(path).getPath();
}
}
String path = classpathFilenameFromURL(name, loc, isClasspathScheme);
LoadServiceResource foundResource = new LoadServiceResource(loc, path);
debugLogFound(foundResource);
return foundResource;
}
return null;
}

/**
* Given a URL to a classloader resource, build an appropriate load string.
*
* @param name the original filename requested
* @param loc the URL to the resource
* @param isClasspathScheme whether we're using the classpath: sceheme
* @return
*/
public static String classpathFilenameFromURL(String name, URL loc, boolean isClasspathScheme) {
String path = "classpath:/" + name;
// special case for typical jar:file URLs, but only if the name didn't have
// the classpath scheme explicitly
if (!isClasspathScheme &&
(loc.getProtocol().equals("jar") || loc.getProtocol().equals("file"))
&& isRequireable(loc)) {
path = getPath(loc);
// On windows file: urls converted to names will return /C:/foo from
// getPath versus C:/foo. Since getPath is used in a million places
// putting the newFile.getPath broke some file with-in Jar loading.
// So I moved it to only this site.
if (Platform.IS_WINDOWS && loc.getProtocol().equals("file")) {
path = new File(path).getPath();
}
}
return path;
}

private String expandRelativeJarPath(String path) {
return path.replaceAll("/[^/]+/\\.\\.|[^/]+/\\.\\./|\\./","").replace("^\\\\","/");
}
Original file line number Diff line number Diff line change
@@ -2750,4 +2750,11 @@ public void testExitTerminatesScript() {
Object result = instance.runScriptlet("exit 1234");
assertEquals(1234L, result);
}

@Test
public void testClasspathScriptletHashClasspathFile() {
ScriptingContainer instance = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
Object result = instance.runScriptlet(PathType.CLASSPATH, "__FILE__.rb");
assertEquals("classpath:/__FILE__.rb", result.toString());
}
}