From 6951f1a5039f9687172b72fdbba11daf722315da Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Sun, 31 Dec 2017 06:51:14 +0100 Subject: [PATCH] Gathering string utils --- CHANGELOG.md | 15 ++++ .../lib/parsers/AndroidLintParser.java | 6 +- .../violations/lib/parsers/CLangParser.java | 2 +- .../violations/lib/parsers/CPDParser.java | 4 +- .../lib/parsers/CPPCheckParser.java | 6 +- .../violations/lib/parsers/CSSLintParser.java | 8 +- .../lib/parsers/CheckStyleParser.java | 10 +-- .../lib/parsers/CodeNarcParser.java | 4 +- .../violations/lib/parsers/CppLintParser.java | 4 +- .../violations/lib/parsers/DocFXParser.java | 4 +- .../lib/parsers/FindbugsParser.java | 10 +-- .../violations/lib/parsers/Flake8Parser.java | 2 +- .../violations/lib/parsers/FxCopParser.java | 5 +- .../lib/parsers/GendarmeParser.java | 2 +- .../violations/lib/parsers/GoLintParser.java | 2 +- .../lib/parsers/JCReportParser.java | 4 +- .../violations/lib/parsers/JSHintParser.java | 6 +- .../violations/lib/parsers/LintParser.java | 8 +- .../violations/lib/parsers/MyPyParser.java | 2 +- .../violations/lib/parsers/PMDParser.java | 12 +-- .../lib/parsers/PerlCriticParser.java | 4 +- .../violations/lib/parsers/PiTestParser.java | 8 +- .../lib/parsers/PyDocStyleParser.java | 3 +- .../violations/lib/parsers/PyLintParser.java | 2 +- .../lib/parsers/ResharperParser.java | 8 +- .../lib/parsers/SbtScalacParser.java | 2 +- .../violations/lib/parsers/SimianParser.java | 4 +- .../lib/parsers/StyleCopParser.java | 4 +- .../violations/lib/parsers/XMLLintParser.java | 4 +- .../violations/lib/parsers/ZPTLintParser.java | 2 +- .../bjurr/violations/lib/util/HTMLUtils.java | 21 ----- .../violations/lib/util/StringUtils.java | 64 +++++++++++++++ .../ViolationParserUtils.java | 82 +++++-------------- .../violations/lib/ViolationsParserTest.java | 4 +- 34 files changed, 174 insertions(+), 154 deletions(-) delete mode 100644 src/main/java/se/bjurr/violations/lib/util/HTMLUtils.java create mode 100644 src/main/java/se/bjurr/violations/lib/util/StringUtils.java rename src/main/java/se/bjurr/violations/lib/{parsers => util}/ViolationParserUtils.java (63%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b165f986..4efe1471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,23 @@ Changelog of Violations lib. ## Unreleased +### GitHub [#28](https://github.com/tomasbjerre/violations-lib/issues/28) Single quotes in xml are printed as &apos; + +**Un-escape XML when reading attributes.** + + * Fixes + +[9b10f800c7b7941](https://github.com/tomasbjerre/violations-lib/commit/9b10f800c7b7941) Sam Judd *2017-12-31 03:25:14* + + +## 1.49 ### No issue +**Relocating to correct Java identifier** + + +[8e64583ce0fec03](https://github.com/tomasbjerre/violations-lib/commit/8e64583ce0fec03) Tomas Bjerre *2017-12-30 18:32:34* + **Doc** diff --git a/src/main/java/se/bjurr/violations/lib/parsers/AndroidLintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/AndroidLintParser.java index e343f9f5..fcbab137 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/AndroidLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/AndroidLintParser.java @@ -4,10 +4,10 @@ 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.findIntegerAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; import static se.bjurr.violations.lib.reports.Parser.ANDROIDLINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findIntegerAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/CLangParser.java b/src/main/java/se/bjurr/violations/lib/parsers/CLangParser.java index 8151b75a..5c6acf83 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/CLangParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/CLangParser.java @@ -5,9 +5,9 @@ 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.getLines; import static se.bjurr.violations.lib.reports.Parser.CLANG; import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/CPDParser.java b/src/main/java/se/bjurr/violations/lib/parsers/CPDParser.java index f73ee3d6..f3897e2d 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/CPDParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/CPDParser.java @@ -5,9 +5,9 @@ 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.Parser.CODENARC; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/CPPCheckParser.java b/src/main/java/se/bjurr/violations/lib/parsers/CPPCheckParser.java index 3ef7f7b0..ed026353 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/CPPCheckParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/CPPCheckParser.java @@ -4,10 +4,10 @@ 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.getChunks; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute; import static se.bjurr.violations.lib.reports.Parser.CPPCHECK; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/CSSLintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/CSSLintParser.java index 6481f3f0..a7ffca61 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/CSSLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/CSSLintParser.java @@ -4,11 +4,11 @@ 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.findAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.findIntegerAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; import static se.bjurr.violations.lib.reports.Parser.CSSLINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findIntegerAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/CheckStyleParser.java b/src/main/java/se/bjurr/violations/lib/parsers/CheckStyleParser.java index 0f7b5e06..ec1f2ed6 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/CheckStyleParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/CheckStyleParser.java @@ -4,12 +4,12 @@ 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.findAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.findIntegerAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute; import static se.bjurr.violations.lib.reports.Parser.CHECKSTYLE; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findIntegerAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/CodeNarcParser.java b/src/main/java/se/bjurr/violations/lib/parsers/CodeNarcParser.java index 1c5a4101..aef7dd33 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/CodeNarcParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/CodeNarcParser.java @@ -5,9 +5,9 @@ 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.Parser.CODENARC; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/CppLintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/CppLintParser.java index 0f9f6cb6..a276bc26 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/CppLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/CppLintParser.java @@ -5,9 +5,9 @@ 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.getLines; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getParts; import static se.bjurr.violations.lib.reports.Parser.CPPLINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getParts; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/DocFXParser.java b/src/main/java/se/bjurr/violations/lib/parsers/DocFXParser.java index ea0e9e0a..e2e19ffb 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/DocFXParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/DocFXParser.java @@ -11,7 +11,7 @@ import java.util.logging.Logger; import se.bjurr.violations.lib.model.SEVERITY; import se.bjurr.violations.lib.model.Violation; -import se.bjurr.violations.lib.util.HTMLUtils; +import se.bjurr.violations.lib.util.StringUtils; public class DocFXParser implements ViolationsParser { private static Logger LOG = Logger.getLogger(DocFXParser.class.getName()); @@ -32,7 +32,7 @@ public List parseReportOutput(String reportContent) throws Exception LOG.log(Level.FINE, "Ignoring " + rawLineToParse + " because there is not file attribute"); continue; } - final String file = HTMLUtils.htmlDecode(fileEncoded); + final String file = StringUtils.htmlDecode(fileEncoded); final String code = (String) parsedMap.get("code"); final String lineString = (String) parsedMap.get("line"); Integer lineInt; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/FindbugsParser.java b/src/main/java/se/bjurr/violations/lib/parsers/FindbugsParser.java index 84cd43c5..cc8438cf 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/FindbugsParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/FindbugsParser.java @@ -2,13 +2,13 @@ import static java.util.logging.Level.SEVERE; import static se.bjurr.violations.lib.model.Violation.violationBuilder; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.findIntegerAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getContent; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute; import static se.bjurr.violations.lib.reports.Parser.FINDBUGS; import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findIntegerAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getContent; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.io.ByteArrayInputStream; import java.io.IOException; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/Flake8Parser.java b/src/main/java/se/bjurr/violations/lib/parsers/Flake8Parser.java index 1233266a..d062e2e1 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/Flake8Parser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/Flake8Parser.java @@ -5,9 +5,9 @@ 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.getLines; import static se.bjurr.violations.lib.reports.Parser.FLAKE8; import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/FxCopParser.java b/src/main/java/se/bjurr/violations/lib/parsers/FxCopParser.java index dda4d277..324e8f38 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/FxCopParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/FxCopParser.java @@ -6,9 +6,9 @@ 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.Parser.FXCOP; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -20,6 +20,7 @@ import se.bjurr.violations.lib.model.SEVERITY; import se.bjurr.violations.lib.model.Violation; import se.bjurr.violations.lib.util.Optional; +import se.bjurr.violations.lib.util.ViolationParserUtils; public class FxCopParser implements ViolationsParser { private static Logger LOG = Logger.getLogger(FxCopParser.class.getSimpleName()); diff --git a/src/main/java/se/bjurr/violations/lib/parsers/GendarmeParser.java b/src/main/java/se/bjurr/violations/lib/parsers/GendarmeParser.java index 9869bbb4..5b5d1bad 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/GendarmeParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/GendarmeParser.java @@ -5,8 +5,8 @@ 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.reports.Parser.GENDARME; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/GoLintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/GoLintParser.java index 114bc379..0f845221 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/GoLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/GoLintParser.java @@ -5,9 +5,9 @@ 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.getLines; import static se.bjurr.violations.lib.reports.Parser.GOLINT; import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/JCReportParser.java b/src/main/java/se/bjurr/violations/lib/parsers/JCReportParser.java index 53d4298b..9c1f7cd9 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/JCReportParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/JCReportParser.java @@ -5,9 +5,9 @@ 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.Parser.JCREPORT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/JSHintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/JSHintParser.java index 4b9b74ff..5bee97d7 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/JSHintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/JSHintParser.java @@ -4,10 +4,10 @@ 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.getChunks; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute; import static se.bjurr.violations.lib.reports.Parser.JSHINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/LintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/LintParser.java index 31d2de2e..5c3d6bb5 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/LintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/LintParser.java @@ -4,11 +4,11 @@ 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.findIntegerAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute; import static se.bjurr.violations.lib.reports.Parser.LINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findIntegerAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/MyPyParser.java b/src/main/java/se/bjurr/violations/lib/parsers/MyPyParser.java index 10f16413..14c0c2bc 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/MyPyParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/MyPyParser.java @@ -4,8 +4,8 @@ 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.Violation.violationBuilder; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getLines; import static se.bjurr.violations.lib.reports.Parser.MYPY; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/PMDParser.java b/src/main/java/se/bjurr/violations/lib/parsers/PMDParser.java index 8ddeda10..877f85cb 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/PMDParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/PMDParser.java @@ -4,13 +4,13 @@ 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.findAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.findIntegerAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getContent; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute; import static se.bjurr.violations.lib.reports.Parser.PMD; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findIntegerAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getContent; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/PerlCriticParser.java b/src/main/java/se/bjurr/violations/lib/parsers/PerlCriticParser.java index e10aac7c..88792811 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/PerlCriticParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/PerlCriticParser.java @@ -5,9 +5,9 @@ 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.getLines; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getParts; import static se.bjurr.violations.lib.reports.Parser.CPPLINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getParts; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/PiTestParser.java b/src/main/java/se/bjurr/violations/lib/parsers/PiTestParser.java index 663c51b0..9cf5671f 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/PiTestParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/PiTestParser.java @@ -2,11 +2,11 @@ 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.getChunks; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getContent; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerContent; import static se.bjurr.violations.lib.reports.Parser.PITEST; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getContent; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerContent; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/PyDocStyleParser.java b/src/main/java/se/bjurr/violations/lib/parsers/PyDocStyleParser.java index d33b3087..21f3b913 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/PyDocStyleParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/PyDocStyleParser.java @@ -3,12 +3,13 @@ import static java.lang.Integer.parseInt; 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.getParts; import static se.bjurr.violations.lib.reports.Parser.PYDOCSTYLE; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getParts; import java.util.ArrayList; import java.util.List; import se.bjurr.violations.lib.model.Violation; +import se.bjurr.violations.lib.util.ViolationParserUtils; public class PyDocStyleParser implements ViolationsParser { 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 bb985916..03216890 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/PyLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/PyLintParser.java @@ -5,8 +5,8 @@ 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.getLines; import static se.bjurr.violations.lib.reports.Parser.PYLINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/ResharperParser.java b/src/main/java/se/bjurr/violations/lib/parsers/ResharperParser.java index b6515556..8839601c 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/ResharperParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/ResharperParser.java @@ -4,11 +4,11 @@ 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.findAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.findIntegerAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; import static se.bjurr.violations.lib.reports.Parser.RESHARPER; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.findIntegerAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/SbtScalacParser.java b/src/main/java/se/bjurr/violations/lib/parsers/SbtScalacParser.java index 0042fc4f..08d0d719 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/SbtScalacParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/SbtScalacParser.java @@ -5,8 +5,8 @@ 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.getLines; import static se.bjurr.violations.lib.reports.Parser.SBTSCALAC; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/SimianParser.java b/src/main/java/se/bjurr/violations/lib/parsers/SimianParser.java index bec3a49e..8f116fc6 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/SimianParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/SimianParser.java @@ -5,9 +5,9 @@ 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.Parser.SIMIAN; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/StyleCopParser.java b/src/main/java/se/bjurr/violations/lib/parsers/StyleCopParser.java index 9799e34d..821fb652 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/StyleCopParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/StyleCopParser.java @@ -3,9 +3,9 @@ import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import static se.bjurr.violations.lib.model.SEVERITY.INFO; 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.Parser.STYLECOP; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/XMLLintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/XMLLintParser.java index 2538cbfe..7106ab7a 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/XMLLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/XMLLintParser.java @@ -3,9 +3,9 @@ import static java.lang.Integer.parseInt; 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.parsers.ViolationParserUtils.getParts; import static se.bjurr.violations.lib.reports.Parser.XMLLINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getParts; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/parsers/ZPTLintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/ZPTLintParser.java index 404904b8..ba7864d5 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/ZPTLintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/ZPTLintParser.java @@ -2,8 +2,8 @@ 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.Parser.ZPTLINT; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/se/bjurr/violations/lib/util/HTMLUtils.java b/src/main/java/se/bjurr/violations/lib/util/HTMLUtils.java deleted file mode 100644 index fc5f86d2..00000000 --- a/src/main/java/se/bjurr/violations/lib/util/HTMLUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -package se.bjurr.violations.lib.util; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public final class HTMLUtils { - private HTMLUtils() {} - - public static String htmlDecode(String input) { - final Pattern p = Pattern.compile("&#(\\d+);"); - final Matcher m = p.matcher(input); - final StringBuffer sb = new StringBuffer(); - while (m.find()) { - final Integer found = Integer.valueOf(m.group(1)); - final String character = String.valueOf((char) found.intValue()); - m.appendReplacement(sb, character); - } - m.appendTail(sb); - return sb.toString(); - } -} diff --git a/src/main/java/se/bjurr/violations/lib/util/StringUtils.java b/src/main/java/se/bjurr/violations/lib/util/StringUtils.java new file mode 100644 index 00000000..310c2a0e --- /dev/null +++ b/src/main/java/se/bjurr/violations/lib/util/StringUtils.java @@ -0,0 +1,64 @@ +package se.bjurr.violations.lib.util; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class StringUtils { + private static final Map XML_ESCAPE_CHARACTER_MAP; + private static final String[] XML_ESCAPE_CHARACTERS; + private static final char XML_ESCAPE_START = '&'; + + static { + final Map temp = new HashMap<>(); + temp.put("'", '\''); + temp.put(""", '\"'); + temp.put("&", '&'); + temp.put("<", '<'); + temp.put(">", '>'); + XML_ESCAPE_CHARACTER_MAP = Collections.unmodifiableMap(temp); + XML_ESCAPE_CHARACTERS = temp.keySet().toArray(new String[0]); + } + + private StringUtils() {} + + public static String htmlDecode(final String input) { + final Pattern p = Pattern.compile("&#(\\d+);"); + final Matcher m = p.matcher(input); + final StringBuffer sb = new StringBuffer(); + while (m.find()) { + final Integer found = Integer.valueOf(m.group(1)); + final String character = String.valueOf((char) found.intValue()); + m.appendReplacement(sb, character); + } + m.appendTail(sb); + return sb.toString(); + } + + public static String xmlDecode(final String input) { + final StringBuilder result = new StringBuilder(input.length()); + for (int i = 0; i < input.length(); ) { + final char current = input.charAt(i); + + boolean isValidXmlEscape = false; + if (current == XML_ESCAPE_START) { + for (final String escapeCharacter : XML_ESCAPE_CHARACTERS) { + if (input.startsWith(escapeCharacter, i)) { + result.append(XML_ESCAPE_CHARACTER_MAP.get(escapeCharacter)); + i += escapeCharacter.length(); + isValidXmlEscape = true; + break; + } + } + } + + if (!isValidXmlEscape) { + result.append(current); + i++; + } + } + return result.toString(); + } +} diff --git a/src/main/java/se/bjurr/violations/lib/parsers/ViolationParserUtils.java b/src/main/java/se/bjurr/violations/lib/util/ViolationParserUtils.java similarity index 63% rename from src/main/java/se/bjurr/violations/lib/parsers/ViolationParserUtils.java rename to src/main/java/se/bjurr/violations/lib/util/ViolationParserUtils.java index 41c046aa..3ab018ed 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/ViolationParserUtils.java +++ b/src/main/java/se/bjurr/violations/lib/util/ViolationParserUtils.java @@ -1,18 +1,16 @@ -package se.bjurr.violations.lib.parsers; +package se.bjurr.violations.lib.util; import static java.lang.Integer.parseInt; import static java.util.regex.Pattern.DOTALL; import static java.util.regex.Pattern.quote; import static se.bjurr.violations.lib.util.Optional.absent; import static se.bjurr.violations.lib.util.Optional.fromNullable; +import static se.bjurr.violations.lib.util.StringUtils.xmlDecode; import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.xml.stream.XMLStreamReader; @@ -20,82 +18,43 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import javax.xml.transform.stream.StreamResult; -import se.bjurr.violations.lib.util.Optional; public final class ViolationParserUtils { - private static final Map XML_ESCAPE_CHARACTER_MAP; - private static final String[] XML_ESCAPE_CHARACTERS; - private static final char XML_ESCAPE_START = '&'; - - static { - Map temp = new HashMap<>(); - temp.put("'", '\''); - temp.put(""", '\"'); - temp.put("&", '&'); - temp.put("<", '<'); - temp.put(">", '>'); - XML_ESCAPE_CHARACTER_MAP = Collections.unmodifiableMap(temp); - XML_ESCAPE_CHARACTERS = temp.keySet().toArray(new String[0]); - } - - private static String unEscapeXml(String input) { - StringBuilder result = new StringBuilder(input.length()); - for (int i = 0; i < input.length(); ) { - char current = input.charAt(i); - - boolean isValidXmlEscape = false; - if (current == XML_ESCAPE_START) { - for (String escapeCharacter : XML_ESCAPE_CHARACTERS) { - if (input.startsWith(escapeCharacter, i)) { - result.append(XML_ESCAPE_CHARACTER_MAP.get(escapeCharacter)); - i += escapeCharacter.length(); - isValidXmlEscape = true; - break; - } - } - } - - if (!isValidXmlEscape) { - result.append(current); - i++; - } - } - return result.toString(); - } - public static String asString(XMLStreamReader xmlr) throws Exception { + public static String asString(final XMLStreamReader xmlr) throws Exception { final Transformer transformer = TransformerFactory.newInstance().newTransformer(); final StringWriter stringWriter = new StringWriter(); transformer.transform(new StAXSource(xmlr), new StreamResult(stringWriter)); return stringWriter.toString(); } - public static Optional findAttribute(String in, String attribute) { + public static Optional findAttribute(final String in, final String attribute) { Pattern pattern = Pattern.compile(attribute + "='([^']+?)'"); Matcher matcher = pattern.matcher(in); if (matcher.find()) { - return fromNullable(unEscapeXml(matcher.group(1))); + return fromNullable(xmlDecode(matcher.group(1))); } pattern = Pattern.compile(attribute + "=\"([^\"]+?)\""); matcher = pattern.matcher(in); if (matcher.find()) { - return fromNullable(unEscapeXml(matcher.group(1))); + return fromNullable(xmlDecode(matcher.group(1))); } return absent(); } - public static Optional findAttribute(XMLStreamReader in, String attribute) { + public static Optional findAttribute(final XMLStreamReader in, final String attribute) { return fromNullable(in.getAttributeValue("", attribute)); } - public static Optional findIntegerAttribute(String in, String attribute) { + public static Optional findIntegerAttribute(final String in, final String attribute) { if (findAttribute(in, attribute).isPresent()) { return fromNullable(parseInt(getAttribute(in, attribute))); } return absent(); } - public static Optional findIntegerAttribute(XMLStreamReader in, String attribute) { + public static Optional findIntegerAttribute( + final XMLStreamReader in, final String attribute) { final String attr = in.getAttributeValue("", attribute); if (attr == null) { return Optional.absent(); @@ -104,7 +63,7 @@ public static Optional findIntegerAttribute(XMLStreamReader in, String } } - public static String getAttribute(String in, String attribute) { + public static String getAttribute(final String in, final String attribute) { final Optional foundOpt = findAttribute(in, attribute); if (foundOpt.isPresent()) { return foundOpt.get(); @@ -112,7 +71,7 @@ public static String getAttribute(String in, String attribute) { throw new RuntimeException("\"" + attribute + "\" not found in \"" + in + "\""); } - public static String getAttribute(XMLStreamReader in, String attribute) { + public static String getAttribute(final XMLStreamReader in, final String attribute) { final String foundOpt = in.getAttributeValue("", attribute); if (foundOpt == null) { String foundin; @@ -126,7 +85,8 @@ public static String getAttribute(XMLStreamReader in, String attribute) { return foundOpt; } - public static List getChunks(String in, String includingStart, String includingEnd) { + public static List getChunks( + final String in, final String includingStart, final String includingEnd) { final Pattern pattern = Pattern.compile("(" + includingStart + ".+?" + includingEnd + ")", DOTALL); final Matcher matcher = pattern.matcher(in); @@ -137,7 +97,7 @@ public static List getChunks(String in, String includingStart, String in return chunks; } - public static String getContent(String in, String tag) { + public static String getContent(final String in, final String tag) { Pattern pattern = Pattern.compile( "<" + tag + "\\s?[^>]*>[^<]*[^<]*", @@ -154,25 +114,25 @@ public static String getContent(String in, String tag) { throw new RuntimeException("\"" + tag + "\" not found in " + in); } - public static Integer getIntegerAttribute(String in, String attribute) { + public static Integer getIntegerAttribute(final String in, final String attribute) { return parseInt(getAttribute(in, attribute)); } - public static Integer getIntegerAttribute(XMLStreamReader in, String attribute) { + public static Integer getIntegerAttribute(final XMLStreamReader in, final String attribute) { return parseInt(getAttribute(in, attribute)); } - public static Integer getIntegerContent(String in, String tag) { + public static Integer getIntegerContent(final String in, final String tag) { final String content = getContent(in, tag); return parseInt(content); } - public static List getLines(String string) { + public static List getLines(final String string) { return Arrays.asList(string.split("\n")); } /** @return List per line in String, with groups from regexpPerLine. */ - public static List> getLines(String string, String regexpPerLine) { + public static List> getLines(final String string, final String regexpPerLine) { final List> results = new ArrayList<>(); final Pattern pattern = Pattern.compile(regexpPerLine); for (final String line : string.split("\n")) { @@ -193,7 +153,7 @@ public static List> getLines(String string, String regexpPerLine) { * Match one regexp at a time. Remove the matched part from the string, trim, and match next * regexp on that string... */ - public static List getParts(String string, String... regexpList) { + public static List getParts(String string, final String... regexpList) { final List parts = new ArrayList<>(); for (final String regexp : regexpList) { final Pattern pattern = Pattern.compile(regexp); diff --git a/src/test/java/se/bjurr/violations/lib/ViolationsParserTest.java b/src/test/java/se/bjurr/violations/lib/ViolationsParserTest.java index d7e49911..2b7e64f2 100644 --- a/src/test/java/se/bjurr/violations/lib/ViolationsParserTest.java +++ b/src/test/java/se/bjurr/violations/lib/ViolationsParserTest.java @@ -1,8 +1,8 @@ package se.bjurr.violations.lib; import static org.assertj.core.api.Assertions.assertThat; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute; -import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute; +import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks; import java.util.ArrayList; import java.util.List;