1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.log4j.util;
19  
20  import org.apache.oro.text.perl.Perl5Util;
21  
22  
23  public class EnhancedJunitTestRunnerFilter implements Filter {
24    private Perl5Util util = new Perl5Util();
25  
26    private static final String[] PATTERNS = {
27            "at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
28            "at org.apache.tools.ant",
29            "at junit.textui.TestRunner",
30            "at com.intellij.rt.execution.junit",
31            "at java.lang.reflect.Method.invoke",
32            "at org.apache.maven.",
33            "at org.codehaus.",
34  		    "at org.junit.internal.runners.",
35  		    "at junit.framework.JUnit4TestAdapter"
36    };
37  
38    public EnhancedJunitTestRunnerFilter() {
39    }
40  
41    /**
42     * Filter out stack trace lines coming from the various JUnit TestRunners.
43     */
44    public String filter(String in) {
45      if (in == null) {
46        return null;
47      }
48  
49        //
50        //  restore the one instance of Method.invoke that we actually want
51        //
52      if (in.indexOf("at junit.framework.TestCase.runTest") != -1) {
53          return "\tat java.lang.reflect.Method.invoke(X)\n\t" + in.trim();
54      }
55  
56      for (int i = 0; i < PATTERNS.length; i++) {
57          if(in.indexOf(PATTERNS[i]) != -1) {
58              return null;
59          }
60      }
61      if (util.match("/\\sat /", in)) {
62         return "\t" + in.trim();
63      }
64      return in;
65    }
66  }