Class MultipleParentClassLoader.Builder
- Enclosing class:
MultipleParentClassLoader
MultipleParentClassLoader
only if multiple or no
ClassLoader
s are found in the process. If exactly a single class loader is found,
this class loader is returned. All class loaders are applied in their collection order with the exception
of the bootstrap class loader which is represented by null
and which is an implicit parent of any
class loader.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<? extends ClassLoader> The class loaders that were collected.private final boolean
true
if the created class loader is sealed. -
Constructor Summary
ConstructorsModifierConstructorDescriptionBuilder()
Creates a new builder without any class loaders.Builder
(boolean sealed) Creates a new builder without any class loaders.private
Builder
(List<? extends ClassLoader> classLoaders, boolean sealed) Creates a new builder. -
Method Summary
Modifier and TypeMethodDescriptionAppends the class loaders of the given types.append
(ClassLoader... classLoader) Appends the given class loaders if they were not yet collected.append
(Collection<? extends Class<?>> types) Appends the class loaders of the given types if those class loaders were not yet collected.append
(List<? extends ClassLoader> classLoaders) Appends the given class loaders if they were not yet appended.appendMostSpecific
(Class<?>... type) Appends the class loaders of the given types but filters any duplicates within the hierarchy of class loaders.appendMostSpecific
(ClassLoader... classLoader) Appends the given class loaders but removes any class loaders that are the parent of any previously registered class loader.appendMostSpecific
(Collection<? extends Class<?>> types) Appends the class loaders of the given types but filters any duplicates within the hierarchy of class loaders.appendMostSpecific
(List<? extends ClassLoader> classLoaders) Appends the given class loaders but removes any class loaders that are the parent of any previously registered class loader.build()
Returns the only class loader that was appended if exactly one class loader was appended or a multiple parent class loader as a parent of all supplied class loader and with the bootstrap class loader as an implicit parent.build
(ClassLoader parent) Returns the only class loader that was appended if exactly one class loader was appended or a multiple parent class loader as a parent of all supplied class loader and with the bootstrap class loader as an implicit parent.private ClassLoader
doBuild
(ClassLoader parent) Creates a multiple parent class loader with an explicit parent.filter
(ElementMatcher<? super ClassLoader> matcher) Only retains all class loaders that match the given matcher.
-
Field Details
-
sealed
private final boolean sealedtrue
if the created class loader is sealed. -
classLoaders
The class loaders that were collected.
-
-
Constructor Details
-
Builder
public Builder()Creates a new builder without any class loaders. -
Builder
public Builder(boolean sealed) Creates a new builder without any class loaders.- Parameters:
sealed
-true
if the created class loader is sealed.
-
Builder
Creates a new builder.- Parameters:
classLoaders
- The class loaders that were collected until now.sealed
-true
if the created class loader is sealed.
-
-
Method Details
-
append
Appends the class loaders of the given types. The bootstrap class loader is implicitly skipped as it is an implicit parent of any class loader.- Parameters:
type
- The types of which to collect the class loaders.- Returns:
- A new builder instance with the additional class loaders of the provided types if they were not yet collected.
-
append
Appends the class loaders of the given types if those class loaders were not yet collected. The bootstrap class loader is implicitly skipped as it is an implicit parent of any class loader.- Parameters:
types
- The types of which to collect the class loaders.- Returns:
- A new builder instance with the additional class loaders.
-
append
Appends the given class loaders if they were not yet collected. The bootstrap class loader is implicitly skipped as it is an implicit parent of any class loader.- Parameters:
classLoader
- The class loaders to be collected.- Returns:
- A new builder instance with the additional class loaders.
-
append
Appends the given class loaders if they were not yet appended. The bootstrap class loader is never appended as it is an implicit parent of any class loader.- Parameters:
classLoaders
- The class loaders to collected.- Returns:
- A new builder instance with the additional class loaders.
-
appendMostSpecific
Appends the class loaders of the given types but filters any duplicates within the hierarchy of class loaders. The bootstrap class loader is implicitly skipped as it is an implicit parent of any class loader. Class loaders are prepended to the list of class loaders.- Parameters:
type
- The types of which to collect the class loaders.- Returns:
- A new builder instance with the additional class loaders of the provided types if they were not yet collected.
-
appendMostSpecific
Appends the class loaders of the given types but filters any duplicates within the hierarchy of class loaders. The bootstrap class loader is implicitly skipped as it is an implicit parent of any class loader. Class loaders are prepended to the list of class loaders.- Parameters:
types
- The types of which to collect the class loaders.- Returns:
- A new builder instance with the additional class loaders.
-
appendMostSpecific
Appends the given class loaders but removes any class loaders that are the parent of any previously registered class loader. The bootstrap class loader is implicitly skipped as it is an implicit parent of any class loader.- Parameters:
classLoader
- The class loaders to be collected.- Returns:
- A new builder instance with the additional class loaders.
-
appendMostSpecific
public MultipleParentClassLoader.Builder appendMostSpecific(List<? extends ClassLoader> classLoaders) Appends the given class loaders but removes any class loaders that are the parent of any previously registered class loader. The bootstrap class loader is implicitly skipped as it is an implicit parent of any class loader.- Parameters:
classLoaders
- The class loaders to collected.- Returns:
- A new builder instance with the additional class loaders.
-
filter
Only retains all class loaders that match the given matcher.- Parameters:
matcher
- The matcher to be used for filtering.- Returns:
- A builder that does not longer consider any appended class loaders that matched the provided matcher.
-
build
Returns the only class loader that was appended if exactly one class loader was appended or a multiple parent class loader as a parent of all supplied class loader and with the bootstrap class loader as an implicit parent. If no class loader was appended, a new class loader is created that declares no parents. If a class loader is created, its explicit parent is set to be the bootstrap class loader.
Important: Byte Buddy does not provide any access control for the creation of the class loader. It is the responsibility of the user of this builder to provide such privileges.
- Returns:
- A suitable class loader.
-
build
Returns the only class loader that was appended if exactly one class loader was appended or a multiple parent class loader as a parent of all supplied class loader and with the bootstrap class loader as an implicit parent. If no class loader was appended, or if only the supplied parent to this method was included, this class loader is returned,
Important: Byte Buddy does not provide any access control for the creation of the class loader. It is the responsibility of the user of this builder to provide such privileges.
- Parameters:
parent
- The class loader's contractual parent which is accessible viaClassLoader.getParent()
. If this class loader is also included in the appended class loaders, it is not- Returns:
- A suitable class loader.
-
doBuild
Creates a multiple parent class loader with an explicit parent.- Parameters:
parent
- The explicit parent class loader.- Returns:
- A multiple parent class loader that includes all collected class loaders and the explicit parent.
-