View Javadoc
1   package org.apache.maven.surefire.api.booter;
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.surefire.api.report.TestOutputReportEntry;
23  import org.apache.maven.surefire.api.report.TestReportListener;
24  import org.apache.maven.surefire.api.report.ReportEntry;
25  import org.apache.maven.surefire.api.report.TestSetReportEntry;
26  
27  /**
28   * Encodes the full output of the test run to the "target".
29   * <br>
30   * This class and the ForkClient contain the full definition of the
31   * "wire-level" protocol used by the forked process. The protocol
32   * is *not* part of any public api and may change without further
33   * notice.
34   * <br>
35   * This class is thread-safe.
36   * <br>
37   * The synchronization in the underlying (target instance)
38   * is used to preserve thread safety of the target stream.
39   * To perform multiple writes/prints for a single request,
40   * they must synchronize on "target" variable in this class.
41   *
42   * @author Kristian Rosenvold
43   */
44  public class ForkingRunListener
45      implements TestReportListener<TestOutputReportEntry>
46  {
47      private final MasterProcessChannelEncoder target;
48      private final boolean trim;
49  
50      public ForkingRunListener( MasterProcessChannelEncoder target, boolean trim )
51      {
52          this.target = target;
53          this.trim = trim;
54      }
55  
56      @Override
57      public void testSetStarting( TestSetReportEntry report )
58      {
59          target.testSetStarting( report, trim );
60      }
61  
62      @Override
63      public void testSetCompleted( TestSetReportEntry report )
64      {
65          target.testSetCompleted( report, trim );
66      }
67  
68      @Override
69      public void testStarting( ReportEntry report )
70      {
71          target.testStarting( report, trim );
72      }
73  
74      @Override
75      public void testSucceeded( ReportEntry report )
76      {
77          target.testSucceeded( report, trim );
78      }
79  
80      @Override
81      public void testAssumptionFailure( ReportEntry report )
82      {
83          target.testAssumptionFailure( report, trim );
84      }
85  
86      @Override
87      public void testError( ReportEntry report )
88      {
89          target.testError( report, trim );
90      }
91  
92      @Override
93      public void testFailed( ReportEntry report )
94      {
95          target.testFailed( report, trim );
96      }
97  
98      @Override
99      public void testSkipped( ReportEntry report )
100     {
101         target.testSkipped( report, trim );
102     }
103 
104     @Override
105     public void testExecutionSkippedByUser()
106     {
107         target.stopOnNextTest();
108     }
109 
110     @Override
111     public void writeTestOutput( TestOutputReportEntry reportEntry )
112     {
113         target.testOutput( reportEntry );
114     }
115 
116     @Override
117     public boolean isDebugEnabled()
118     {
119         return true;
120     }
121 
122     @Override
123     public void debug( String message )
124     {
125         target.consoleDebugLog( message );
126     }
127 
128     @Override
129     public boolean isInfoEnabled()
130     {
131         return true;
132     }
133 
134     @Override
135     public void info( String message )
136     {
137         target.consoleInfoLog( message );
138     }
139 
140     @Override
141     public boolean isWarnEnabled()
142     {
143         return true;
144     }
145 
146     @Override
147     public void warning( String message )
148     {
149         target.consoleWarningLog( message );
150     }
151 
152     @Override
153     public boolean isErrorEnabled()
154     {
155         return true;
156     }
157 
158     @Override
159     public void error( String message )
160     {
161         target.consoleErrorLog( message );
162     }
163 
164     @Override
165     public void error( String message, Throwable t )
166     {
167         target.consoleErrorLog( message, t );
168     }
169 
170     @Override
171     public void error( Throwable t )
172     {
173         error( null, t );
174     }
175 }