Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.version>3.0</maven.version>
<!-- Empty fallback supports direct surefire:test without prepare-agent. -->
<jacocoArgLine></jacocoArgLine>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Dependency versions -->
<commons-exec.version>1.6.0</commons-exec.version>
<commons-lang.version>2.6</commons-lang.version>
<jackson.version>2.17.2</jackson.version>
<jackson.version>2.22.4</jackson.version>
<java-websocket.version>1.6.0</java-websocket.version>
<junit-jupiter.version>6.1.0</junit-jupiter.version>
<junit.version>4.13.2</junit.version>
Expand Down Expand Up @@ -344,7 +346,7 @@
<configuration>
<skip>false</skip>
<skipTests>false</skipTests>
<argLine>-Xmx1024m -Dfile.encoding=UTF-8</argLine>
<argLine>@{jacocoArgLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target/test-classes</additionalClasspathElement>
</additionalClasspathElements>
Expand Down Expand Up @@ -423,6 +425,9 @@
<executions>
<execution>
<id>prepare-agent</id>
<configuration>
<propertyName>jacocoArgLine</propertyName>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
Loading