1 package org.apache.maven.plugin.surefire;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.lang.reflect.Constructor;
24 import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
25 import org.apache.maven.surefire.util.ReflectionUtils;
26 import org.apache.maven.surefire.util.SurefireReflectionException;
27
28 import javax.annotation.Nonnull;
29
30
31
32
33 public class CommonReflector
34 {
35 private final Class<?> startupReportConfiguration;
36
37 private final ClassLoader surefireClassLoader;
38
39 public CommonReflector( @Nonnull ClassLoader surefireClassLoader )
40 {
41 this.surefireClassLoader = surefireClassLoader;
42
43 try
44 {
45 startupReportConfiguration = surefireClassLoader.loadClass( StartupReportConfiguration.class.getName() );
46 }
47 catch ( ClassNotFoundException e )
48 {
49 throw new SurefireReflectionException( e );
50 }
51 }
52
53 public Object createReportingReporterFactory( @Nonnull StartupReportConfiguration startupReportConfiguration )
54 {
55 Class<?>[] args = new Class[]{ this.startupReportConfiguration };
56 Object src = createStartupReportConfiguration( startupReportConfiguration );
57 Object[] params = new Object[]{ src };
58 return ReflectionUtils.instantiateObject( DefaultReporterFactory.class.getName(), args, params,
59 surefireClassLoader );
60 }
61
62
63 Object createStartupReportConfiguration( @Nonnull StartupReportConfiguration reporterConfiguration )
64 {
65 Constructor<?> constructor = ReflectionUtils.getConstructor( this.startupReportConfiguration,
66 new Class[]{ boolean.class, boolean.class,
67 String.class, boolean.class, boolean.class,
68 File.class, boolean.class, String.class,
69 String.class, boolean.class } );
70
71 final Object[] params = { reporterConfiguration.isUseFile(), reporterConfiguration.isPrintSummary(),
72 reporterConfiguration.getReportFormat(), reporterConfiguration.isRedirectTestOutputToFile(),
73 reporterConfiguration.isDisableXmlReport(), reporterConfiguration.getReportsDirectory(),
74 reporterConfiguration.isTrimStackTrace(), reporterConfiguration.getReportNameSuffix(),
75 reporterConfiguration.getConfigurationHash(), reporterConfiguration.isRequiresRunHistory() };
76 return ReflectionUtils.newInstance( constructor, params );
77 }
78
79 }