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.
Implementet Violations-StyleCopParser as Native-Parser. Implementet Test-File for StyleCopParser.
- Loading branch information
1 parent
8dfc6c0
commit 1d9c7c0
Showing
4 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
src/main/java/hudson/plugins/warnings/parser/stylecop/StyleCopParser.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
38 changes: 38 additions & 0 deletions
38
src/main/java/hudson/plugins/warnings/parser/stylecop/XmlElementUtil.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,38 @@ | ||
package hudson.plugins.warnings.parser.stylecop; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
|
||
//CHECKSTYLE:OFF | ||
@SuppressWarnings({"PMD", "all"}) | ||
public class XmlElementUtil { | ||
|
||
private XmlElementUtil() { | ||
} | ||
|
||
public static List<Element> getNamedChildElements(final Element parent, final String name) { | ||
List<Element> elements = new ArrayList<Element>(); | ||
if (parent != null) { | ||
Node child = parent.getFirstChild(); | ||
while (child != null) { | ||
if ((child.getNodeType() == Node.ELEMENT_NODE) && (child.getNodeName().equals(name))) { | ||
elements.add((Element) child); | ||
} | ||
child = child.getNextSibling(); | ||
} | ||
} | ||
return elements; | ||
} | ||
|
||
public static Element getFirstElementByTagName(final Element parent, final String tagName) { | ||
List<Element> foundElements = getNamedChildElements(parent, tagName); | ||
if (foundElements.size() > 0) { | ||
return foundElements.get(0); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/hudson/plugins/warnings/parser/StyleCopParserTest.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 org.junit.Assert.*; | ||
|
||
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; | ||
import hudson.plugins.warnings.parser.fxcop.FxCopParser; | ||
import hudson.plugins.warnings.parser.stylecop.StyleCopParser; | ||
|
||
/** | ||
* Tests the class {@link FxCopParser}. | ||
* | ||
* @author Ulli Hafner | ||
*/ | ||
public class StyleCopParserTest extends ParserTester { | ||
/** | ||
* Verifies that the StyleCop parser works as expected. | ||
* | ||
* @throws IOException | ||
* if the file could not be read | ||
*/ | ||
@Test | ||
public void testStyleCop() throws IOException { | ||
Collection<FileAnnotation> result = new StyleCopParser().parse(openFile()); | ||
|
||
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 2, result.size()); | ||
|
||
Iterator<FileAnnotation> iterator = result.iterator(); | ||
checkWarning(iterator.next(), 18, | ||
"The call to components must begin with the 'this.' prefix to indicate that the item is a member of the class.", | ||
"Form1.Designer.cs", | ||
"stylecop", | ||
Priority.NORMAL); | ||
checkWarning(iterator.next(), 16, | ||
"The call to components must begin with the 'this.' prefix to indicate that the item is a member of the class.", | ||
"Form1.Designer.cs", | ||
"stylecop", | ||
Priority.NORMAL); | ||
} | ||
|
||
@Override | ||
protected String getWarningsFile() { | ||
return "stylecop.xml"; | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
src/test/resources/hudson/plugins/warnings/parser/stylecop.xml
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,22 @@ | ||
<StyleCopViolations> | ||
<Violation | ||
Section="Root.ListViewProblem.Form1.Dispose%bool" | ||
LineNumber="18" | ||
Source="Form1.Designer.cs" | ||
RuleNamespace="Microsoft.StyleCop.CSharp.ReadabilityRules" | ||
Rule="PrefixLocalCallsWithThis" | ||
RuleId="SA1101"> | ||
The call to components must begin with the 'this.' prefix to indicate that the item is a member of the class. | ||
</Violation> | ||
|
||
|
||
<Violation | ||
Section="Root.ListViewProblem.Form1.Dispose%bool" | ||
LineNumber="16" | ||
Source="Form1.Designer.cs" | ||
RuleNamespace="Microsoft.StyleCop.CSharp.ReadabilityRules" | ||
Rule="PrefixLocalCallsWithThis" | ||
RuleId="SA1101"> | ||
The call to components must begin with the 'this.' prefix to indicate that the item is a member of the class. | ||
</Violation> | ||
</StyleCopViolations> |