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
[JENKINS-13969] Update of regexp to support Eclipse 3.8 warnings.
  • Loading branch information
uhafner committed Jun 11, 2012
1 parent 57d20b5 commit 0a999e4
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 51 deletions.
15 changes: 11 additions & 4 deletions src/main/java/hudson/plugins/warnings/parser/EclipseParser.java
Expand Up @@ -15,7 +15,7 @@
@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+)\\).*(?:\\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[^\\^]*)+(?:\\r?\\n(.*)([\\^]+).*)\\r?\\n(?:\\s*\\[.*\\]\\s*)?(.*)";

/**
* Creates a new instance of {@link EclipseParser}.
Expand Down Expand Up @@ -52,13 +52,20 @@ protected Warning createWarning(final Matcher matcher) {
else {
priority = Priority.HIGH;
}
Warning warning = createWarning(matcher.group(2), getLineNumber(matcher.group(3)), matcher.group(6), priority);
Warning warning = createWarning(matcher.group(2), getLineNumber(getLine(matcher)), matcher.group(7), priority);

int columnStart = StringUtils.defaultString(matcher.group(4)).length();
int columnEnd = columnStart + matcher.group(5).length();
int columnStart = StringUtils.defaultString(matcher.group(5)).length();
int columnEnd = columnStart + matcher.group(6).length();
warning.setColumnPosition(columnStart, columnEnd);

return warning;
}

private String getLine(final Matcher matcher) {
String eclipse34 = matcher.group(3);
String eclipse38 = matcher.group(4);

return StringUtils.defaultIfEmpty(eclipse34, eclipse38);
}
}

@@ -0,0 +1,62 @@
package hudson.plugins.warnings.parser;

import static junit.framework.Assert.*;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.Priority;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import org.junit.Test;

/**
* Basic tests for the Eclipse parser.
*
* @author Ulli Hafner
*/
public abstract class AbstractEclipseParserTest extends ParserTester {
/**
* Creates the parser under test.
*
* @return the created parser
*/
protected AbstractWarningsParser createParser() {
return new EclipseParser();
}

/**
* Returns the type of the parser.
*
* @return the type of the parser
*/
protected String getType() {
return new EclipseParser().getGroup();
}

@Override
protected String getWarningsFile() {
return "eclipse.txt";
}

/**
* Parses a file with two deprecation warnings.
*
* @throws IOException
* if the file could not be read
*/
@Test
public void parseDeprecation() throws IOException {
Collection<FileAnnotation> warnings = createParser().parse(openFile());

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

Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
3,
"The serializable class AttributeException does not declare a static final serialVersionUID field of type long",
"C:/Desenvolvimento/Java/jfg/src/jfg/AttributeException.java",
getType(), "", Priority.NORMAL);
}
}
Expand Up @@ -7,7 +7,7 @@
*
* @author Ulli Hafner
*/
public class DynamicDocumentParserTest extends EclipseParserTest {
public class DynamicDocumentParserTest extends AbstractEclipseParserTest {
private static final String TYPE = "Eclipse Dynamic";

@Override
Expand Down
81 changes: 35 additions & 46 deletions src/test/java/hudson/plugins/warnings/parser/EclipseParserTest.java
Expand Up @@ -18,7 +18,41 @@
/**
* Tests the class {@link EclipseParser}.
*/
public class EclipseParserTest extends ParserTester {
public class EclipseParserTest extends AbstractEclipseParserTest {
/**
* Parses a warning log with 2 previously undetected warnings.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-13696">Issue 13696</a>
*/
@Test
public void issue13969() throws IOException {
Collection<FileAnnotation> warnings = createParser().parse(openFile("issue13969.txt"));

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

ParserResult result = new ParserResult(warnings);
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 3, result.getNumberOfAnnotations());

Iterator<FileAnnotation> iterator = warnings.iterator();
checkWarning(iterator.next(),
369,
"The method compare(List<String>, List<String>) from the type PmModelImporter is never used locally",
"/media/ssd/multi-x-processor/workspace/msgPM_Access/com.faktorzehn.pa2msgpm.core/src/com/faktorzehn/pa2msgpm/core/loader/PmModelImporter.java",
getType(), "", Priority.NORMAL);
checkWarning(iterator.next(),
391,
"The method getTableValues(PropertyRestrictionType) from the type PmModelImporter is never used locally",
"/media/ssd/multi-x-processor/workspace/msgPM_Access/com.faktorzehn.pa2msgpm.core/src/com/faktorzehn/pa2msgpm/core/loader/PmModelImporter.java",
getType(), "", Priority.NORMAL);
checkWarning(iterator.next(),
56,
"The value of the field PropertyImporterTest.ERROR_RESPONSE is not used",
"/media/ssd/multi-x-processor/workspace/msgPM_Access/com.faktorzehn.pa2msgpm.core.test/src/com/faktorzehn/pa2msgpm/core/importer/PropertyImporterTest.java",
getType(), "", Priority.NORMAL);
}

/**
* Parses a warning log with 15 warnings.
*
Expand Down Expand Up @@ -80,45 +114,6 @@ public void issue6427() throws IOException {
getType(), "", Priority.NORMAL);
}

/**
* Creates the parser under test.
*
* @return the created parser
*/
protected AbstractWarningsParser createParser() {
return new EclipseParser();
}

/**
* Parses a file with two deprecation warnings.
*
* @throws IOException
* if the file could not be read
*/
@Test
public void parseDeprecation() throws IOException {
Collection<FileAnnotation> warnings = createParser().parse(openFile());

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

Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
3,
"The serializable class AttributeException does not declare a static final serialVersionUID field of type long",
"C:/Desenvolvimento/Java/jfg/src/jfg/AttributeException.java",
getType(), "", Priority.NORMAL);
}

/**
* Returns the type of the parser.
*
* @return the type of the parser
*/
protected String getType() {
return new EclipseParser().getGroup();
}

/**
* Parses a warning log with 2 eclipse messages, the affected source text spans one and two lines.
*
Expand Down Expand Up @@ -168,11 +163,5 @@ public void issue7077all() throws IOException {
number++;
}
}


@Override
protected String getWarningsFile() {
return "eclipse.txt";
}
}

17 changes: 17 additions & 0 deletions src/test/resources/hudson/plugins/warnings/parser/issue13969.txt
@@ -0,0 +1,17 @@
[INFO] Compiling 5 source files to /media/ssd/multi-x-processor/workspace/msgPM_Access/com.faktorzehn.pa2msgpm.core/target/classes
[WARNING] /media/ssd/multi-x-processor/workspace/msgPM_Access/com.faktorzehn.pa2msgpm.core/src/com/faktorzehn/pa2msgpm/core/loader/PmModelImporter.java:[369,0]
private boolean compare(List<String> rowTableValues, List<String> allowedValues) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method compare(List<String>, List<String>) from the type PmModelImporter is never used locally
[WARNING] /media/ssd/multi-x-processor/workspace/msgPM_Access/com.faktorzehn.pa2msgpm.core/src/com/faktorzehn/pa2msgpm/core/loader/PmModelImporter.java:[391,0]
private List<String> getTableValues(PropertyRestrictionType restrictionType) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method getTableValues(PropertyRestrictionType) from the type PmModelImporter is never used locally
2 problems (2 warnings)


[WARNING] /media/ssd/multi-x-processor/workspace/msgPM_Access/com.faktorzehn.pa2msgpm.core.test/src/com/faktorzehn/pa2msgpm/core/importer/PropertyImporterTest.java:[56,0]
private static final OperationResponseType ERROR_RESPONSE = new OperationResponseType(1, "ERROR");
^^^^^^^^^^^^^^
The value of the field PropertyImporterTest.ERROR_RESPONSE is not used
1 problem (1 warning)

0 comments on commit 0a999e4

Please sign in to comment.