From 47ab790254fed53a1338ea12228075a7eef8feb7 Mon Sep 17 00:00:00 2001 From: "Kevin S. Clarke" Date: Mon, 18 Nov 2024 01:30:41 -0500 Subject: [PATCH] Fix Sonar warnings --- pom.xml | 6 ++++++ .../info/freelibrary/iiif/webrepl/Server.java | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index fc5c2462..b5df5364 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,7 @@ 0.45.0 3.1.3 3.6.0 + 5.0.5 5.11.0 @@ -85,6 +86,11 @@ jiiify-presentation-v3 ${jpv3.version} + + info.freelibrary + freelib-utils + ${freelib.utils.version} + ch.qos.logback logback-classic diff --git a/src/main/java/info/freelibrary/iiif/webrepl/Server.java b/src/main/java/info/freelibrary/iiif/webrepl/Server.java index 308afd32..4f2bf9f7 100644 --- a/src/main/java/info/freelibrary/iiif/webrepl/Server.java +++ b/src/main/java/info/freelibrary/iiif/webrepl/Server.java @@ -34,6 +34,7 @@ import info.freelibrary.util.Env; import info.freelibrary.util.StringUtils; import info.freelibrary.util.warnings.PMD; +import info.freelibrary.util.warnings.Sonar; import info.freelibrary.iiif.presentation.v3.Manifest; @@ -140,6 +141,7 @@ private static class JPv3Handler implements Handler { * @throws ClassNotFoundException If the JPv3 classes cannot be found * @throws URISyntaxException If the Jar file's path couldn't be converted into a URI */ + @SuppressWarnings({ Sonar.SYSTEM_OUT_ERR }) JPv3Handler() throws IOException, ClassNotFoundException, URISyntaxException { myOutputStream = new ByteArrayOutputStream(); myShell = JShell.builder().compilerOptions("--enable-preview", "--source", "21") @@ -150,15 +152,15 @@ private static class JPv3Handler implements Handler { // Check that all the imports can be loaded successfully myShell.eval(getImports()).stream().filter(event -> !Snippet.Status.VALID.equals(event.status())) - .map((Function) SnippetEvent::status) - .forEach(System.err::println); + .map((Function) SnippetEvent::status).forEach(System.err::println); // Load the JPv3 classes so the imports have something to load myShell.addToClasspath(getJarClasspath()); } @Override - @SuppressWarnings({ PMD.COGNITIVE_COMPLEXITY, "PMD.SystemPrintln" }) + @SuppressWarnings({ PMD.COGNITIVE_COMPLEXITY, PMD.SYSTEM_PRINTLN, PMD.COGNITIVE_COMPLEXITY, + Sonar.SYSTEM_OUT_ERR }) public void handle(final Request aRequest, final Consumer aCallback) { final String uri = aRequest.uri(); final Response response; @@ -188,11 +190,9 @@ public void handle(final Request aRequest, final Consumer aCallback) { final StringBuilder buffer = new StringBuilder(snippet.source()); // Just check one at a time, and let the editor iterate - myShell.diagnostics(snippet).findFirst() - .ifPresentOrElse(new DiagConsumer(buffer), () -> { - buffer.delete(0, buffer.length()) - .append("Parsing error, but diagnostics were not found"); - }); + myShell.diagnostics(snippet).findFirst().ifPresentOrElse( + new DiagConsumer(buffer), () -> buffer.delete(0, buffer.length()) + .append("Parsing error, but diagnostics were not found")); try { myOutputStream.write(buffer.toString().getBytes(UTF_8));