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 JunitTestRunnerFilter implements Filter {
24    Perl5Util util = new Perl5Util();
25  
26    /**
27     * Filter out stack trace lines coming from the various JUnit TestRunners.
28     */
29    public String filter(String in) {
30      if (in == null) {
31        return null;
32      }
33  
34      if (
35        util.match(
36            "/at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner/", in)) {
37        return null;
38      } else if (
39        util.match(
40            "/at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner/",
41            in)) {
42        return null;
43      } else if (
44        util.match(
45            "/at com.intellij/",
46            in)) {
47        return null;
48      } else if (in.indexOf("at junit.") >= 0 && in.indexOf("ui.TestRunner") >= 0) {
49         return null;
50      } else if (in.indexOf("org.apache.maven") >= 0) {
51         return null;
52      } else if(in.indexOf("junit.internal") >= 0) {
53          return null;
54      } else if(in.indexOf("JUnit4TestAdapter") >= 0) {
55          return null;
56      } else if (util.match("/\\sat /", in)) {
57         return "\t" + in.trim();
58      } else {
59        return in;
60      }
61    }
62  }