View Javadoc
1   package org.apache.maven.plugin.surefire.extensions;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter;
23  import org.apache.maven.plugin.surefire.report.DirectConsoleOutput;
24  import org.apache.maven.surefire.extensions.ConsoleOutputReportEventListener;
25  import org.apache.maven.surefire.extensions.ConsoleOutputReporter;
26  import org.apache.maven.surefire.api.util.ReflectionUtils;
27  
28  import java.io.File;
29  import java.io.PrintStream;
30  
31  /**
32   * Default implementation for extension of console logger.
33   * Signatures can be changed between major, minor versions or milestones.
34   * <br>
35   * Builds {@link ConsoleOutputReportEventListener listeners}.
36   * The listeners handle test set events.
37   *
38   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
39   * @since 3.0.0-M4
40   */
41  public class SurefireConsoleOutputReporter
42          extends ConsoleOutputReporter
43  {
44      @Override
45      public ConsoleOutputReportEventListener createListener( File reportsDirectory, String reportNameSuffix,
46                                                              Integer forkNumber )
47      {
48          return new ConsoleOutputFileReporter( reportsDirectory, reportNameSuffix, false, forkNumber, getEncoding() );
49      }
50  
51      @Override
52      public ConsoleOutputReportEventListener createListener( PrintStream out, PrintStream err )
53      {
54          return new DirectConsoleOutput( out, err );
55      }
56  
57      @Override
58      public Object clone( ClassLoader target )
59      {
60          try
61          {
62              Class<?> cls = ReflectionUtils.reloadClass( target, this );
63              Object clone = cls.newInstance();
64  
65              cls.getMethod( "setDisable", boolean.class )
66                      .invoke( clone, isDisable() );
67              cls.getMethod( "setEncoding", String.class )
68                      .invoke( clone, getEncoding() );
69  
70              return clone;
71          }
72          catch ( ReflectiveOperationException e )
73          {
74              throw new IllegalStateException( e.getLocalizedMessage() );
75          }
76      }
77  
78      @Override
79      public String toString()
80      {
81          return "SurefireConsoleOutputReporter{"
82                  + "disable=" + isDisable()
83                  + ", encoding=" + getEncoding()
84                  + '}';
85      }
86  }