Debian Codegraph @

test/harness/jpype/common/OnShutdown.java

raw symbols SCIP
1 /* ****************************************************************************
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14 See NOTICE file for details.
15 **************************************************************************** */
16 package jpype.common;
17
18 import java.lang.reflect.InvocationTargetException;
19 import java.lang.reflect.Method;
20
21 /**
22 *
23 * @author nelson85
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 // If coverage tools are being used, we need to dump last before everything
47 // shuts down
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); // make sure we don't clober
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 }