| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package jpype.common; |
| 17 |
|
| 18 |
import java.lang.reflect.InvocationTargetException; |
| 19 |
import java.lang.reflect.Method; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class OnShutdown |
| 26 |
{ |
| 27 |
|
| 28 |
static public void addCoverageHook(Object context) |
| 29 |
{ |
| 30 |
try |
| 31 |
{ |
| 32 |
Method method = context.getClass().getMethod("_addPost", Runnable.class); |
| 33 |
method.invoke(context, new CoverageHook()); |
| 34 |
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) |
| 35 |
{ |
| 36 |
System.out.println("Fail to install post hook " + ex.getMessage()); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
private static class CoverageHook implements Runnable |
| 41 |
{ |
| 42 |
|
| 43 |
@Override |
| 44 |
public void run() |
| 45 |
{ |
| 46 |
|
| 47 |
|
| 48 |
try |
| 49 |
{ |
| 50 |
Class<?> RT = Class.forName("org.jacoco.agent.rt.RT"); |
| 51 |
Method getAgent = RT.getMethod("getAgent"); |
| 52 |
Object agent = getAgent.invoke(null); |
| 53 |
Thread.sleep(100); |
| 54 |
agent.getClass().getMethod("dump", boolean.class).invoke(agent, false); |
| 55 |
System.err.println("*** Coverage dumped"); |
| 56 |
} catch (InterruptedException | NullPointerException | ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) |
| 57 |
{ |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |