1 package org.apache.maven.surefire.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24 import org.apache.maven.surefire.util.NestedRuntimeException;
25 import org.apache.maven.surefire.util.ReflectionUtils;
26
27
28
29
30
31
32
33 public class JdkReflector
34 {
35 private final Method assertionStatusMethod;
36
37
38 public JdkReflector()
39 {
40 assertionStatusMethod = ReflectionUtils.tryGetMethod( ClassLoader.class, "setDefaultAssertionStatus",
41 new Class[]{ boolean.class } );
42 }
43
44 public void invokeAssertionStatusMethod( ClassLoader classLoader, boolean enableAssertions )
45 {
46 if ( assertionStatusMethod != null )
47 {
48 try
49 {
50 Object[] args = new Object[]{ enableAssertions ? Boolean.TRUE : Boolean.FALSE };
51 assertionStatusMethod.invoke( classLoader, args );
52 }
53 catch ( IllegalAccessException e )
54 {
55 throw new NestedRuntimeException( "Unable to access the assertion enablement method", e );
56 }
57 catch ( InvocationTargetException e )
58 {
59 throw new NestedRuntimeException( "Unable to invoke the assertion enablement method", e );
60 }
61 }
62 }
63
64 }