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.
Merge pull request #25 from habast/jenkins-Pep8Parser
[FIXED JENKINS-17791] Added native Pep8 parser.
- Loading branch information
Showing
6 changed files
with
170 additions
and
41 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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> |
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
62 changes: 62 additions & 0 deletions
62
src/main/java/hudson/plugins/warnings/parser/Pep8Parser.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,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; | ||
} | ||
} | ||
} | ||
|
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
59 changes: 59 additions & 0 deletions
59
src/test/java/hudson/plugins/warnings/parser/Pep8ParserTest.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,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"; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/hudson/plugins/warnings/parser/pep8Test.txt
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,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|?. |