Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[JENKINS-27664] Better Performance of EclipseParser.
Browse files Browse the repository at this point in the history
Tune the regular expression used in the EclipseParser to not backtrack
through the whole log output.
  • Loading branch information
TobiX committed Mar 10, 2016
1 parent 6b50ca1 commit 167f35f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Expand Up @@ -8,6 +8,7 @@

import hudson.plugins.analysis.util.model.Priority;


/**
* A parser for Eclipse compiler warnings.
*
Expand All @@ -16,7 +17,11 @@
@Extension
public class EclipseParser extends RegexpDocumentParser {
private static final long serialVersionUID = 425883472788422955L;
private static final String ANT_ECLIPSE_WARNING_PATTERN = "\\[?(WARNING|ERROR)\\]?\\s*(?:in)?\\s*(.*)(?:\\(at line\\s*(\\d+)\\)|:\\[(\\d+)).*(?:\\r?\\n[^\\^]*)+(?:\\r?\\n(.*)([\\^]+).*)\\r?\\n(?:\\s*\\[.*\\]\\s*)?(.*)";
private static final String ANT_ECLIPSE_WARNING_PATTERN =
"\\[?(WARNING|ERROR)\\]?\\s*(?:in)?\\s*(.*)(?:\\(at line\\s*(\\d+)\\)|:\\[(\\d+)).*" +
"(?:\\r?\\n[^\\^\\n]*){1,3}" +
"\\r?\\n(.*)([\\^]+).*" +
"\\r?\\n(?:\\s*\\[.*\\]\\s*)?(.*)";

/**
* Creates a new instance of {@link EclipseParser}.
Expand Down
Expand Up @@ -188,5 +188,20 @@ public void issue7077all() throws IOException {
number++;
}
}

/**
* Parses a warning log which doesn't contain any Eclipse warnings, but
* shows some pretty bad performance when matching the regular expression.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-27664">Issue 27664</a>
*/
@Test(timeout = 10000)
public void issue27664() throws IOException {
Collection<FileAnnotation> warnings = createParser().parse(openFile("issue27664.txt"));

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 0, warnings.size());
}
}

20 changes: 20 additions & 0 deletions src/test/resources/hudson/plugins/warnings/parser/issue27664.txt
@@ -0,0 +1,20 @@
[WARNING] xxx.java:[226,37] [deprecation] getBoolean(String,boolean) in Sample has been deprecated
[WARNING] xxx.java:[228,37] [deprecation] getBoolean(String,boolean) in Sample has been deprecated
[WARNING] xxx.java:[230,37] [deprecation] getBoolean(String,boolean) in Sample has been deprecated
[WARNING] xxx.java:[232,37] [deprecation] getBoolean(String,boolean) in Sample has been deprecated
[WARNING] xxx.java:[186,48] [deprecation] getString(String,String) in Sample has been deprecated
[WARNING] xxx.java:[343,66] [deprecation] getInt(String,int) in Sample has been deprecated
[WARNING] xxx.java:[36,35] [deprecation] getString(String,String) in Sample has been deprecated
[WARNING] xxx.java:[39,35] [deprecation] getString(String,String) in Sample has been deprecated
[WARNING] xxx.java:[34,33] [deprecation] getString(String,String) in Sample has been deprecated
[WARNING] xxx.java:[27,47] [deprecation] Sample2 in com.example has been deprecated
[WARNING] xxx.java:[299,41] [deprecation] getString(String,String) in Sample has been deprecated
[WARNING] xxx.java:[36,48] [deprecation] getString(String,String) in Sample has been deprecated
[WARNING] xxx.java:[23,41] [deprecation] Sample2 in com.example has been deprecated
[WARNING] xxx.java:[91,31] [deprecation] getString(String,String) in Sample has been deprecated
[WARNING] xxx.java:[212,66] [deprecation] add(int,TimeUnit) in Date has been deprecated
[WARNING] xxx.java:[213,68] [deprecation] subtract(int,TimeUnit) in Date has been deprecated
[WARNING] xxx.java:[261,61] [deprecation] subtract(int,TimeUnit) in Date has been deprecated
[WARNING] xxx.java:[324,61] [deprecation] add(int,TimeUnit) in Date has been deprecated
[WARNING] xxx.java:[330,61] [deprecation] add(int,TimeUnit) in Date has been deprecated
[WARNING] xxx.java:[27,48] [deprecation] getString(String,String) in Sample has been deprecated

0 comments on commit 167f35f

Please sign in to comment.