Skip to content

Commit

Permalink
Showing 181 changed files with 1,290 additions and 1,174 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -394,7 +394,7 @@ public InputStream getScriptSource() {
} else if (script.startsWith("classpath:")) {
stream = getScriptSourceFromJar(script);
} else if (script.startsWith("uri:classloader:")) {
FileResource urlResource = URLResource.create(loader, script);
FileResource urlResource = URLResource.create(loader, script, true);
stream = urlResource.inputStream();
} else {
File file = JRubyFile.create(getCurrentDirectory(), getScriptFileName());
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ private FoundLibrary findFileResourceWithLoadPath(String searchName, String suff
String pathWithSuffix = fullPath + suffix;

DebugLog.Resource.logTry(pathWithSuffix);
FileResource resource = JRubyFile.createResource(runtime, pathWithSuffix);
FileResource resource = JRubyFile.createResourceAsFile(runtime, pathWithSuffix);
if (resource.exists()) {
DebugLog.Resource.logFound(pathWithSuffix);
String scriptName = resolveScriptName(resource, pathWithSuffix);
12 changes: 10 additions & 2 deletions core/src/main/java/org/jruby/util/JRubyFile.java
Original file line number Diff line number Diff line change
@@ -63,11 +63,19 @@ public static FileResource createResource(ThreadContext context, String pathname
return createResource(context.runtime, pathname);
}

public static FileResource createResourceAsFile(Ruby runtime, String pathname) {
return createResource(runtime, runtime.getCurrentDirectory(), pathname, true);
}

public static FileResource createResource(Ruby runtime, String pathname) {
return createResource(runtime, runtime.getCurrentDirectory(), pathname);
return createResource(runtime, runtime.getCurrentDirectory(), pathname, false);
}

public static FileResource createResource(Ruby runtime, String cwd, String pathname) {
return createResource(runtime, cwd, pathname, false);
}

private static FileResource createResource(Ruby runtime, String cwd, String pathname, boolean isFile) {
FileResource emptyResource = EmptyFileResource.create(pathname);
if (emptyResource != null) return emptyResource;

@@ -87,7 +95,7 @@ public static FileResource createResource(Ruby runtime, String cwd, String pathn
}

// replace is needed for maven/jruby-complete/src/it/app_using_classpath_uri to work
if (pathname.startsWith("uri:")) return URLResource.create(runtime, pathname);
if (pathname.startsWith("uri:")) return URLResource.create(runtime, pathname, isFile);

if (pathname.startsWith("file:")) {
pathname = pathname.substring(5);
26 changes: 10 additions & 16 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -149,38 +149,38 @@ public Channel openChannel( ModeFlags flags, int perm ) throws ResourceException
return Channels.newChannel(inputStream());
}

public static FileResource create(ClassLoader cl, String pathname) {
public static FileResource create(ClassLoader cl, String pathname, boolean isFile) {
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);
String[] files = isFile ? null : listClassLoaderFiles(cl, pathname);
return new URLResource(URI_CLASSLOADER + pathname,
cl,
url == null ? null : pathname,
files);
}

public static FileResource createClassloaderURI(Ruby runtime, String pathname) {
return create(runtime.getJRubyClassLoader(), pathname);
public static FileResource createClassloaderURI(Ruby runtime, String pathname, boolean isFile) {
return create(runtime.getJRubyClassLoader(), pathname, isFile);
}

public static FileResource create(Ruby runtime, String pathname)
public static FileResource create(Ruby runtime, String pathname, boolean isFile)
{
if (!pathname.startsWith(URI)) {
return null;
}
pathname = pathname.substring(URI.length());
if (pathname.startsWith(CLASSLOADER)) {
return createClassloaderURI(runtime, pathname.substring(CLASSLOADER.length()));
return createClassloaderURI(runtime, pathname.substring(CLASSLOADER.length()), isFile);
}
return createRegularURI(pathname);
return createRegularURI(pathname, isFile);
}

private static FileResource createRegularURI(String pathname) {
private static FileResource createRegularURI(String pathname, boolean isFile) {
URL url;
try
{
@@ -200,7 +200,7 @@ private static FileResource createRegularURI(String pathname) {
// file does not exists
return new URLResource(URI + pathname, (URL)null, null);
}
String[] files = listFiles(pathname);
String[] files = isFile ? null : listFiles(pathname);
if (files != null) {
return new URLResource(URI + pathname, (URL)null, files);
}
@@ -252,12 +252,9 @@ private static String[] listFilesFromInputStream(InputStream is) {
}

private static String[] listClassLoaderFiles(ClassLoader classloader, String pathname) {
if (pathname.endsWith(".rb") || pathname.endsWith(".class") || pathname.endsWith(".jar")) {
return null;
}
try
{
pathname = pathname + (pathname.equals("") ? ".jrubydir" : "/.jrubydir");
pathname += pathname.equals("") ? ".jrubydir" : "/.jrubydir";
Enumeration<URL> urls = classloader.getResources(pathname);
if (!urls.hasMoreElements()) {
return null;
@@ -280,9 +277,6 @@ private static String[] listClassLoaderFiles(ClassLoader classloader, String pat
}

private static String[] listFiles(String pathname) {
if (pathname.endsWith(".rb") || pathname.endsWith(".class") || pathname.endsWith(".jar")) {
return null;
}
try
{
InputStream is = new URL(pathname + "/.jrubydir").openStream();
20 changes: 12 additions & 8 deletions core/src/test/java/org/jruby/util/URLResourceTest.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public class URLResourceTest extends TestCase {

public void testDirectory(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri);
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri, false);

assertNotNull(resource );
assertFalse(resource.isFile());
@@ -22,7 +22,7 @@ public void testDirectory(){

public void testNoneDirectory(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir/dir_without_listing" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri);
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri, false);

assertNotNull(resource );
// you can open streams on file-system directories
@@ -34,7 +34,7 @@ public void testNoneDirectory(){

public void testFile(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir/.jrubydir" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri);
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri, false);

assertNotNull(resource );
// you can open streams on file-system directories
@@ -46,7 +46,7 @@ public void testFile(){

public void testNonExistingFile(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri + "/not_there");
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri + "/not_there", false);

assertNotNull(resource );
assertFalse(resource.isFile());
@@ -57,7 +57,8 @@ public void testNonExistingFile(){

public void testDirectoryClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:classloader:/somedir");
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
"uri:classloader:/somedir", false);

assertNotNull( resource );
assertFalse( resource.isFile() );
@@ -70,7 +71,8 @@ public void testDirectoryClassloader()

public void testNoneDirectoryClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:classloader:/somedir/dir_without_listing");
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
"uri:classloader:/somedir/dir_without_listing", false);

assertNotNull( resource );
// you can open streams on file-system directories
@@ -82,7 +84,8 @@ public void testNoneDirectoryClassloader()

public void testFileClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:classloader:/somedir/.jrubydir" );
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
"uri:classloader:/somedir/.jrubydir", false );

assertNotNull( resource );
// you can open streams on file-system directories
@@ -94,7 +97,8 @@ public void testFileClassloader()

public void testNonExistingFileClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:classloader:/somedir/not_there" );
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
"uri:classloader:/somedir/not_there", false );

assertNotNull( resource );
assertFalse( resource.isFile() );
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/process/getrlimit_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/process/maxgroups_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/pathname/parent_tags.txt

This file was deleted.

12 changes: 12 additions & 0 deletions tool/truffle-findbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -167,4 +167,16 @@
<Bug pattern="BC_UNCONFIRMED_CAST" />
</Match>

<!-- Temporary while we remove RubyBasicObject -->

<Match>
<Class name="~org\.jruby\.truffle\..*" />
<Bug pattern="BC_UNCONFIRMED_CAST" />
</Match>

<Match>
<Class name="~org\.jruby\.truffle\..*" />
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" />
</Match>

</FindBugsFilter>
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@
import org.jruby.truffle.nodes.core.UnboundMethodNodes;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.core.hash.HashNodes;
import org.jruby.truffle.runtime.ThreadLocalObject;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.ThreadLocalObject;
import org.jruby.truffle.runtime.core.*;

public abstract class RubyGuards {
53 changes: 27 additions & 26 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -19,18 +19,15 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;

import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;

import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.instrument.RubyWrapperNode;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.sockets.NativeSockets;
import org.jruby.util.ByteList;
@@ -162,26 +159,18 @@ public RubyString executeRubyString(VirtualFrame frame) throws UnexpectedResultE
}
}

// If you try to make this RubyBasicObject things break in the DSL

public RubyArray executeRubyArray(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

if (value instanceof RubyArray) {
if (RubyGuards.isRubyArray(value)) {
return (RubyArray) value;
} else {
throw new UnexpectedResultException(value);
}
}

public RubyHash executeRubyHash(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

if (value instanceof RubyHash) {
return (RubyHash) value;
} else {
throw new UnexpectedResultException(value);
}
}

public RubyRegexp executeRubyRegexp(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

@@ -212,6 +201,18 @@ public RubyProc executeRubyProc(VirtualFrame frame) throws UnexpectedResultExcep
}
}

// If you try to make this RubyBasicObject things break in the DSL

public RubyHash executeRubyHash(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

if (RubyGuards.isRubyHash(value)) {
return (RubyHash) value;
} else {
throw new UnexpectedResultException(value);
}
}

public RubyBasicObject executeRubyBasicObject(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

@@ -248,47 +249,47 @@ protected RubyBasicObject nil() {
return getContext().getCoreLibrary().getNilObject();
}

protected RubyString createEmptyString() {
protected RubyBasicObject createEmptyString() {
return StringNodes.createEmptyString(getContext().getCoreLibrary().getStringClass());
}

protected RubyString createString(String string) {
protected RubyBasicObject createString(String string) {
return StringNodes.createString(getContext().getCoreLibrary().getStringClass(), string);
}

protected RubyString createString(String string, Encoding encoding) {
protected RubyBasicObject createString(String string, Encoding encoding) {
return StringNodes.createString(getContext().getCoreLibrary().getStringClass(), string, encoding);
}

protected RubyString createString(byte[] bytes) {
protected RubyBasicObject createString(byte[] bytes) {
return StringNodes.createString(getContext().getCoreLibrary().getStringClass(), bytes);
}

protected RubyString createString(ByteBuffer bytes) {
protected RubyBasicObject createString(ByteBuffer bytes) {
return StringNodes.createString(getContext().getCoreLibrary().getStringClass(), bytes);
}

protected RubyString createString(ByteList bytes) {
protected RubyBasicObject createString(ByteList bytes) {
return StringNodes.createString(getContext().getCoreLibrary().getStringClass(), bytes);
}

protected RubyArray createEmptyArray() {
protected RubyBasicObject createEmptyArray() {
return ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());
}

protected RubyArray createArray(int[] store, int size) {
protected RubyBasicObject createArray(int[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

protected RubyArray createArray(long[] store, int size) {
protected RubyBasicObject createArray(long[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

protected RubyArray createArray(double[] store, int size) {
protected RubyBasicObject createArray(double[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

protected RubyArray createArray(Object[] store, int size) {
protected RubyBasicObject createArray(Object[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.hash.KeyValue;
import org.jruby.truffle.runtime.methods.Arity;
@@ -45,7 +45,7 @@ public CheckArityNode(RubyContext context, SourceSection sourceSection, Arity ar
public void executeVoid(VirtualFrame frame) {
final Object[] frameArguments = frame.getArguments();
final int given;
final RubyHash keywordArguments;
final RubyBasicObject keywordArguments;

//TODO (MS): Check merge
if (RubyArguments.isKwOptimized(frame.getArguments())) {
@@ -76,7 +76,7 @@ public void executeVoid(VirtualFrame frame) {
}
}

private boolean checkArity(VirtualFrame frame, int given, RubyHash keywordArguments) {
private boolean checkArity(VirtualFrame frame, int given, RubyBasicObject keywordArguments) {
if (keywordArguments != null) {
given -= 1;
}
Loading

0 comments on commit f806e01

Please sign in to comment.