View Javadoc
1   package org.apache.maven.plugin.surefire.report;
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.report.ReportEntry;
23  import org.apache.maven.surefire.report.StackTraceWriter;
24  
25  /**
26   * @author Kristian Rosenvold
27   */
28  public class WrappedReportEntry
29      implements ReportEntry
30  {
31      private static final String NL = System.getProperty( "line.separator" );
32  
33      private final ReportEntry original;
34  
35      private final ReportEntryType reportEntryType;
36  
37      private final Integer elapsed;
38  
39      private final Utf8RecodingDeferredFileOutputStream stdout;
40  
41      private final Utf8RecodingDeferredFileOutputStream stdErr;
42  
43      public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
44                                 Utf8RecodingDeferredFileOutputStream stdout,
45                                 Utf8RecodingDeferredFileOutputStream stdErr )
46      {
47          this.original = original;
48          this.reportEntryType = reportEntryType;
49          this.elapsed = estimatedElapsed;
50          this.stdout = stdout;
51          this.stdErr = stdErr;
52      }
53  
54      public Integer getElapsed()
55      {
56          return elapsed;
57      }
58  
59      public ReportEntryType getReportEntryType()
60      {
61          return reportEntryType;
62      }
63  
64      public Utf8RecodingDeferredFileOutputStream getStdout()
65      {
66          return stdout;
67      }
68  
69      public Utf8RecodingDeferredFileOutputStream getStdErr()
70      {
71          return stdErr;
72      }
73  
74      public String getSourceName()
75      {
76          return original.getSourceName();
77      }
78  
79      public String getName()
80      {
81          return original.getName();
82      }
83  
84      public String getClassMethodName()
85      {
86          return getSourceName() + "." + getName();
87      }
88  
89      public String getGroup()
90      {
91          return original.getGroup();
92      }
93  
94      public StackTraceWriter getStackTraceWriter()
95      {
96          return original.getStackTraceWriter();
97      }
98  
99      public String getMessage()
100     {
101         return original.getMessage();
102     }
103 
104     public String getStackTrace( boolean trimStackTrace )
105     {
106         StackTraceWriter w = original.getStackTraceWriter();
107         return w == null ? null : ( trimStackTrace ? w.writeTrimmedTraceToString() : w.writeTraceToString() );
108     }
109 
110     public String elapsedTimeAsString()
111     {
112         return elapsedTimeAsString( getElapsed() );
113     }
114 
115     String elapsedTimeAsString( long runTime )
116     {
117         return ReporterUtils.formatElapsedTime( runTime );
118     }
119 
120     public String getReportName()
121     {
122         final int i = getName().lastIndexOf( "(" );
123         return i > 0 ? getName().substring( 0, i ) : getName();
124     }
125 
126     public String getReportName( String suffix )
127     {
128         return suffix != null && suffix.length() > 0 ? getReportName() + "(" + suffix + ")" : getReportName();
129     }
130 
131     public String getOutput( boolean trimStackTrace )
132     {
133         return getElapsedTimeSummary() + "  <<< " + getReportEntryType().toString().toUpperCase() + "!" + NL
134             + getStackTrace( trimStackTrace );
135     }
136 
137     public String getElapsedTimeVerbose()
138     {
139         return "Time elapsed: " + elapsedTimeAsString() + " sec";
140     }
141 
142     public String getElapsedTimeSummary()
143     {
144         return getName() + "  " + getElapsedTimeVerbose();
145     }
146 
147     public boolean isErrorOrFailure()
148     {
149         ReportEntryType thisType = getReportEntryType();
150         return ReportEntryType.FAILURE == thisType || ReportEntryType.ERROR == thisType;
151     }
152 
153     public boolean isSkipped()
154     {
155         return ReportEntryType.SKIPPED == getReportEntryType();
156     }
157 
158     public boolean isSucceeded()
159     {
160         return ReportEntryType.SUCCESS == getReportEntryType();
161     }
162 
163     public String getNameWithGroup()
164     {
165         return original.getNameWithGroup();
166     }
167 }