Package org.jruby.runtime.load
Class LoadService
java.lang.Object
org.jruby.runtime.load.LoadService
- Direct Known Subclasses:
OSGiLoadService
How require works in JRuby
When requiring a name from Ruby, JRuby will first remove any file extension it knows about, thereby making it possible to use this string to see if JRuby has already loaded the name in question. If a .rb extension is specified, JRuby will only try those extensions when searching. If a .so, .o, .dll, or .jar extension is specified, JRuby will only try .so or .jar when searching. Otherwise, JRuby goes through the known suffixes (.rb, .rb.ast.ser, .so, and .jar) and tries to find a library with this name. The process for finding a library follows this order for all searchable extensions:- First, check if the name starts with 'jar:', then the path points to a jar-file resource which is returned.
- Second, try searching for the file in the current dir
- Then JRuby looks through the load path trying these variants:
- See if the current load path entry starts with 'jar:', if so check if this jar-file contains the name
- Otherwise JRuby tries to construct a path by combining the entry and the current working directy, and then see if a file with the correct name can be reached from this point.
- If all these fail, try to load the name as a resource from classloader resources, using the bare name as well as the load path entries
- When we get to this state, the normal JRuby loading has failed. At
this stage JRuby tries to load Java native extensions, by following this
process:
- First it checks that we haven't already found a library. If we found a library of type JarredScript, the method continues.
- The first step is translating the name given into a valid Java Extension class name. First it splits the string into each path segment, and then makes all but the last downcased. After this it takes the last entry, removes all underscores and capitalizes each part separated by underscores. It then joins everything together and tacks on a 'Service' at the end. Lastly, it removes all leading dots, to make it a valid Java FWCN.
- If the previous library was of type JarredScript, we try to add the jar-file to the classpath
- Now JRuby tries to instantiate the class with the name constructed. If this works, we return a ClassExtensionLibrary. Otherwise, the old library is put back in place, if there was one.
- When all separate methods have been tried and there was no result, a LoadError will be raised.
- Otherwise, the name will be added to the loaded features, and the library loaded
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassDeprecated.classDeprecated.classDeprecated.static interfaceDeprecated.private static class(package private) static enumclassDeprecated.(package private) final classprivate static enumclassDeprecated.static classDeprecated.classDeprecated.static enumprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionDeprecated.private booleanprotected static final Patternprotected LibrarySearcherprotected StringArraySetprotected RubyArrayprivate final LoadService.LoadTimer(package private) static final Logger(package private) final LoadService.RequireLocksprotected final Rubyprotected static final Patternprivate static final Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBuiltinLibrary(String name, Library library) Deprecated.protected voidaddLoadedFeature(String name) Deprecated.protected voidaddLoadedFeature(String shortName, String name) Deprecated.protected voidvoidAdd additional directories to the load path.voidAdd additional directories to the load path.booleanautoloadRequire(RubyString requireName) protected StringbuildClassName(String className) Deprecated.protected voidcheckEmptyLoad(String file) static StringclasspathFilenameFromURL(String name, URL loc, boolean isClasspathScheme) Given a URL to a classloader resource, build an appropriate load string.protected LibrarycreateLibrary(String baseName, String loadName, LoadServiceResource resource) protected LibrarycreateLibrary(LoadService.SearchState state, LoadServiceResource resource) Deprecated.private static voiddebugLoadException(Ruby runtime, Throwable ex) protected final voiddebugLogFound(String what, String msg) protected final voiddebugLogFound(LoadServiceResource resource) protected final voiddebugLogTry(String what, String msg) private StringexpandRelativeJarPath(String path) booleanfeatureAlreadyLoaded(String feature) booleanfeatureAlreadyLoaded(String feature, String[] loading) protected LibraryfindBuiltinLibrary(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.findFileForLoad(String file) Deprecated.protected LoadServiceResourcefindFileInClasspath(String name) this method uses the appropriate lookup strategy to find a file.protected LibraryDeprecated.protected LibrarySearcher.FoundLibraryfindLibraryWithClassloaders(String baseName, LoadService.SuffixType suffixType) protected LibraryfindLibraryWithClassloaders(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.protected LibraryfindLibraryWithoutCWD(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.Deprecated.getClassPathResource(ClassLoader classLoader, String name) protected StringgetFileName(JRubyFile file, String namePlusSuffix) Deprecated.getJarFile(String jarFileName) protected StringgetLoadPathEntry(IRubyObject entry) voidCalled to initialize the load path with a set of optional prepended directories and then the standard set of dirs.protected booleanisJarfileLibrary(Library library, String file) protected booleanisJarfileLibrary(LoadService.SearchState state, String file) Deprecated.protected static booleanisRequireable(URL loc) voidvoidloadFromClassLoader(ClassLoader classLoader, String file, boolean wrap) protected booleanloadPathLooksLikeClasspathURL(String loadPathEntry) protected booleanloadPathLooksLikeJarURL(String loadPathEntry) private static RaiseExceptionnewLoadErrorFromThrowable(Ruby runtime, String file, Throwable t) voidvoidDeprecated.static voidreflectedLoad(Ruby runtime, String libraryName, String className, ClassLoader classLoader, boolean wrap) Load the org.jruby.runtime.load.Library implementation specified by className.voidremoveBuiltinLibrary(String name) Deprecated.voidDeprecated.booleanprotected voidDeprecated.protected StringresolveLoadName(LoadServiceResource foundResource, String previousPath) protected LibrarySearcher.FoundLibrarysearchForLoad(String file) Replaces findLibraryBySearchState but split off for load.protected charsearchForRequire(String file, LibrarySearcher.FoundLibrary[] path) Replaces findLibraryBySearchState but split off for require.booleanDeprecated.private LoadService.RequireStatesmartLoadInternal(String file, boolean circularRequireWarning) private String[]splitJarUrl(String loadPathEntry) protected booleantryLoadingLibraryOrScript(Ruby runtime, Library library, String searchFile) protected booleantryLoadingLibraryOrScript(Ruby runtime, LoadService.SearchState state) Deprecated.protected LoadServiceResourcetryResourceAsIs(String namePlusSuffix) Deprecated.protected LoadServiceResourcetryResourceAsIs(String namePlusSuffix, String debugName) Deprecated.protected LoadServiceResourcetryResourceFromCWD(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.protected LoadServiceResourcetryResourceFromDotSlash(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.protected LoadServiceResourcetryResourceFromHome(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.protected LoadServiceResourcetryResourceFromJarURL(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.protected LoadServiceResourcetryResourceFromJarURLWithLoadPath(String namePlusSuffix, String loadPathEntry) Deprecated.protected LoadServiceResourcetryResourceFromLoadPath(String namePlusSuffix, String loadPathEntry) Deprecated.protected LoadServiceResourcetryResourceFromLoadPathOrURL(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated.protected voidwarnCircularRequire(String requireName)
-
Field Details
-
LOG
-
loadTimer
-
canGetAbsolutePath
private boolean canGetAbsolutePath -
sourcePattern
-
extensionPattern
-
loadPath
-
loadedFeatures
-
jarFiles
-
runtime
-
librarySearcher
-
requireLocks
-
URI_PATTERN
-
builtinLibraries
Deprecated.
-
-
Constructor Details
-
LoadService
-
-
Method Details
-
init
Called to initialize the load path with a set of optional prepended directories and then the standard set of dirs. This should only be called once, at load time, since it wipes out loaded features.- Parameters:
prependDirectories-
-
addPaths
Add additional directories to the load path.- Parameters:
additionalDirectories- a List of additional dirs to append to the load path
-
addPaths
Add additional directories to the load path.- Parameters:
additionalDirectories- an array of additional dirs to append to the load path
-
provide
-
addPath
-
load
-
loadFromClassLoader
-
require
-
autoloadRequire
-
warnCircularRequire
-
smartLoadInternal
-
reflectedLoad
public static void reflectedLoad(Ruby runtime, String libraryName, String className, ClassLoader classLoader, boolean wrap) Load the org.jruby.runtime.load.Library implementation specified by className. The purpose of using this method is to avoid having static references to the given library class, thereby avoiding the additional classloading when the library is not in use.- Parameters:
runtime- The runtime in which to loadlibraryName- The name of the library, to use for error messagesclassName- The class of the libraryclassLoader- The classloader to use to load itwrap- Whether to wrap top-level in an anonymous module
-
debugLoadException
-
getLoadPath
-
getLoadedFeatures
-
isJarfileLibrary
-
tryLoadingLibraryOrScript
-
newLoadErrorFromThrowable
-
checkEmptyLoad
- Throws:
RaiseException
-
debugLogTry
-
debugLogFound
-
debugLogFound
-
searchForRequire
Replaces findLibraryBySearchState but split off for require. Needed for OSGiLoadService to override. -
searchForLoad
Replaces findLibraryBySearchState but split off for load. Needed for OSGiLoadService to override. -
featureAlreadyLoaded
-
featureAlreadyLoaded
-
findLibraryWithClassloaders
protected LibrarySearcher.FoundLibrary findLibraryWithClassloaders(String baseName, LoadService.SuffixType suffixType) -
createLibrary
-
getLoadPathEntry
-
getJarFile
-
loadPathLooksLikeJarURL
-
loadPathLooksLikeClasspathURL
-
splitJarUrl
-
findFileInClasspath
this method uses the appropriate lookup strategy to find a file. It is used by Kernel#require.- Parameters:
name- the file to find, this is a path name- Returns:
- the correct file
-
isRequireable
-
getClassPathResource
-
classpathFilenameFromURL
Given a URL to a classloader resource, build an appropriate load string.- Parameters:
name- the original filename requestedloc- the URL to the resourceisClasspathScheme- whether we're using the classpath: sceheme- Returns:
-
expandRelativeJarPath
-
resolveLoadName
-
getFileName
Deprecated. -
addBuiltinLibrary
Deprecated. -
removeBuiltinLibrary
Deprecated. -
getBuiltinLibraries
Deprecated. -
smartLoad
Deprecated.This method did require the specified file without getting a lock. Now we offer safe version only. Userequire(String)instead. -
addLoadedFeature
Deprecated. -
buildClassName
Deprecated. -
findBuiltinLibrary
@Deprecated protected Library findBuiltinLibrary(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated. -
findLibraryWithoutCWD
@Deprecated protected Library findLibraryWithoutCWD(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated. -
tryResourceFromCWD
@Deprecated protected LoadServiceResource tryResourceFromCWD(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) throws RaiseException Deprecated.- Throws:
RaiseException
-
tryResourceFromDotSlash
@Deprecated protected LoadServiceResource tryResourceFromDotSlash(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) throws RaiseException Deprecated.Try loading the resource from the current dir by appending suffixes and passing it to tryResourceAsIs to have the ./ replaced by CWD.- Throws:
RaiseException
-
tryResourceFromHome
@Deprecated protected LoadServiceResource tryResourceFromHome(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) throws RaiseException Deprecated.- Throws:
RaiseException
-
tryResourceFromJarURL
@Deprecated protected LoadServiceResource tryResourceFromJarURL(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated. -
tryResourceFromLoadPathOrURL
@Deprecated protected LoadServiceResource tryResourceFromLoadPathOrURL(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated. -
tryResourceFromJarURLWithLoadPath
@Deprecated protected LoadServiceResource tryResourceFromJarURLWithLoadPath(String namePlusSuffix, String loadPathEntry) Deprecated. -
tryResourceFromLoadPath
@Deprecated protected LoadServiceResource tryResourceFromLoadPath(String namePlusSuffix, String loadPathEntry) throws RaiseException Deprecated.- Throws:
RaiseException
-
tryResourceAsIs
@Deprecated protected LoadServiceResource tryResourceAsIs(String namePlusSuffix) throws RaiseException Deprecated.- Throws:
RaiseException
-
tryResourceAsIs
@Deprecated protected LoadServiceResource tryResourceAsIs(String namePlusSuffix, String debugName) throws RaiseException Deprecated.- Throws:
RaiseException
-
removeInternalLoadedFeature
Deprecated. -
reraiseRaiseExceptions
Deprecated.- Throws:
RaiseException
-
findFileForLoad
Deprecated. -
createLibrary
@Deprecated protected Library createLibrary(LoadService.SearchState state, LoadServiceResource resource) Deprecated. -
findLibraryWithClassloaders
@Deprecated protected Library findLibraryWithClassloaders(LoadService.SearchState state, String baseName, LoadService.SuffixType suffixType) Deprecated. -
tryLoadingLibraryOrScript
@Deprecated protected boolean tryLoadingLibraryOrScript(Ruby runtime, LoadService.SearchState state) Deprecated. -
isJarfileLibrary
Deprecated. -
findLibraryBySearchState
Deprecated. -
provide
Deprecated. -
addLoadedFeature
Deprecated.
-