View Javadoc
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 java.io.File;
22  import java.nio.charset.Charset;
23  
24  import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
25  import org.apache.maven.plugin.surefire.report.ConsoleReporter;
26  import org.apache.maven.plugin.surefire.report.FileReporter;
27  import org.apache.maven.plugin.surefire.report.TestSetStats;
28  import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
29  import org.apache.maven.surefire.api.util.ReflectionUtils;
30  import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
31  import org.apache.maven.surefire.extensions.StatelessTestsetInfoFileReportEventListener;
32  import org.apache.maven.surefire.extensions.StatelessTestsetInfoReporter;
33  
34  /**
35   * Default implementation for extension of
36   * {@link StatelessTestsetInfoFileReportEventListener test-set event listener for stateless file and console reporter}
37   * in plugin. Signatures can be changed between major, minor versions or milestones.
38   * <br>
39   * Builds {@link StatelessTestsetInfoFileReportEventListener listeners}.
40   * The listener handles <em>testSetCompleted</em> event.
41   *
42   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
43   * @since 3.0.0-M4
44   */
45  public class SurefireStatelessTestsetInfoReporter
46          extends StatelessTestsetInfoReporter<WrappedReportEntry, TestSetStats> {
47      @Override
48      public StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> createListener(
49              ConsoleLogger logger) {
50          return new ConsoleReporter(logger, false, false);
51      }
52  
53      @Override
54      public StatelessTestsetInfoFileReportEventListener<WrappedReportEntry, TestSetStats> createListener(
55              File reportsDirectory, String reportNameSuffix, Charset encoding) {
56          return new FileReporter(reportsDirectory, reportNameSuffix, encoding, false, false, false);
57      }
58  
59      @Override
60      public Object clone(ClassLoader target) {
61          try {
62              Class<?> cls = ReflectionUtils.reloadClass(target, this);
63              Object clone = cls.newInstance();
64  
65              cls.getMethod("setDisable", boolean.class).invoke(clone, isDisable());
66  
67              return clone;
68          } catch (ReflectiveOperationException e) {
69              throw new IllegalStateException(e.getLocalizedMessage());
70          }
71      }
72  
73      @Override
74      public String toString() {
75          return "SurefireStatelessTestsetInfoReporter{disable=" + isDisable() + "}";
76      }
77  }