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