Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[FIXED JENKINS-14018] Added new parser for C++ Lint.
  • Loading branch information
uhafner committed Jun 19, 2012
1 parent 40118da commit 888b0dc8a090e1d7d6b2d9a1d18ae05250bed7e4
@@ -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;
}
}

@@ -1,7 +1,6 @@
package hudson.plugins.warnings.parser;

import hudson.plugins.violations.types.codenarc.CodenarcParser;
import hudson.plugins.violations.types.cpplint.CppLintParser;
import hudson.plugins.violations.types.csslint.CssLintParser;
import hudson.plugins.violations.types.fxcop.FxCopParser;
import hudson.plugins.violations.types.gendarme.GendarmeParser;
@@ -28,10 +27,6 @@ public static void addParsers(final List<AbstractWarningsParser> parsers) {
Messages._Warnings_Codenarc_ParserName(),
Messages._Warnings_Codenarc_LinkName(),
Messages._Warnings_Codenarc_TrendName()));
parsers.add(new ViolationsAdapter(new CppLintParser(),
Messages._Warnings_CppLint_ParserName(),
Messages._Warnings_CppLint_LinkName(),
Messages._Warnings_CppLint_TrendName()));
parsers.add(new ViolationsAdapter(new CssLintParser(),
Messages._Warnings_CssLint_ParserName(),
Messages._Warnings_CssLint_LinkName(),
@@ -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);
}
}

1 comment on commit 888b0dc

@buildhive
Copy link

@buildhive buildhive commented on 888b0dc Jun 19, 2012

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?)

Please sign in to comment.