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

Commit

Permalink
Merge pull request #25 from habast/jenkins-Pep8Parser
Browse files Browse the repository at this point in the history
[FIXED JENKINS-17791] Added native Pep8 parser.
  • Loading branch information
uhafner committed Jun 18, 2013
2 parents d958f11 + 0afd582 commit 233085d
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 41 deletions.
69 changes: 34 additions & 35 deletions .classpath
@@ -1,35 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/localizer">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/localizer">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,4 @@
<<<<<<< HEAD
eclipse.preferences.version=1
encoding//src/main/java=ISO-8859-1
encoding//src/main/resources=ISO-8859-1
Expand All @@ -6,3 +7,13 @@ encoding//src/test/resources=ISO-8859-1
encoding//src/test/resources/hudson/plugins/warnings/parser/issue7178.txt=UTF-8
encoding//target/generated-sources/localizer=ISO-8859-1
encoding/<project>=ISO-8859-1
=======
eclipse.preferences.version=1
encoding//src/main/java=ISO-8859-1
encoding//src/main/resources=ISO-8859-1
encoding//src/test/java=ISO-8859-1
encoding//src/test/resources=ISO-8859-1
encoding//src/test/resources/hudson/plugins/warnings/parser/issue7178.txt=UTF-8
encoding//target/generated-sources/localizer=ISO-8859-1
encoding/<project>=ISO-8859-1
>>>>>>> branch 'master' of https://github.com/habast/warnings-plugin.git
62 changes: 62 additions & 0 deletions src/main/java/hudson/plugins/warnings/parser/Pep8Parser.java
@@ -0,0 +1,62 @@
package hudson.plugins.warnings.parser;

import java.util.regex.Matcher;

import hudson.Extension;

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

/**
* A parser for the Pep8 Compiler warning.
*
* @author Marvin Schütz
*/
@Extension
public class Pep8Parser extends RegexpLineParser {
private static final long serialVersionUID = -8444940209330966997L;
private static final String PEP8_WARNING_PATTERN = "(.*):(\\d+):\\d+: (\\D\\d*) (.*)";

/**
* Creates a new instance of {@link Pep8Parser}.
*/
public Pep8Parser() {
super(Messages._Warnings_Pep8_ParserName(),
Messages._Warnings_Pep8_LinkName(),
Messages._Warnings_Pep8_TrendName(),
PEP8_WARNING_PATTERN, true);
}

@Override
protected Warning createWarning(final Matcher matcher) {
String message = matcher.group(4);
String category = classifyIfEmpty(matcher.group(3), message);

return createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, message, mapPriority(category));
}

@Override
protected boolean isLineInteresting(final String line) {
return line.contains("E") || line.contains("W") || line.contains("F") ||
line.contains("R") || line.contains("C");
}

/**
* Determined the Priority of the Warning.
*
* @param priority
* the Warningcode
* @return the Priority of the Warning
*/
private Priority mapPriority(final String priority) {
if(priority.contains("F") || priority.contains("E") || priority.contains("W")){
return Priority.HIGH;
}
else if(priority.contains("R")){
return Priority.NORMAL;
}
else{
return Priority.LOW;
}
}
}

Expand Up @@ -5,7 +5,6 @@
import hudson.plugins.violations.types.codenarc.CodenarcParser;
import hudson.plugins.violations.types.csslint.CssLintParser;
import hudson.plugins.violations.types.gendarme.GendarmeParser;
import hudson.plugins.violations.types.pep8.Pep8Parser;
import hudson.plugins.violations.types.stylecop.StyleCopParser;

/**
Expand Down Expand Up @@ -34,11 +33,6 @@ public static void addParsers(final List<AbstractWarningsParser> parsers) {
Messages._Warnings_Gendarme_ParserName(),
Messages._Warnings_Gendarme_LinkName(),
Messages._Warnings_Gendarme_TrendName()));

parsers.add(new ViolationsAdapter(new Pep8Parser(),
Messages._Warnings_Pep8_ParserName(),
Messages._Warnings_Pep8_LinkName(),
Messages._Warnings_Pep8_TrendName()));
parsers.add(new ViolationsAdapter(new StyleCopParser(),
Messages._Warnings_StyleCop_ParserName(),
Messages._Warnings_StyleCop_LinkName(),
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/hudson/plugins/warnings/parser/Pep8ParserTest.java
@@ -0,0 +1,59 @@
package hudson.plugins.warnings.parser;

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

import org.junit.Test;

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

/**
* Tests the class {@link Pep8parser}}.
*
* @author Marvin Schütz
*/
public class Pep8ParserTest extends ParserTester {
private static final String WARNING_TYPE = "Pep8";

/**
* Parses a Testfile with a simple and a complexe Warning and 2 complexe Warnings with lower Priority.
*
* @throws IOException
* falls das File nicht geoeffnet werden kann
*/
@Test
public void testParseSimpleAndComplexMessage() throws IOException {
Pep8Parser parser = new Pep8Parser();

Collection<FileAnnotation> warnings = parser.parse(openFile());
Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation warning = iterator.next();

checkWarning(warning, 1, "trailing whitespace", "trunk/src/python/file.py",
WARNING_TYPE, "W291", Priority.HIGH);

warning = iterator.next();

checkWarning(warning, 98, "Message #has! 12special-_ chars|?.",
"trunk/src/python/file.py", WARNING_TYPE, "E111", Priority.HIGH);

warning = iterator.next();

checkWarning(warning, 98, "Message #has! 12special-_ chars|?.",
"trunk2/src/python/file.py", WARNING_TYPE, "R111", Priority.NORMAL);

warning = iterator.next();

checkWarning(warning, 98, "Message #has! 12special-_ chars|?.",
"trunk3/src/python/file.py", WARNING_TYPE, "C111", Priority.LOW);
}


/** {@inheritDoc} */
@Override
protected String getWarningsFile() {
return "pep8Test.txt";
}
}
@@ -0,0 +1,4 @@
trunk/src/python/file.py:1:2: W291 trailing whitespace
trunk/src/python/file.py:98:11: E111 Message #has! 12special-_ chars|?.
trunk2/src/python/file.py:98:11: R111 Message #has! 12special-_ chars|?.
trunk3/src/python/file.py:98:11: C111 Message #has! 12special-_ chars|?.

0 comments on commit 233085d

Please sign in to comment.