Skip to content

Commit

Permalink
Fix Sonar warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Nov 18, 2024
1 parent 9db7e18 commit 47ab790
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<docker.plugin.version>0.45.0</docker.plugin.version>
<deploy.plugin.version>3.1.3</deploy.plugin.version>
<shade.plugin.version>3.6.0</shade.plugin.version>
<freelib.utils.version>5.0.5</freelib.utils.version>

<!-- Test dependency versions -->
<junit.version>5.11.0</junit.version>
Expand Down Expand Up @@ -85,6 +86,11 @@
<artifactId>jiiify-presentation-v3</artifactId>
<version>${jpv3.version}</version>
</dependency>
<dependency>
<groupId>info.freelibrary</groupId>
<artifactId>freelib-utils</artifactId>
<version>${freelib.utils.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/info/freelibrary/iiif/webrepl/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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")
Expand All @@ -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<? super SnippetEvent, ? extends Status>) SnippetEvent::status)
.forEach(System.err::println);
.map((Function<? super SnippetEvent, Status>) 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<Response> aCallback) {
final String uri = aRequest.uri();
final Response response;
Expand Down Expand Up @@ -188,11 +190,9 @@ public void handle(final Request aRequest, final Consumer<Response> 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));
Expand Down

0 comments on commit 47ab790

Please sign in to comment.