/** * This method did require the specified file without getting a lock. * Now we offer safe version only. Use {@link LoadService#require(String)} instead. */ @Deprecated public boolean smartLoad(String file) { return require(file); }
public LoadService create(Ruby runtime) { return new LoadService(runtime); } };
public void provide(String library) { addBuiltinLibrary(library, Library.DUMMY); addLoadedFeature(library, library); }
private boolean smartLoadInternal(String file) { checkEmptyLoad(file); SearchState state = findFileForLoad(file); if (state == null) { return false; } if (state.library == null) { throw runtime.newLoadError("no such file to load -- " + state.searchFile, state.searchFile); } // check with long name if (featureAlreadyLoaded(state.loadName)) { return false; } boolean loaded = tryLoadingLibraryOrScript(runtime, state); if (loaded) { addLoadedFeature(file, state.loadName); } return loaded; }
public void load(final Ruby runtime, boolean wrap) throws IOException { runtime.getLoadService().removeBuiltinLibrary("net/protocol.rb"); runtime.getLoadService().removeInternalLoadedFeature("net/protocol.rb"); runtime.getLoadService().require("net/protocol"); NetProtocolBufferedIO.create(runtime); } }// NetProtocolBufferedIOLibrary
/** * Get an instance of a JRuby runtime. * @param loadPaths additional load paths you wish to add * @param config a runtime configuration instance * @return an instance */ public static Ruby initialize(List<String> loadPaths, RubyInstanceConfig config) { Ruby runtime = Ruby.newInstance(config); runtime.getLoadService().addPaths(loadPaths); runtime.getLoadService().require("java"); return runtime; }
public void load(Ruby runtime, boolean wrap) { runtime.getLoadService().require("java"); // load Ruby parts of the 'jruby' library runtime.getLoadService().loadFromClassLoader(runtime.getJRubyClassLoader(), "jruby/jruby.rb", false); RubyModule JRuby = runtime.getOrCreateModule("JRuby"); JRuby.defineAnnotatedMethods(JRubyLibrary.class); JRuby.defineAnnotatedMethods(JRubyUtilLibrary.class); JRuby.defineClassUnder("ThreadLocal", runtime.getObject(), JRubyThreadLocal.ALLOCATOR) .defineAnnotatedMethods(JRubyExecutionContextLocal.class); JRuby.defineClassUnder("FiberLocal", runtime.getObject(), JRubyFiberLocal.ALLOCATOR) .defineAnnotatedMethods(JRubyExecutionContextLocal.class); RubyModule CONFIG = JRuby.defineModuleUnder("CONFIG"); CONFIG.getSingletonClass().defineAnnotatedMethods(JRubyConfig.class); }
getLoadService().init(config.getLoadPaths()); loadService.require("jruby"); getLoadService().require("jruby/profiler/shutdown_hook"); loadService.loadFromClassLoader(getClassLoader(), "jruby/bundler/startup.rb", false); topSelf.callMethod(getCurrentContext(), "require", RubyString.newString(this, scriptName)); } else { loadService.require(scriptName);
addPaths(prependDirectories); String rubylib = env.op_aref(runtime.getCurrentContext(), env_rubylib).toString(); String[] paths = rubylib.split(File.pathSeparator); addPaths(paths); addPath(RbConfigLibrary.getSiteDir(runtime)); addPath(RbConfigLibrary.getVendorDir(runtime)); addPath(rubygemsDir); addPath(RbConfigLibrary.getRubySharedLibDir(runtime)); addPath(RbConfigLibrary.getRubyLibDirFor(runtime, "2.0")); addPath(RbConfigLibrary.getRubyLibDir(runtime)); addPath(".");
/** * Add additional directories to the load path. * * @param additionalDirectories a List of additional dirs to append to the load path */ public void addPaths(List<String> additionalDirectories) { for (String dir : additionalDirectories) { addPath(dir); } }
@Override public void load(Ruby runtime) { if (runtime.getLoadService().autoloadRequire(file())) { // Do not finish autoloading by cyclic autoload module.finishAutoload(baseName); } } });
private void addBuiltinIfAllowed(String name, Library lib) { if (profile.allowBuiltin(name)) { loadService.addBuiltinLibrary(name, lib); } }
@Deprecated protected void addLoadedFeature(String name) { addLoadedFeature(name, name); }
protected void addLoadedFeature(String shortName, String name) { loadedFeatures.appendString(runtime, name); addFeatureToIndex(shortName, name); }
public boolean trySearch(SearchState state) throws RaiseException { // no library or extension found, try to load directly as a class Script script; String className = buildClassName(state.searchFile); int lastSlashIndex = className.lastIndexOf('/'); if (lastSlashIndex > -1 && lastSlashIndex < className.length() - 1 && !Character.isJavaIdentifierStart(className.charAt(lastSlashIndex + 1))) { if (lastSlashIndex == -1) { className = '_' + className; } else { className = className.substring(0, lastSlashIndex + 1) + '_' + className.substring(lastSlashIndex + 1); } } className = className.replace('/', '.'); try { Class scriptClass = Class.forName(className); script = (Script) scriptClass.newInstance(); } catch (Exception cnfe) { return true; } state.library = new ScriptClassLibrary(script); return true; } }
private boolean smartLoadInternal(String file) { checkEmptyLoad(file); SearchState state = findFileForLoad(file); if (state == null) { return false; } if (state.library == null) { throw runtime.newLoadError("no such file to load -- " + state.searchFile, state.searchFile); } // check with long name if (featureAlreadyLoaded(state.loadName)) { return false; } boolean loaded = tryLoadingLibraryOrScript(runtime, state); if (loaded) { addLoadedFeature(file, state.loadName); } return loaded; }
public void load(final Ruby runtime, boolean wrap) throws IOException { runtime.getLoadService().removeBuiltinLibrary("net/protocol.rb"); runtime.getLoadService().removeInternalLoadedFeature("net/protocol.rb"); runtime.getLoadService().require("net/protocol"); NetProtocolBufferedIO.create(runtime); } }// NetProtocolBufferedIOLibrary
/** * Get an instance of a JRuby runtime. * @param loadPaths additional load paths you wish to add * @param config a runtime configuration instance * @return an instance */ public static Ruby initialize(List loadPaths, RubyInstanceConfig config) { Ruby runtime = Ruby.newInstance(config); runtime.getLoadService().addPaths((List<String>)loadPaths); runtime.getLoadService().require("java"); return runtime; }
public void load(Ruby runtime, boolean wrap) { runtime.getLoadService().require("java"); // load Ruby parts of the 'jruby' library runtime.getLoadService().loadFromClassLoader(runtime.getJRubyClassLoader(), "jruby/jruby.rb", false); RubyModule JRuby = runtime.getOrCreateModule("JRuby"); JRuby.defineAnnotatedMethods(JRubyLibrary.class); JRuby.defineAnnotatedMethods(JRubyUtilLibrary.class); JRuby.defineClassUnder("ThreadLocal", runtime.getObject(), JRubyThreadLocal.ALLOCATOR) .defineAnnotatedMethods(JRubyExecutionContextLocal.class); JRuby.defineClassUnder("FiberLocal", runtime.getObject(), JRubyFiberLocal.ALLOCATOR) .defineAnnotatedMethods(JRubyExecutionContextLocal.class); RubyModule CONFIG = JRuby.defineModuleUnder("CONFIG"); CONFIG.getSingletonClass().defineAnnotatedMethods(JRubyConfig.class); }