Skip to content

Commit

Permalink
Simian, ZPTLint, JCReport
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 5, 2016
1 parent 3ac58cc commit 60fa8a9
Show file tree
Hide file tree
Showing 15 changed files with 686 additions and 2 deletions.
63 changes: 62 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,71 @@ Changelog of Git Changelog.
## Unreleased
### No issue

**Simian, ZPTLint, JCReport**


[3128473c31455e8](https://github.com/tomasbjerre/git-changelog-lib/commit/3128473c31455e8) Tomas Bjerre *2016-11-05 22:38:58*

**Gendarme**


[3ac58ccc82b8360](https://github.com/tomasbjerre/git-changelog-lib/commit/3ac58ccc82b8360) Tomas Bjerre *2016-11-05 21:28:33*

**CPD**


[7a4e651c53ab3b2](https://github.com/tomasbjerre/git-changelog-lib/commit/7a4e651c53ab3b2) Tomas Bjerre *2016-11-05 19:16:50*

**CodeNarc**


[23fa562feee2bb2](https://github.com/tomasbjerre/git-changelog-lib/commit/23fa562feee2bb2) Tomas Bjerre *2016-11-05 18:58:32*


## 1.15
### No issue

**Exposing parser in reporter**


[2e216ee38cb2fdb](https://github.com/tomasbjerre/git-changelog-lib/commit/2e216ee38cb2fdb) Tomas Bjerre *2016-11-03 18:03:08*


## 1.14
### No issue

**Letting the reporters parse strings, not files**


[375706d8e579bfc](https://github.com/tomasbjerre/git-changelog-lib/commit/375706d8e579bfc) Tomas Bjerre *2016-11-03 17:54:20*


## 1.13
### GitHub [#11](https://github.com/tomasbjerre/violations-lib/issues/11)

**Handling css-lint reports where there are not line or evidence**

* Also setting severity level for PyLint.

[35d5d33b447b37a](https://github.com/tomasbjerre/git-changelog-lib/commit/35d5d33b447b37a) Tomas Bjerre *2016-10-26 15:39:37*


## 1.12
### No issue

**Changing rule format in PyLint to CODE(codeName)**


[24618707a88497c](https://github.com/tomasbjerre/git-changelog-lib/commit/24618707a88497c) Tomas Bjerre *2016-10-25 17:44:33*


## 1.11
### No issue

**PyLint parser**


[10929695672b31f](https://github.com/tomasbjerre/git-changelog-lib/commit/10929695672b31f) Tomas Bjerre *2016-10-24 17:16:22*
[ec90aa741fdeb67](https://github.com/tomasbjerre/git-changelog-lib/commit/ec90aa741fdeb67) Tomas Bjerre *2016-10-24 17:16:46*


## 1.10
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ It supports:
* [_Gendarme_](http://www.mono-project.com/docs/tools+libraries/tools/gendarme/)
* [_JSHint_](http://jshint.com/)
* _Lint_ A common XML format, used by different linters.
* [_JCReport_](https://github.com/jCoderZ/fawkez/wiki/JcReport)
* [_PerlCritic_](https://github.com/Perl-Critic)
* [_PiTest_](http://pitest.org/)
* [_PyLint_](https://www.pylint.org/)
* [_PMD_](https://pmd.github.io/)
* [_ReSharper_](https://www.jetbrains.com/resharper/)
* [_Simian_](http://www.harukizaemon.com/simian/)
* [_StyleCop_](https://stylecop.codeplex.com/)
* [_XMLLint_](http://xmlsoft.org/xmllint.html)
* [_ZPTLint_](https://pypi.python.org/pypi/zptlint)

Example reports are available [in the test resources](https://github.com/tomasbjerre/violations-lib/tree/master/src/test/resources), examples of how to generate them are available [here](https://github.com/tomasbjerre/violations-test/blob/master/build.sh).

Expand Down
86 changes: 86 additions & 0 deletions src/main/java/se/bjurr/violations/lib/parsers/JCReportParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package se.bjurr.violations.lib.parsers;

import static com.google.common.collect.Lists.newArrayList;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.model.SEVERITY.WARN;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute;
import static se.bjurr.violations.lib.reports.Reporter.JCREPORT;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;

import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

public class JCReportParser implements ViolationsParser {

@Override
public List<Violation> parseFile(String string) throws Exception {
List<Violation> violations = newArrayList();

try (InputStream input = new ByteArrayInputStream(string.getBytes())) {

XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader xmlr = factory.createXMLStreamReader(input);

String name = null;
String findingType = null;
Integer line = null;
String message = null;
String origin = null;
String severity = null;
while (xmlr.hasNext()) {
int eventType = xmlr.next();
if (eventType == START_ELEMENT) {
if (xmlr.getLocalName().equals("file")) {
name = getAttribute(xmlr, "name");
}
if (xmlr.getLocalName().equals("item")) {
findingType = getAttribute(xmlr, "finding-type");
line = getIntegerAttribute(xmlr, "line");
message = getAttribute(xmlr, "message");
origin = getAttribute(xmlr, "origin");
severity = getAttribute(xmlr, "severity");
Violation violation = violationBuilder()//
.setReporter(JCREPORT)//
.setFile(name)//
.setMessage(message)//
.setRule(findingType + "(" + origin + ")")//
.setSeverity(toSeverity(severity))//
.setStartLine(line)//
.build();
violations.add(violation);
}
}
}
}
return violations;
}

private SEVERITY toSeverity(String severity) {
if (severity.equals("error")) {
return ERROR;
}
if (severity.equals("cpd")) {
return ERROR;
}
if (severity.equals("warning")) {
return WARN;
}
if (severity.equals("design")) {
return WARN;
}
if (severity.equals("code-style")) {
return INFO;
}
return INFO;
}
}
75 changes: 75 additions & 0 deletions src/main/java/se/bjurr/violations/lib/parsers/SimianParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package se.bjurr.violations.lib.parsers;

import static com.google.common.collect.Lists.newArrayList;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.model.SEVERITY.WARN;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute;
import static se.bjurr.violations.lib.reports.Reporter.SIMIAN;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;

import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

public class SimianParser implements ViolationsParser {

@Override
public List<Violation> parseFile(String string) throws Exception {
List<Violation> violations = newArrayList();

try (InputStream input = new ByteArrayInputStream(string.getBytes())) {

XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader xmlr = factory.createXMLStreamReader(input);

String sourceFile = null;
Integer lineCount = null;
Integer startLineNumber = null;
Integer endLineNumber = null;
while (xmlr.hasNext()) {
int eventType = xmlr.next();
if (eventType == START_ELEMENT) {
if (xmlr.getLocalName().equals("set")) {
lineCount = getIntegerAttribute(xmlr, "lineCount");
}
if (xmlr.getLocalName().equals("block")) {
sourceFile = getAttribute(xmlr, "sourceFile");
startLineNumber = getIntegerAttribute(xmlr, "startLineNumber");
endLineNumber = getIntegerAttribute(xmlr, "endLineNumber");

Violation violation = violationBuilder()//
.setReporter(SIMIAN)//
.setFile(sourceFile)//
.setMessage("Duplication")//
.setRule("DUPLICATION")//
.setSeverity(toSeverity(lineCount))//
.setStartLine(startLineNumber)//
.setEndLine(endLineNumber)//
.build();
violations.add(violation);
}
}
}
}
return violations;
}

private SEVERITY toSeverity(Integer lineCount) {
if (lineCount < 10) {
return INFO;
}
if (lineCount < 50) {
return WARN;
}
return ERROR;
}
}
38 changes: 38 additions & 0 deletions src/main/java/se/bjurr/violations/lib/parsers/ZPTLintParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package se.bjurr.violations.lib.parsers;

import static com.google.common.collect.Lists.newArrayList;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getLines;
import static se.bjurr.violations.lib.reports.Reporter.ZPTLINT;

import java.util.List;

import se.bjurr.violations.lib.model.Violation;

public class ZPTLintParser implements ViolationsParser {

@Override
public List<Violation> parseFile(String string) throws Exception {
List<Violation> violations = newArrayList();
for (List<String> parts : getLines(string, "[ ]+Error in: (.*) (.*) , at line (\\d+).*")) {
if (parts.size() < 3) {
continue;
}
Integer lineInFile = Integer.parseInt(parts.get(3));
String message = parts.get(2);
String fileName = parts.get(1);
Violation violation = violationBuilder()//
.setReporter(ZPTLINT)//
.setFile(fileName)//
.setMessage(message)//
.setRule("ZPT")//
.setSeverity(ERROR)//
.setStartLine(lineInFile)//
.build();
violations.add(violation);
}
return violations;
}

}
8 changes: 7 additions & 1 deletion src/main/java/se/bjurr/violations/lib/reports/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@
import se.bjurr.violations.lib.parsers.Flake8Parser;
import se.bjurr.violations.lib.parsers.FxCopParser;
import se.bjurr.violations.lib.parsers.GendarmeParser;
import se.bjurr.violations.lib.parsers.JCReportParser;
import se.bjurr.violations.lib.parsers.JSHintParser;
import se.bjurr.violations.lib.parsers.LintParser;
import se.bjurr.violations.lib.parsers.PMDParser;
import se.bjurr.violations.lib.parsers.PerlCriticParser;
import se.bjurr.violations.lib.parsers.PiTestParser;
import se.bjurr.violations.lib.parsers.PyLintParser;
import se.bjurr.violations.lib.parsers.ResharperParser;
import se.bjurr.violations.lib.parsers.SimianParser;
import se.bjurr.violations.lib.parsers.StyleCopParser;
import se.bjurr.violations.lib.parsers.ViolationsParser;
import se.bjurr.violations.lib.parsers.XMLLintParser;
import se.bjurr.violations.lib.parsers.ZPTLintParser;

public enum Reporter {
ANDROIDLINT(new AndroidLintParser()), //
Expand All @@ -45,15 +48,18 @@ public enum Reporter {
FLAKE8(new Flake8Parser()), //
FXCOP(new FxCopParser()), //
GENDARME(new GendarmeParser()), //
JCREPORT(new JCReportParser()), //
JSHINT(new JSHintParser()), //
LINT(new LintParser()), //
PERLCRITIC(new PerlCriticParser()), //
PITEST(new PiTestParser()), //
PMD(new PMDParser()), //
PYLINT(new PyLintParser()), //
RESHARPER(new ResharperParser()), //
SIMIAN(new SimianParser()), //
STYLECOP(new StyleCopParser()), //
XMLLINT(new XMLLintParser());
XMLLINT(new XMLLintParser()), //
ZPTLINT(new ZPTLintParser());

private static Logger LOG = Logger.getLogger(Reporter.class.getSimpleName());
private ViolationsParser violationsParser;
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/se/bjurr/violations/lib/JCReportTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package se.bjurr.violations.lib;

import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.violations.lib.TestUtils.getRootFolder;
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.reports.Reporter.JCREPORT;

import java.util.List;

import org.junit.Test;

import se.bjurr.violations.lib.model.Violation;

public class JCReportTest {
@Test
public void testThatViolationsCanBeParsed() {
String rootFolder = getRootFolder();

List<Violation> actual = violationsReporterApi() //
.withPattern(".*/jcreport/.*\\.xml$") //
.inFolder(rootFolder) //
.findAll(JCREPORT) //
.violations();

assertThat(actual)//
.hasSize(54);

assertThat(actual.get(0).getMessage())//
.isEqualTo("Type Javadoc comment is missing an @author tag.");
assertThat(actual.get(0).getFile())//
.isEqualTo("D:/projects/fawkez/test/java/org/jcoderz/commons/logging/XmlPrinterTest.java");
assertThat(actual.get(0).getSeverity())//
.isEqualTo(INFO);
assertThat(actual.get(0).getRule().get())//
.isEqualTo("CS_MISSING_TAG(Checkstyle)");
assertThat(actual.get(0).getStartLine())//
.isEqualTo(50);
assertThat(actual.get(0).getEndLine())//
.isEqualTo(50);

assertThat(actual.get(1).getMessage())//
.isEqualTo("Class LogElementHandler should be declared as final.");
}

}
Loading

0 comments on commit 60fa8a9

Please sign in to comment.