Skip to content

Commit 93f873c

Browse files
committed
fix: update Jackson 2 and restore JaCoCo coverage collection
1 parent 7213597 commit 93f873c

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# - push / pull_request on the main branch
55
# - manual workflow_dispatch
66
#
7-
# Runs `mvn -B clean verify` which includes the JaCoCo coverage gate
8-
# (90% line coverage, haltOnFailure=false) configured in the POM.
7+
# Runs `mvn -B clean verify` which collects JaCoCo coverage and checks the target
8+
# (90% line coverage, warning only: haltOnFailure=false) configured in the POM.
99
name: CI
1010

1111
on:

‎pom.xml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@
5757
<maven.compiler.source>${java.version}</maven.compiler.source>
5858
<maven.compiler.target>${java.version}</maven.compiler.target>
5959
<maven.version>3.0</maven.version>
60+
<!-- Empty fallback supports direct surefire:test without prepare-agent. -->
61+
<jacocoArgLine></jacocoArgLine>
6062
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6163
<!-- Dependency versions -->
6264
<commons-exec.version>1.6.0</commons-exec.version>
6365
<commons-lang.version>2.6</commons-lang.version>
64-
<jackson.version>2.17.2</jackson.version>
66+
<jackson.version>2.22.4</jackson.version>
6567
<java-websocket.version>1.6.0</java-websocket.version>
6668
<junit-jupiter.version>6.1.0</junit-jupiter.version>
6769
<junit.version>4.13.2</junit.version>
@@ -344,7 +346,7 @@
344346
<configuration>
345347
<skip>false</skip>
346348
<skipTests>false</skipTests>
347-
<argLine>-Xmx1024m -Dfile.encoding=UTF-8</argLine>
349+
<argLine>@{jacocoArgLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
348350
<additionalClasspathElements>
349351
<additionalClasspathElement>${basedir}/target/test-classes</additionalClasspathElement>
350352
</additionalClasspathElements>
@@ -423,6 +425,9 @@
423425
<executions>
424426
<execution>
425427
<id>prepare-agent</id>
428+
<configuration>
429+
<propertyName>jacocoArgLine</propertyName>
430+
</configuration>
426431
<goals>
427432
<goal>prepare-agent</goal>
428433
</goals>

‎src/main/java/io/github/easy4j/opencli/parser/OpenCliStdoutJson.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public static JsonNode parseLenient(String stdout) {
4141
}
4242
String trim = stdout.trim();
4343
try {
44-
return MAPPER.readTree(trim);
44+
JsonNode node = MAPPER.readTree(trim);
45+
return node == null || node.isMissingNode()
46+
? MAPPER.getNodeFactory().textNode(stdout) : node;
4547
} catch (JsonProcessingException e) {
4648
log.debug("stdout is not strict JSON, wrapping as text: {}", e.getMessage());
4749
return MAPPER.getNodeFactory().textNode(stdout);

‎src/test/java/io/github/easy4j/opencli/parser/OpenCliStdoutJsonTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99

1010
class OpenCliStdoutJsonTest {
1111

12+
@Test
13+
void shouldPreserveWhitespaceOnlyOutput() {
14+
assertEquals(" \n\t ", OpenCliStdoutJson.parseLenient(" \n\t ").textValue());
15+
}
16+
17+
@Test
18+
void shouldRetainJacksonTwoNodeContract() {
19+
assertTrue(OpenCliStdoutJson.parseLenient("null").isNull());
20+
assertEquals("hello", OpenCliStdoutJson.parseLenient("\"hello\"").textValue());
21+
assertEquals(42, OpenCliStdoutJson.parseLenient("42").intValue());
22+
assertEquals("{broken", OpenCliStdoutJson.parseLenient("{broken").textValue());
23+
}
24+
1225
@Test
1326
void shouldParseValidJsonObject() {
1427
JsonNode node = OpenCliStdoutJson.parseLenient("{\"a\":1}");

0 commit comments

Comments
 (0)