|
6 | 6 |
|
7 | 7 | package datadog.instrument.classinject; |
8 | 8 |
|
| 9 | +import static java.util.Collections.singletonMap; |
9 | 10 | import static org.objectweb.asm.Opcodes.*; |
10 | 11 |
|
11 | 12 | import datadog.instrument.glue.DefineClassGlue; |
|
38 | 39 | @SuppressWarnings({"rawtypes", "unchecked"}) |
39 | 40 | public final class ClassInjector { |
40 | 41 |
|
| 42 | + /** |
| 43 | + * Injects a class on the bootstrap classpath. |
| 44 | + * |
| 45 | + * @param name the name of the class |
| 46 | + * @param bytecode the class bytecode |
| 47 | + * @return the injected class |
| 48 | + * @throws IllegalStateException if class injection is not enabled |
| 49 | + */ |
| 50 | + public static Class<?> injectBootClass(String name, byte[] bytecode) { |
| 51 | + return injectBootClasses(singletonMap(name, bytecode)).get(0); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Injects a class using the given class-loader. |
| 56 | + * |
| 57 | + * @param name the name of the class |
| 58 | + * @param bytecode the class bytecode |
| 59 | + * @param cl the class-loader to use |
| 60 | + * @return the injected class |
| 61 | + * @throws IllegalStateException if class injection is not enabled |
| 62 | + */ |
| 63 | + public static Class<?> injectClass(String name, byte[] bytecode, ClassLoader cl) { |
| 64 | + return injectClasses(singletonMap(name, bytecode), cl).get(0); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Injects a class using the given protection domain. |
| 69 | + * |
| 70 | + * @param name the name of the class |
| 71 | + * @param bytecode the class bytecode |
| 72 | + * @param pd the protection domain to use |
| 73 | + * @return the injected class |
| 74 | + * @throws IllegalStateException if class injection is not enabled |
| 75 | + */ |
| 76 | + public static Class<?> injectClass(String name, byte[] bytecode, ProtectionDomain pd) { |
| 77 | + return injectClasses(singletonMap(name, bytecode), pd).get(0); |
| 78 | + } |
| 79 | + |
41 | 80 | /** |
42 | 81 | * Injects classes on the bootstrap classpath. |
43 | 82 | * |
|
0 commit comments