Class AgentModule
java.lang.Object
org.jacoco.agent.rt.internal.AgentModule
An isolated class loader and distinct module to encapsulate JaCoCo runtime
classes. This isolated environment allows to specifically open JDK packages
to the agent runtime without changing package accessibility for the
application under test.
The implementation uses the property that the unnamed module is distinct from all run-time modules (including unnamed modules) bound to other class loaders.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate static Class<?> static booleanChecks whether Java modules are supported by the current Java runtime.<T> Class<T> loadClassInModule(Class<T> original) Loads a copy of the given class in the isolated classloader.voidopenPackage(Instrumentation instrumentation, Class<?> classInPackage) Opens the package of the provided class to the module created in thisAgentModule()instance.
-
Field Details
-
scope
-
classLoader
-
-
Constructor Details
-
AgentModule
-
-
Method Details
-
isSupported
public static boolean isSupported()Checks whether Java modules are supported by the current Java runtime.- Returns:
trueis modules are supported
-
openPackage
Opens the package of the provided class to the module created in thisAgentModule()instance.- Parameters:
instrumentation- service provided to the agent by the Java runtimeclassInPackage- example class of the package to open- Throws:
Exception- if package cannot be opened
-
loadClassInModule
Loads a copy of the given class in the isolated classloader. Also any inner classes are loader from the isolated classloader.- Type Parameters:
T- type of the class to load- Parameters:
original- original class definition which is used as source- Returns:
- class object from the isolated class loader
- Throws:
Exception- if the class cannot be loaded
-
addToScopeWithInnerClasses
-
getModuleClass
- Throws:
ClassNotFoundException
-