Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingInstrumentation
- java.lang.Object
-
- net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
-
- net.bytebuddy.dynamic.loading.ClassInjector.UsingInstrumentation
-
- All Implemented Interfaces:
ClassInjector
- Enclosing interface:
- ClassInjector
@Enhance public static class ClassInjector.UsingInstrumentation extends ClassInjector.AbstractBase
A class injector using aInstrumentationto append to either the boot classpath or the system class path.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceClassInjector.UsingInstrumentation.DispatcherA dispatcher to interact with the instrumentation API.static classClassInjector.UsingInstrumentation.TargetA representation of the target to which Java classes should be appended to.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ClassInjector.AbstractBase, ClassInjector.UsingInstrumentation, ClassInjector.UsingJna, ClassInjector.UsingLookup, ClassInjector.UsingReflection, ClassInjector.UsingUnsafe
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCLASS_FILE_EXTENSIONThe class file extension.private static ClassInjector.UsingInstrumentation.DispatcherDISPATCHERA dispatcher for interacting with the instrumentation API.private java.io.FilefolderThe folder to be used for storing jar files.private java.lang.instrument.InstrumentationinstrumentationThe instrumentation to use for appending to the class path or the boot path.private static java.lang.StringJARThe jar file name extension.private RandomStringrandomStringA random string generator for creating file names.private ClassInjector.UsingInstrumentation.TargettargetA representation of the target path to which classes are to be appended.-
Fields inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
SUPPRESS_ACCESS_CHECKS
-
Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedUsingInstrumentation(java.io.File folder, ClassInjector.UsingInstrumentation.Target target, java.lang.instrument.Instrumentation instrumentation, RandomString randomString)Creates an instrumentation-based class injector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.java.util.Map<java.lang.String,java.lang.Class<?>>injectRaw(java.util.Set<java.lang.String> names, ClassFileLocator classFileLocator)Injects the given types into the represented class loader.booleanisAlive()Indicates if this class injector is available on the current VM.static booleanisAvailable()Returnstrueif this class injector is available on this VM.static ClassInjectorof(java.io.File folder, ClassInjector.UsingInstrumentation.Target target, java.lang.instrument.Instrumentation instrumentation)Creates an instrumentation-based class injector.static voidredefineModule(java.lang.instrument.Instrumentation instrumentation, JavaModule target, java.util.Set<JavaModule> reads, java.util.Map<java.lang.String,java.util.Set<JavaModule>> exports, java.util.Map<java.lang.String,java.util.Set<JavaModule>> opens, java.util.Set<java.lang.Class<?>> uses, java.util.Map<java.lang.Class<?>,java.util.List<java.lang.Class<?>>> provides)Modifies a module's properties usingInstrumentation.-
Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject, inject, injectRaw
-
-
-
-
Field Detail
-
JAR
private static final java.lang.String JAR
The jar file name extension.- See Also:
- Constant Field Values
-
CLASS_FILE_EXTENSION
private static final java.lang.String CLASS_FILE_EXTENSION
The class file extension.- See Also:
- Constant Field Values
-
DISPATCHER
private static final ClassInjector.UsingInstrumentation.Dispatcher DISPATCHER
A dispatcher for interacting with the instrumentation API.
-
instrumentation
private final java.lang.instrument.Instrumentation instrumentation
The instrumentation to use for appending to the class path or the boot path.
-
target
private final ClassInjector.UsingInstrumentation.Target target
A representation of the target path to which classes are to be appended.
-
folder
private final java.io.File folder
The folder to be used for storing jar files.
-
randomString
private final RandomString randomString
A random string generator for creating file names.
-
-
Constructor Detail
-
UsingInstrumentation
protected UsingInstrumentation(java.io.File folder, ClassInjector.UsingInstrumentation.Target target, java.lang.instrument.Instrumentation instrumentation, RandomString randomString)Creates an instrumentation-based class injector.- Parameters:
folder- The folder to be used for storing jar files.target- A representation of the target path to which classes are to be appended.instrumentation- The instrumentation to use for appending to the class path or the boot path.randomString- The random string generator to use.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.- Type Parameters:
T- The type of the action's resolved value.- Parameters:
action- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
redefineModule
public static void redefineModule(java.lang.instrument.Instrumentation instrumentation, JavaModule target, java.util.Set<JavaModule> reads, java.util.Map<java.lang.String,java.util.Set<JavaModule>> exports, java.util.Map<java.lang.String,java.util.Set<JavaModule>> opens, java.util.Set<java.lang.Class<?>> uses, java.util.Map<java.lang.Class<?>,java.util.List<java.lang.Class<?>>> provides)Modifies a module's properties usingInstrumentation.- Parameters:
instrumentation- TheInstrumentationinstance to use for applying the modification.target- The target module that should be modified.reads- A set of additional modules this module should read.exports- A map of packages to export to a set of modules.opens- A map of packages to open to a set of modules.uses- A set of provider interfaces to use by this module.provides- A map of provider interfaces to provide by this module mapped to the provider implementations.
-
of
public static ClassInjector of(java.io.File folder, ClassInjector.UsingInstrumentation.Target target, java.lang.instrument.Instrumentation instrumentation)
Creates an instrumentation-based class injector.- Parameters:
folder- The folder to be used for storing jar files.target- A representation of the target path to which classes are to be appended.instrumentation- The instrumentation to use for appending to the class path or the boot path.- Returns:
- An appropriate class injector that applies instrumentation.
-
isAlive
public boolean isAlive()
Indicates if this class injector is available on the current VM.- Returns:
trueif this injector is available on the current VM.
-
injectRaw
public java.util.Map<java.lang.String,java.lang.Class<?>> injectRaw(java.util.Set<java.lang.String> names, ClassFileLocator classFileLocator)Injects the given types into the represented class loader.- Parameters:
names- The names of the types to load via injection.classFileLocator- The class file locator to use for resolving binary representations.- Returns:
- The loaded types that were passed as arguments.
-
isAvailable
public static boolean isAvailable()
Returnstrueif this class injector is available on this VM.- Returns:
trueif this class injector is available on this VM.
-
-