static FileResource wrap(POSIX posix, JRubyFile file) { return new RegularFileResource(posix, file, file.getPathDefault()); }
public static FileResource createResource(String cwd, String pathname) { if (pathname == null) { // null pathnames do not exist return new RegularFileResource(JRubyNonExistentFile.NOT_EXIST); } // Try as a jar resource first FileResource jarResource = JarResource.create(pathname); if (jarResource != null) { return jarResource; } return new RegularFileResource(create(cwd, pathname)); }
static FileResource wrap(POSIX posix, JRubyFile file) { return new RegularFileResource(posix, file, file.getPathDefault()); }
private static FileResource createResource(Ruby runtime, String cwd, String pathname, boolean isFile) { FileResource resource = EmptyFileResource.create(pathname); if (resource != null) return resource; // This will work against anything potentially containing a '!' in it and does not require a scheme. // (see test/test_java_on_load_path.rb: $LOAD_PATH << "test/test_jruby_1332.jar!"; require 'test_jruby_1332.rb' resource = JarResource.create(pathname); if (resource != null) return resource; if (Platform.IS_WINDOWS && (pathname.equalsIgnoreCase("nul") || pathname.equalsIgnoreCase("nul:"))) { return new NullDeviceResource(); } if (pathname.indexOf(':') > 0) { // scheme-oriented resources if (pathname.startsWith("classpath:")) { pathname = "uri:classloader:/" + pathname.substring(10); } // replace is needed for maven/jruby-complete/src/it/app_using_classpath_uri to work if (pathname.startsWith("uri:")) return URLResource.create(runtime, pathname, isFile); if (pathname.startsWith("file:")) { pathname = pathname.substring(5); if (pathname.length() == 0) return EmptyFileResource.INSTANCE; } } if (cwd != null && (cwd.startsWith("uri:") || cwd.startsWith("file:")) && !new File(pathname).isAbsolute()) { return createResource(runtime, null, cwd + '/' + pathname); } // If any other special resource types fail, count it as a filesystem backed resource. return new RegularFileResource(runtime != null ? runtime.getPosix() : null, create(cwd, pathname), pathname); }
private static FileResource createResource(Ruby runtime, String cwd, String pathname, boolean isFile) { FileResource resource = EmptyFileResource.create(pathname); if (resource != null) return resource; // This will work against anything potentially containing a '!' in it and does not require a scheme. // (see test/test_java_on_load_path.rb: $LOAD_PATH << "test/test_jruby_1332.jar!"; require 'test_jruby_1332.rb' resource = JarResource.create(pathname); if (resource != null) return resource; if (Platform.IS_WINDOWS && (pathname.equalsIgnoreCase("nul") || pathname.equalsIgnoreCase("nul:"))) { return new NullDeviceResource(); } if (pathname.indexOf(':') > 0) { // scheme-oriented resources if (pathname.startsWith("classpath:")) { pathname = "uri:classloader:/" + pathname.substring(10); } // replace is needed for maven/jruby-complete/src/it/app_using_classpath_uri to work if (pathname.startsWith("uri:")) return URLResource.create(runtime, pathname, isFile); if (pathname.startsWith("file:")) { pathname = pathname.substring(5); if (pathname.length() == 0) return EmptyFileResource.INSTANCE; } } if (cwd != null && (cwd.startsWith("uri:") || cwd.startsWith("file:")) && !new File(pathname).isAbsolute()) { return createResource(runtime, null, cwd + '/' + pathname); } // If any other special resource types fail, count it as a filesystem backed resource. return new RegularFileResource(runtime != null ? runtime.getPosix() : null, create(cwd, pathname), pathname); }