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

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-12482] Improved regular expression of JavaC parser to
support Java 7 compiler format.
  • Loading branch information
uhafner committed Feb 20, 2012
1 parent 82b0b4c commit bf57fb2
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/warnings/parser/JavacParser.java
Expand Up @@ -11,7 +11,7 @@ public class JavacParser extends RegexpLineParser {
/** Warning type of this parser. */
static final String WARNING_TYPE = "Java Compiler";
/** Pattern of javac compiler warnings. */
private static final String JAVAC_WARNING_PATTERN = "^\\[WARNING\\]\\s*(.*):\\[(\\d*)[.,; 0-9]*\\]\\s*(?:\\[(\\w*)\\])?\\s*(.*)$";
private static final String JAVAC_WARNING_PATTERN = "^(?:\\[WARNING\\]\\s+)?(.*):\\[(\\d*)[.,; 0-9]*\\]\\s*(?:\\[(\\w*)\\])?\\s*(.*)$";

/**
* Creates a new instance of <code>JavacParser</code>.
Expand All @@ -23,7 +23,7 @@ public JavacParser() {
/** {@inheritDoc} */
@Override
protected boolean isLineInteresting(final String line) {
return line.contains("[WARNING]");
return line.contains("[");
}

/**
Expand Down
Expand Up @@ -14,6 +14,24 @@
* Tests the class {@link JavacParser}.
*/
public class JavacParserTest extends ParserTester {
/**
* Parses a warning log with 15 warnings.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-12482">Issue 12482</a>
*/
@Test
public void issue12482() throws IOException {
Collection<FileAnnotation> java6 = parse("issue12482-java6.txt");

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 62, java6.size());

Collection<FileAnnotation> java7 = parse("issue12482-java7.txt");

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 62, java7.size());
}

/**
* Parses a file with two deprecation warnings.
*
Expand Down Expand Up @@ -48,7 +66,7 @@ public void parseDeprecation() throws IOException {
*/
@Test
public void parseArrayInDeprecatedMethod() throws IOException {
Collection<FileAnnotation> warnings = new JavacParser().parse(openFile("issue5868.txt"));
Collection<FileAnnotation> warnings = parse("issue5868.txt");

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1, warnings.size());

Expand All @@ -60,6 +78,10 @@ public void parseArrayInDeprecatedMethod() throws IOException {
AntJavacParser.WARNING_TYPE, "Deprecation", Priority.NORMAL);
}

protected Collection<FileAnnotation> parse(final String fileName) throws IOException {
return new JavacParser().parse(openFile(fileName));
}

/** {@inheritDoc} */
@Override
protected String getWarningsFile() {
Expand Down

0 comments on commit bf57fb2

Please sign in to comment.