diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61fc12c..3d09f57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,8 +4,8 @@ # - push / pull_request on the main branch # - manual workflow_dispatch # -# Runs `mvn -B clean verify` which includes the JaCoCo coverage gate -# (90% line coverage, haltOnFailure=false) configured in the POM. +# Runs `mvn -B clean verify` which collects JaCoCo coverage and checks the target +# (90% line coverage, warning only: haltOnFailure=false) configured in the POM. name: CI on: @@ -35,7 +35,10 @@ jobs: cache: maven - name: Build and verify with JaCoCo coverage gate - run: mvn -B --no-transfer-progress clean verify + run: | + mvn -B --no-transfer-progress clean verify + test -s target/jacoco.exec + test -s target/site/jacoco/jacoco.xml - name: Upload JaCoCo coverage report if: always() diff --git a/pom.xml b/pom.xml index c92d615..1f517d4 100644 --- a/pom.xml +++ b/pom.xml @@ -57,11 +57,13 @@ ${java.version} ${java.version} 3.0 + + UTF-8 1.6.0 2.6 - 2.17.2 + 2.22.4 1.6.0 6.1.0 4.13.2 @@ -344,7 +346,7 @@ false false - -Xmx1024m -Dfile.encoding=UTF-8 + @{jacocoArgLine} -Xmx1024m -Dfile.encoding=UTF-8 ${basedir}/target/test-classes @@ -423,6 +425,9 @@ prepare-agent + + jacocoArgLine + prepare-agent diff --git a/src/main/java/io/github/easy4j/opencli/parser/OpenCliStdoutJson.java b/src/main/java/io/github/easy4j/opencli/parser/OpenCliStdoutJson.java index ffbe310..bae8ca8 100644 --- a/src/main/java/io/github/easy4j/opencli/parser/OpenCliStdoutJson.java +++ b/src/main/java/io/github/easy4j/opencli/parser/OpenCliStdoutJson.java @@ -41,7 +41,9 @@ public static JsonNode parseLenient(String stdout) { } String trim = stdout.trim(); try { - return MAPPER.readTree(trim); + JsonNode node = MAPPER.readTree(trim); + return node == null || node.isMissingNode() + ? MAPPER.getNodeFactory().textNode(stdout) : node; } catch (JsonProcessingException e) { log.debug("stdout is not strict JSON, wrapping as text: {}", e.getMessage()); return MAPPER.getNodeFactory().textNode(stdout); diff --git a/src/test/java/io/github/easy4j/opencli/parser/OpenCliStdoutJsonTest.java b/src/test/java/io/github/easy4j/opencli/parser/OpenCliStdoutJsonTest.java index bea5a49..6867645 100644 --- a/src/test/java/io/github/easy4j/opencli/parser/OpenCliStdoutJsonTest.java +++ b/src/test/java/io/github/easy4j/opencli/parser/OpenCliStdoutJsonTest.java @@ -9,6 +9,19 @@ class OpenCliStdoutJsonTest { + @Test + void shouldPreserveWhitespaceOnlyOutput() { + assertEquals(" \n\t ", OpenCliStdoutJson.parseLenient(" \n\t ").textValue()); + } + + @Test + void shouldRetainJacksonTwoNodeContract() { + assertTrue(OpenCliStdoutJson.parseLenient("null").isNull()); + assertEquals("hello", OpenCliStdoutJson.parseLenient("\"hello\"").textValue()); + assertEquals(42, OpenCliStdoutJson.parseLenient("42").intValue()); + assertEquals("{broken", OpenCliStdoutJson.parseLenient("{broken").textValue()); + } + @Test void shouldParseValidJsonObject() { JsonNode node = OpenCliStdoutJson.parseLenient("{\"a\":1}");