1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.plugin.surefire.extensions;
20
21 import org.apache.maven.plugin.surefire.report.StatelessXmlReporter;
22 import org.apache.maven.plugin.surefire.report.TestSetStats;
23 import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
24 import org.apache.maven.surefire.api.util.ReflectionUtils;
25 import org.apache.maven.surefire.extensions.StatelessReportEventListener;
26 import org.apache.maven.surefire.extensions.StatelessReporter;
27
28 /**
29 * Default implementation for extension of {@link StatelessXmlReporter} in plugin.
30 * Signatures can be changed between major, minor versions or milestones.
31 * <br>
32 * This is a builder of {@link StatelessReportEventListener listener}.
33 * The listener handles <em>testSetCompleted</em> event.
34 *
35 * author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
36 * @since 3.0.0-M4
37 */
38 public class SurefireStatelessReporter
39 extends StatelessReporter<WrappedReportEntry, TestSetStats, DefaultStatelessReportMojoConfiguration> {
40 /**
41 * Activated in the injection point of MOJO.
42 */
43 public SurefireStatelessReporter() {
44 this(false, "3.0.2");
45 }
46
47 /**
48 * Activated if null injection point in MOJO.
49 * @param disable {@code true} to disable performing the report
50 * @param version version of the schema
51 */
52 public SurefireStatelessReporter(boolean disable, String version) {
53 setDisable(disable);
54 setVersion(version);
55 }
56
57 @Override
58 public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createListener(
59 DefaultStatelessReportMojoConfiguration configuration) {
60 return new StatelessXmlReporter(
61 configuration.getReportsDirectory(),
62 configuration.getReportNameSuffix(),
63 configuration.isTrimStackTrace(),
64 configuration.getRerunFailingTestsCount(),
65 configuration.getTestClassMethodRunHistory(),
66 configuration.getXsdSchemaLocation(),
67 getVersion(),
68 false,
69 false,
70 false,
71 false,
72 configuration.isEnableOutErrElements(),
73 configuration.isEnablePropertiesElement());
74 }
75
76 @Override
77 public Object clone(ClassLoader target) {
78 try {
79 Class<?> cls = ReflectionUtils.reloadClass(target, this);
80 Object clone = cls.newInstance();
81
82 cls.getMethod("setDisable", boolean.class).invoke(clone, isDisable());
83 cls.getMethod("setVersion", String.class).invoke(clone, getVersion());
84
85 return clone;
86 } catch (ReflectiveOperationException e) {
87 throw new IllegalStateException(e.getLocalizedMessage());
88 }
89 }
90 }