Skip to content

Commit

Permalink
Adding category to model #39
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Aug 18, 2018
1 parent eb78f2c commit 9fa7ff2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
out
.okhttpcache
.classpath
.project
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

Changelog of Violations lib.

## Unreleased
### GitHub [#39](https://github.com/tomasbjerre/violations-lib/issues/39) AndroidLintParser doesn't expose rule correctly

**Adding category to model**


[3c6f6acd7646597](https://github.com/tomasbjerre/violations-lib/commit/3c6f6acd7646597) Tomas Bjerre *2018-08-18 13:46:33*


## 1.58
### No issue

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/se/bjurr/violations/lib/model/Violation.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class ViolationBuilder {
private Parser parser;
private String reporter;
private String rule;
private String category;
private SEVERITY severity;
private String source;
private Map<String, String> specifics = new HashMap<>();
Expand Down Expand Up @@ -66,6 +67,11 @@ public ViolationBuilder setRule(final String rule) {
return this;
}

public ViolationBuilder setCategory(String category) {
this.category = category;
return this;
}

public ViolationBuilder setSeverity(final SEVERITY severity) {
this.severity = severity;
return this;
Expand Down Expand Up @@ -116,6 +122,7 @@ public static ViolationBuilder violationBuilder() {
private String reporter;

private final String rule;
private final String category;
private final SEVERITY severity;
private final String source;
private final Map<String, String> specifics;
Expand All @@ -129,6 +136,7 @@ public Violation() {
file = null;
source = null;
rule = null;
category = null;
reporter = null;
specifics = null;
parser = null;
Expand All @@ -149,6 +157,7 @@ public Violation(final ViolationBuilder vb) {
file = checkNotNull(emptyToNull(vb.file), "file").replaceAll("\\\\", "/");
source = nullToEmpty(vb.source);
rule = nullToEmpty(vb.rule);
category = nullToEmpty(vb.category);
specifics = vb.specifics;
}

Expand All @@ -163,6 +172,7 @@ public Violation(final Violation v) {
file = v.file;
source = v.source;
rule = v.rule;
category = v.category;
specifics = v.specifics;
}

Expand Down Expand Up @@ -282,6 +292,10 @@ public String getRule() {
return rule;
}

public String getCategory() {
return category;
}

public SEVERITY getSeverity() {
return severity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<Violation> parseReportOutput(String string) throws Exception {
String summary = getAttribute(issueChunk, "summary").trim();
String explanation = getAttribute(issueChunk, "explanation");

String rule = getAttribute(issueChunk, "category");
String category = getAttribute(issueChunk, "category");

violations.add( //
violationBuilder() //
Expand All @@ -44,8 +44,9 @@ public List<Violation> parseReportOutput(String string) throws Exception {
.setColumn(charAttrib.orNull()) //
.setFile(filename) //
.setSeverity(toSeverity(severity)) //
.setRule(rule) //
.setMessage(id + ": " + summary + "\n" + message + "\n" + explanation) //
.setRule(id) //
.setCategory(category) //
.setMessage(summary + "\n" + message + "\n" + explanation) //
.build() //
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public List<Violation> parseReportOutput(String string) throws Exception {
.setFile(filename) //
.setSeverity(severity) //
.setRule(rule) //
.setCategory(ruleSetOpt.orNull())
.setMessage(message.trim()) //
.build() //
);
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/se/bjurr/violations/lib/AndroidLintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public void testThatViolationsCanBeParsed() {
.setStartLine(10) //
.setEndLine(10) //
.setColumn(9) //
.setRule("Correctness")
.setRule("ScrollViewSize") //
.setCategory("Correctness") //
.setMessage(
"ScrollViewSize: ScrollView size validation\n"
"ScrollView size validation\n"
+ "This LinearLayout should use `android:layout_height=\"wrap_content\"`\n"
+ "ScrollView children must set their `layout_width` or `layout_height` attributes to `wrap_content` rather than `fill_parent` or `match_parent` in the scrolling dimension") //
.setSeverity(WARN) //
Expand All @@ -51,9 +52,10 @@ public void testThatViolationsCanBeParsed() {
.setStartLine(0) //
.setEndLine(0) //
.setColumn(null) //
.setRule("Correctness") //
.setRule("InvalidPackage") //
.setCategory("Correctness") //
.setMessage(
"InvalidPackage: Package not included in Android\n"
"Package not included in Android\n"
+ "Invalid package reference in library; not included in Android: `java.nio.file`. Referenced from `okio.Okio`.\n"
+ "This check scans through libraries looking for calls to APIs that are not included in Android.\n"
+ " \n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static se.bjurr.violations.lib.reports.Parser.CHECKSTYLE;

import org.junit.Test;

import se.bjurr.violations.lib.model.Violation.ViolationBuilder;
import uk.co.jemos.podam.api.PodamFactoryImpl;

Expand Down

0 comments on commit 9fa7ff2

Please sign in to comment.