Author: carnold
Date: Wed Aug 15 15:15:39 2007
New Revision: 566357
URL: http://svn.apache.org/viewvc?view=rev&rev=566357
Log:
Bug 42099: Migrate ExpressionFilter from oro to java.util.regex
Modified:
logging/log4j/companions/extras/trunk/pom.xml
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rule/LikeRule.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ControlFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ISO8601Filter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/LineNumberFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/SunReflectFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLDateFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java
Modified: logging/log4j/companions/extras/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/pom.xml?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
--- logging/log4j/companions/extras/trunk/pom.xml (original)
+++ logging/log4j/companions/extras/trunk/pom.xml Wed Aug 15 15:15:39 2007
@@ -214,11 +214,6 @@
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>
- <dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- <version>2.0.8</version>
- </dependency>
</dependencies>
<reporting>
Modified:
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rule/LikeRule.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rule/LikeRule.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rule/LikeRule.java
(original)
+++
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rule/LikeRule.java
Wed Aug 15 15:15:39 2007
@@ -17,15 +17,14 @@
package org.apache.log4j.rule;
-import java.io.IOException;
-import java.util.Stack;
-
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.LoggingEventFieldResolver;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
+
+import java.io.IOException;
+import java.util.Stack;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
/**
* A Rule class providing support for ORO-based regular expression syntax.
@@ -50,7 +49,7 @@
/**
* Regular expression matcher.
*/
- private transient Perl5Matcher matcher = new Perl5Matcher();
+ private transient Matcher matcher = null;
/**
* Field.
*/
@@ -96,24 +95,26 @@
* @return new instance
*/
public static Rule getRule(final String field, final String pattern) {
- Perl5Compiler compiler = new Perl5Compiler();
- Pattern pattern1 = null;
-
try {
- pattern1 = compiler.compile(pattern,
Perl5Compiler.CASE_INSENSITIVE_MASK);
- } catch (MalformedPatternException e) {
+ return new LikeRule(field, Pattern.compile(pattern,
Pattern.CASE_INSENSITIVE));
+ } catch (PatternSyntaxException e) {
throw new IllegalArgumentException(
"Invalid LIKE rule - " + e.getMessage());
}
-
- return new LikeRule(field, pattern1);
}
/** [EMAIL PROTECTED] */
public boolean evaluate(final LoggingEvent event) {
Object input = RESOLVER.getValue(field, event);
- return ((input != null) && (pattern != null)
- && (matcher.matches(input.toString(), pattern)));
+ if((input != null) && (pattern != null)) {
+ if (matcher == null) {
+ matcher = pattern.matcher(input.toString());
+ } else {
+ matcher.reset(input.toString());
+ }
+ return matcher.matches();
+ }
+ return false;
}
/**
@@ -129,11 +130,8 @@
try {
field = (String) in.readObject();
String patternString = (String) in.readObject();
- Perl5Compiler compiler = new Perl5Compiler();
- matcher = new Perl5Matcher();
- pattern = compiler.compile(patternString,
- Perl5Compiler.CASE_INSENSITIVE_MASK);
- } catch (MalformedPatternException e) {
+ pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
+ } catch (PatternSyntaxException e) {
throw new IOException("Invalid LIKE rule - " + e.getMessage());
}
}
@@ -148,6 +146,6 @@
private void writeObject(final java.io.ObjectOutputStream out)
throws IOException {
out.writeObject(field);
- out.writeObject(pattern.getPattern());
+ out.writeObject(pattern.pattern());
}
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,18 +17,20 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Pattern;
public class AbsoluteDateAndTimeFilter implements Filter {
- Perl5Util util = new Perl5Util();
+ private final Pattern pattern;
+
+ public AbsoluteDateAndTimeFilter() {
+ pattern = Pattern.compile(Filter.ABSOLUTE_DATE_AND_TIME_PAT);
+ }
public String filter(String in) {
- String pat = "/" + Filter.ABSOLUTE_DATE_AND_TIME_PAT + "/";
- if (util.match(pat, in)) {
- return util.substitute(
- "s/" + Filter.ABSOLUTE_DATE_AND_TIME_PAT + "//", in);
+ if (pattern.matcher(in).find()) {
+ return pattern.matcher(in).replaceAll("");
} else {
return in;
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,16 +17,18 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class AbsoluteTimeFilter implements Filter {
- Perl5Util util = new Perl5Util();
public String filter(String in) {
- String pat = "/" + Filter.ABSOLUTE_TIME_PAT + "/";
+ String pat = Filter.ABSOLUTE_TIME_PAT;
- if (util.match(pat, in)) {
- return util.substitute("s/" + Filter.ABSOLUTE_TIME_PAT + "//", in);
+ Pattern pattern = Pattern.compile(pat);
+ Matcher matcher = pattern.matcher(in);
+ if (matcher.find()) {
+ return matcher.replaceAll("");
} else {
return in;
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ControlFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ControlFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ControlFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ControlFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,11 +17,10 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Pattern;
public class ControlFilter implements Filter {
- Perl5Util util = new Perl5Util();
String[] allowedPatterns;
public ControlFilter(String[] allowedPatterns) {
@@ -32,10 +31,8 @@
int len = allowedPatterns.length;
for (int i = 0; i < len; i++) {
- //System.out.println("["+allowedPatterns[i]+"]");
- if (util.match("/" + allowedPatterns[i] + "/", in)) {
- //System.out.println("["+in+"] matched ["+allowedPatterns[i]);
- return in;
+ if (Pattern.compile(allowedPatterns[i]).matcher(in).find()) {
+ return in;
}
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ISO8601Filter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ISO8601Filter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ISO8601Filter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/ISO8601Filter.java
Wed Aug 15 15:15:39 2007
@@ -17,17 +17,19 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.*;
public class ISO8601Filter implements Filter {
- Perl5Util util = new Perl5Util();
+ private final Pattern pattern;
- public String filter(String in) {
- String pat = "/" + ISO8601_PAT + "/";
+ public ISO8601Filter() {
+ pattern = Pattern.compile(ISO8601_PAT);
+ }
- if (util.match(pat, in)) {
- return util.substitute("s/" + ISO8601_PAT + "//", in);
+ public String filter(String in) {
+ if (pattern.matcher(in).find()) {
+ return pattern.matcher(in).replaceAll("");
} else {
return in;
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,22 +17,30 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Pattern;
public class JunitTestRunnerFilter implements Filter {
- Perl5Util util = new Perl5Util();
- private static final String[] patterns = {
- "/at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner/",
- "/at org.apache.tools.ant/",
- "/at junit.textui.TestRunner/",
- "/at com.intellij.rt.execution.junit/",
- "/at java.lang.reflect.Method.invoke/",
- "/at org.apache.maven./",
- "/at org.codehaus./",
- "/at org.junit.internal.runners./"
+ private static final String[] PATTERNS = {
+ "at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "at org.apache.tools.ant",
+ "at junit.textui.TestRunner",
+ "at com.intellij.rt.execution.junit",
+ "at java.lang.reflect.Method.invoke",
+ "at org.apache.maven.",
+ "at org.codehaus.",
+ "at org.junit.internal.runners."
};
+ private final Pattern[] patterns;
+
+ public JunitTestRunnerFilter() {
+ patterns = new Pattern[PATTERNS.length];
+ for (int i = 0; i < PATTERNS.length; i++) {
+ patterns[i] = Pattern.compile(PATTERNS[i]);
+ }
+
+ }
/**
* Filter out stack trace lines coming from the various JUnit TestRunners.
@@ -45,12 +53,12 @@
//
// restore the one instance of Method.invoke that we actually want
//
- if (util.match("/at junit.framework.TestCase.runTest/", in)) {
+ if (in.indexOf("at junit.framework.TestCase.runTest") != -1) {
return "\tat java.lang.reflect.Method.invoke(X)\n" + in;
}
for (int i = 0; i < patterns.length; i++) {
- if(util.match(patterns[i], in)) {
+ if(patterns[i].matcher(in).find()) {
return null;
}
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/LineNumberFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/LineNumberFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/LineNumberFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/LineNumberFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,17 +17,24 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Pattern;
public class LineNumberFilter implements Filter {
- Perl5Util util = new Perl5Util();
+ private Pattern linePattern;
+ private Pattern nativePattern;
- public String filter(String in) {
- if (util.match("/\\(.*:\\d{1,4}\\)/", in)) {
- return util.substitute("s/\\(.*:\\d{1,4}\\)/\\(X\\)/", in);
- } else if (util.match("/\\(Native Method\\)/", in)) {
- return util.substitute("s/\\(Native Method\\)/\\(X\\)/", in);
+ public LineNumberFilter() {
+ linePattern = Pattern.compile("\\(.*:\\d{1,4}\\)");
+ nativePattern = Pattern.compile("\\(Native Method\\)");
+ }
+
+ public String filter(final String in) {
+
+ if (linePattern.matcher(in).find()) {
+ return linePattern.matcher(in).replaceAll("(X)");
+ } else if (nativePattern.matcher(in).find()) {
+ return nativePattern.matcher(in).replaceAll("(X)");
} else {
return in;
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,18 +17,19 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Pattern;
public class RelativeTimeFilter implements Filter {
- Perl5Util util = new Perl5Util();
+ private final Pattern relativePattern;
- public String filter(String in) {
- String pat = "/" + Filter.RELATIVE_TIME_PAT + "/";
+ public RelativeTimeFilter() {
+ relativePattern = Pattern.compile(Filter.RELATIVE_TIME_PAT);
+ }
- if (util.match(pat, in)) {
- //System.out.println("Removing relative time from line ["+in+"]");
- return util.substitute("s/" + Filter.RELATIVE_TIME_PAT + "//", in);
+ public String filter(String in) {
+ if (relativePattern.matcher(in).find()) {
+ return relativePattern.matcher(in).replaceAll("");
} else {
return in;
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/SunReflectFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/SunReflectFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/SunReflectFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/SunReflectFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,21 +17,18 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
-
/**
* The sun.reflect.* lines are not present in all JDKs.
*
* @author Ceki Gulcu
*/
public class SunReflectFilter implements Filter {
- Perl5Util util = new Perl5Util();
public String filter(String in) {
if(in == null) {
return null;
}
- if (util.match("/at sun.reflect/", in)) {
+ if (in.indexOf("at sun.reflect") != -1) {
return null;
} else {
return in;
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLDateFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLDateFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLDateFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLDateFilter.java
Wed Aug 15 15:15:39 2007
@@ -16,19 +16,20 @@
*/
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Pattern;
public class XMLDateFilter implements Filter {
- private Perl5Util util = new Perl5Util();
private final static String PATTERN =
- "/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}/";
+ "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}";
+ private final Pattern pattern;
public XMLDateFilter() {
+ pattern = Pattern.compile(PATTERN);
}
public String filter(final String in) {
- if (in != null && util.match(PATTERN, in)) {
- return util.substitute("s" + PATTERN + "yyyy-MM-ddTHH:mm:ss.SSS/", in);
+ if (in != null && pattern.matcher(in).find()) {
+ return pattern.matcher(in).replaceAll("yyyy-MM-ddTHH:mm:ss.SSS");
} else {
return in;
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,22 +17,19 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
-
+import java.util.regex.Pattern;
public class XMLLineAttributeFilter implements Filter {
- Perl5Util util = new Perl5Util();
- public String filter(String in) {
+ public String filter(final String in) {
if(in == null) {
return null;
}
- if (util.match("/line=\"\\d{1,3}\"/", in)) {
- return util.substitute("s/line=\"\\d{1,3}\"/line=\"X\"/", in);
- } else if (util.match("/line=\"?\"/", in)) {
- return util.substitute("s/line=\"?\"/line=\"X\"/", in);
- } else {
- return in;
+ if (Pattern.compile("line=\"\\d{1,3}\"").matcher(in).find()) {
+ return
Pattern.compile("line=\"\\d{1,3}\"").matcher(in).replaceAll("line=\"X\"");
+ } else if (Pattern.compile("line=\"?\"").matcher(in).find()) {
+ return
Pattern.compile("line=\"?\"").matcher(in).replaceAll("line=\"X\"");
}
+ return in;
}
}
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java?view=diff&rev=566357&r1=566356&r2=566357
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java
Wed Aug 15 15:15:39 2007
@@ -17,19 +17,20 @@
package org.apache.log4j.util;
-import org.apache.oro.text.perl.Perl5Util;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class XMLTimestampFilter implements Filter {
- Perl5Util util = new Perl5Util();
public String filter(String in) {
if(in == null) {
return null;
}
- if (util.match("/timestamp=\"\\d{10,13}\"/", in)) {
- return util.substitute(
- "s/timestamp=\"\\d{10,13}\"/timestamp=\"XXX\"/", in);
+ Pattern pattern = Pattern.compile("timestamp=\"\\d{10,13}\"");
+ Matcher matcher = pattern.matcher(in);
+ if (matcher.find()) {
+ return matcher.replaceAll("timestamp=\"XXX\"");
} else {
return in;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]