diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4ac168..f9c3feb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ Changelog of Violations lib. ## Unreleased +### No issue + +**Issue template** + + +[990f4d6da1000b6](https://github.com/tomasbjerre/violations-lib/commit/990f4d6da1000b6) Tomas Bjerre *2018-07-03 14:12:54* + +**Updating docs on PyLint** + + +[4016805bf281f1f](https://github.com/tomasbjerre/violations-lib/commit/4016805bf281f1f) Tomas Bjerre *2018-05-03 17:08:10* + + +## 1.55 ### GitHub [#33](https://github.com/tomasbjerre/violations-lib/issues/33) Add support for NullAway **NullAway** @@ -22,6 +36,16 @@ Changelog of Violations lib. ### No issue +**Avoiding Optional in model** + + +[a2c03571ee99246](https://github.com/tomasbjerre/violations-lib/commit/a2c03571ee99246) Tomas Bjerre *2018-05-01 04:58:35* + +**TSLint** + + +[9df7684f4fba7e8](https://github.com/tomasbjerre/violations-lib/commit/9df7684f4fba7e8) Tomas Bjerre *2018-04-20 10:06:18* + **Adding another PMD test** diff --git a/build.sh b/build.sh index 99788fe4..a1e446c2 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #!/bin/bash -./gradlew clean gitChangelogTask build -i --refresh-dependencies -Dhttp.socketTimeout=60000 -Dhttp.connectionTimeout=60000 +./gradlew clean gitChangelogTask build -i -Dhttp.socketTimeout=60000 -Dhttp.connectionTimeout=60000 diff --git a/src/main/java/se/bjurr/violations/lib/model/Violation.java b/src/main/java/se/bjurr/violations/lib/model/Violation.java index 5291be83..1bd79649 100644 --- a/src/main/java/se/bjurr/violations/lib/model/Violation.java +++ b/src/main/java/se/bjurr/violations/lib/model/Violation.java @@ -1,5 +1,6 @@ package se.bjurr.violations.lib.model; +import static se.bjurr.violations.lib.util.StringUtils.escapeHTML; import static se.bjurr.violations.lib.util.Utils.checkNotNull; import static se.bjurr.violations.lib.util.Utils.emptyToNull; import static se.bjurr.violations.lib.util.Utils.firstNonNull; @@ -107,6 +108,7 @@ public static ViolationBuilder violationBuilder() { private final Integer endLine; private final String file; private final String message; + private final String messageEscaped; /** The algorithm, the format, used. */ private final Parser parser; /** @@ -120,12 +122,14 @@ public static ViolationBuilder violationBuilder() { private final String source; private final Map specifics; private final Integer startLine; + private String fileName; public Violation() { startLine = null; endLine = null; severity = null; message = null; + messageEscaped = null; file = null; source = null; rule = null; @@ -146,7 +150,10 @@ public Violation(final ViolationBuilder vb) { column = vb.column; severity = checkNotNull(vb.severity, "severity"); message = checkNotNull(emptyToNull(vb.message), "message"); + messageEscaped = escapeHTML(message); file = checkNotNull(emptyToNull(vb.file), "file").replaceAll("\\\\", "/"); + final String[] fileParts = file.split("\\/"); + fileName = fileParts[fileParts.length - 1]; source = emptyToNull(vb.source); rule = emptyToNull(vb.rule); specifics = vb.specifics; @@ -248,10 +255,18 @@ public String getFile() { return file; } + public String getFileName() { + return fileName; + } + public String getMessage() { return message; } + public String getMessageEscaped() { + return messageEscaped; + } + public Parser getParser() { return parser; } diff --git a/src/main/java/se/bjurr/violations/lib/parsers/PyLintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/PyLintParser.java index 417de581..a09e5bd4 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/PyLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/PyLintParser.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.List; - import se.bjurr.violations.lib.model.SEVERITY; import se.bjurr.violations.lib.model.Violation; diff --git a/src/main/java/se/bjurr/violations/lib/util/StringUtils.java b/src/main/java/se/bjurr/violations/lib/util/StringUtils.java index 310c2a0e..286d67d2 100644 --- a/src/main/java/se/bjurr/violations/lib/util/StringUtils.java +++ b/src/main/java/se/bjurr/violations/lib/util/StringUtils.java @@ -61,4 +61,19 @@ public static String xmlDecode(final String input) { } return result.toString(); } + + public static String escapeHTML(final String s) { + final StringBuilder out = new StringBuilder(Math.max(16, s.length())); + for (int i = 0; i < s.length(); i++) { + final char c = s.charAt(i); + if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') { + out.append("&#"); + out.append((int) c); + out.append(';'); + } else { + out.append(c); + } + } + return out.toString(); + } } diff --git a/src/test/java/se/bjurr/violations/lib/model/ViolationTest.java b/src/test/java/se/bjurr/violations/lib/model/ViolationTest.java index 06ab98bc..8a7cb515 100644 --- a/src/test/java/se/bjurr/violations/lib/model/ViolationTest.java +++ b/src/test/java/se/bjurr/violations/lib/model/ViolationTest.java @@ -9,18 +9,42 @@ public class ViolationTest { - @Test - public void testThatFilePathsAreAlwaysFronSlashes() { - assertThat( // - violationBuilder() // - .setParser(CHECKSTYLE) // - .setFile("c:\\path\\to\\file.xml") // - .setMessage("message") // - .setSeverity(ERROR) // - .setStartLine(1) // - .build() // - .getFile() // - ) // - .isEqualTo("c:/path/to/file.xml"); - } + @Test + public void testThatFilePathsAreAlwaysFronSlashes() { + final Violation violation = violationBuilder() // + .setParser(CHECKSTYLE) // + .setFile("c:\\path\\to\\file.xml") // + .setMessage("message") // + .setSeverity(ERROR) // + .setStartLine(1) // + .build(); + assertThat(violation.getFile()) // + .isEqualTo("c:/path/to/file.xml"); + } + + @Test + public void testThatFileNameCanBeExtracted() { + final Violation violation = violationBuilder() // + .setParser(CHECKSTYLE) // + .setFile("c:\\path\\to\\file1.xml") // + .setMessage("message") // + .setSeverity(ERROR) // + .setStartLine(1) // + .build(); + assertThat(violation.getFileName()) // + .isEqualTo("file1.xml"); + } + + @Test + public void testThatFileNameCanBeExtractedWhenNoSlashes() { + final Violation violation = violationBuilder() // + .setParser(CHECKSTYLE) // + .setFile("file2.xml") // + .setMessage("message") // + .setSeverity(ERROR) // + .setStartLine(1) // + .build(); + assertThat(violation.getFileName()) // + .isEqualTo("file2.xml"); + } }