This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-14018] Added new parser for C++ Lint.
- Loading branch information
Showing
4 changed files
with
1,159 additions
and
5 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/hudson/plugins/warnings/parser/CppLintParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package hudson.plugins.warnings.parser; | ||
|
||
import hudson.Extension; | ||
import hudson.plugins.analysis.util.model.Priority; | ||
|
||
import java.util.regex.Matcher; | ||
|
||
/** | ||
* A parser for the ant javac compiler warnings. | ||
* | ||
* @author Ulli Hafner | ||
*/ | ||
@Extension | ||
public class CppLintParser extends RegexpLineParser { | ||
private static final long serialVersionUID = 1737791073711198075L; | ||
private static final String PATTERN = "^\\s*(.*)\\s*\\((\\d*)\\):\\s*(.*)\\s*\\[(.*)\\] \\[(.*)\\]$"; | ||
|
||
/** | ||
* Creates a new instance of {@link CppLintParser}. | ||
*/ | ||
public CppLintParser() { | ||
super(Messages._Warnings_CppLint_ParserName(), | ||
Messages._Warnings_CppLint_LinkName(), | ||
Messages._Warnings_CppLint_TrendName(), | ||
PATTERN); | ||
} | ||
|
||
@Override | ||
protected Warning createWarning(final Matcher matcher) { | ||
Priority priority = mapPriority(matcher.group(5)); | ||
|
||
return createWarning(matcher.group(1), getLineNumber(matcher.group(2)), matcher.group(4), matcher.group(3), priority); | ||
} | ||
|
||
private Priority mapPriority(final String priority) { | ||
int value = getLineNumber(priority); | ||
if (value >= 5) { | ||
return Priority.HIGH; | ||
} | ||
if (value >= 3) { | ||
return Priority.NORMAL; | ||
} | ||
return Priority.LOW; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/hudson/plugins/warnings/parser/CppLintParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package hudson.plugins.warnings.parser; | ||
|
||
import static junit.framework.Assert.*; | ||
import hudson.plugins.analysis.core.ParserResult; | ||
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; | ||
|
||
/** | ||
* Tests the class {@link CppLintParser}. | ||
* | ||
* @author Ulli Hafner | ||
*/ | ||
public class CppLintParserTest extends ParserTester { | ||
/** {@inheritDoc} */ | ||
@Override | ||
protected String getWarningsFile() { | ||
return "cpplint.txt"; | ||
} | ||
|
||
/** | ||
* Parses a file with 1031 warnings. | ||
* | ||
* @throws IOException | ||
* if the file could not be read | ||
*/ | ||
@Test | ||
public void testParser() throws IOException { | ||
Collection<FileAnnotation> warnings = new CppLintParser().parse(openFile()); | ||
|
||
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1031, warnings.size()); | ||
|
||
ParserResult result = new ParserResult(warnings); | ||
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 81, result.getNumberOfAnnotations(Priority.HIGH)); | ||
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 201, result.getNumberOfAnnotations(Priority.NORMAL)); | ||
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 749, result.getNumberOfAnnotations(Priority.LOW)); | ||
|
||
Iterator<FileAnnotation> iterator = warnings.iterator(); | ||
FileAnnotation annotation = iterator.next(); | ||
checkWarning(annotation, | ||
824, | ||
"Tab found; better to use spaces", | ||
"c:/Workspace/Trunk/Project/P1/class.cpp", | ||
"whitespace/tab", Priority.LOW); | ||
} | ||
} | ||
|
Oops, something went wrong.
888b0dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jenkins » warnings-plugin #53 FAILURE
Looks like this commit caused a build failure
(what's this?)