Skip to content

Commit

Permalink
Make quarkus-jsonb and quarkus-jackson optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
tms0 authored and gastaldi committed Mar 20, 2024
1 parent 283d20a commit c18fdf3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
19 changes: 12 additions & 7 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson-deployment</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jsonb-deployment</artifactId>
<scope>compile</scope>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.loggingjson</groupId>
Expand All @@ -42,6 +36,17 @@
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jsonb</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

import org.jboss.jandex.ClassInfo;

import io.quarkiverse.loggingjson.JsonFactory;
import io.quarkiverse.loggingjson.LoggingJsonRecorder;
import io.quarkiverse.loggingjson.config.Config;
import io.quarkiverse.loggingjson.jackson.JacksonJsonFactory;
import io.quarkiverse.loggingjson.jsonb.JsonbJsonFactory;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
Expand All @@ -31,21 +34,21 @@ FeatureBuildItem feature() {
@Record(ExecutionTime.RUNTIME_INIT)
LogConsoleFormatBuildItem setUpConsoleFormatter(Capabilities capabilities, LoggingJsonRecorder recorder,
Config config) {
return new LogConsoleFormatBuildItem(recorder.initializeConsoleJsonLogging(config, useJackson(capabilities)));
return new LogConsoleFormatBuildItem(recorder.initializeConsoleJsonLogging(config, jsonFactory(capabilities)));
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
LogFileFormatBuildItem setUpFileFormatter(Capabilities capabilities, LoggingJsonRecorder recorder,
Config config) {
return new LogFileFormatBuildItem(recorder.initializeFileJsonLogging(config, useJackson(capabilities)));
return new LogFileFormatBuildItem(recorder.initializeFileJsonLogging(config, jsonFactory(capabilities)));
}

private boolean useJackson(Capabilities capabilities) {
private JsonFactory jsonFactory(Capabilities capabilities) {
if (capabilities.isPresent(Capability.JACKSON)) {
return true;
return new JacksonJsonFactory();
} else if (capabilities.isPresent(Capability.JSONB)) {
return false;
return new JsonbJsonFactory();
} else {
throw new RuntimeException(
"Missing json implementation to use for logging-json. Supported: [quarkus-jackson, quarkus-jsonb]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JsonDefaultFormatterJacksonTest extends JsonDefaultFormatterBaseTest {
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class))
.setForcedDependencies(Collections.singletonList(
new AppArtifact("io.quarkus", "quarkus-jackson-deployment", System.getProperty("test.quarkus.version"))))
new AppArtifact("io.quarkus", "quarkus-jackson", System.getProperty("test.quarkus.version"))))
.withConfigurationResource("application-json.properties");

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JsonDefaultFormatterJsonbTest extends JsonDefaultFormatterBaseTest {
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class))
.setForcedDependencies(Collections.singletonList(
new AppArtifact("io.quarkus", "quarkus-jsonb-deployment", System.getProperty("test.quarkus.version"))))
new AppArtifact("io.quarkus", "quarkus-jsonb", System.getProperty("test.quarkus.version"))))
.withConfigurationResource("application-json.properties");

@Test
Expand Down
3 changes: 2 additions & 1 deletion docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
<!-- Make sure the doc is built after the other artifacts -->
<dependency>
<groupId>io.quarkiverse.loggingjson</groupId>
<artifactId>quarkus-logging-json-deployment</artifactId>
<artifactId>quarkus-logging-json-integration-tests</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
</dependencies>

Expand Down
8 changes: 6 additions & 2 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jsonb</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import io.quarkiverse.loggingjson.config.Config;
import io.quarkiverse.loggingjson.config.ConfigFormatter;
import io.quarkiverse.loggingjson.jackson.JacksonJsonFactory;
import io.quarkiverse.loggingjson.jsonb.JsonbJsonFactory;
import io.quarkiverse.loggingjson.providers.*;
import io.quarkus.arc.Arc;
import io.quarkus.arc.InjectableInstance;
Expand All @@ -24,17 +22,17 @@ public class LoggingJsonRecorder {
private static final Logger log = LoggerFactory.getLogger(LoggingJsonRecorder.class);

public RuntimeValue<Optional<Formatter>> initializeConsoleJsonLogging(Config config,
boolean useJackson) {
return initializeJsonLogging(config.console, config, useJackson);
JsonFactory jsonFactory) {
return initializeJsonLogging(config.console, config, jsonFactory);
}

public RuntimeValue<Optional<Formatter>> initializeFileJsonLogging(Config config,
boolean useJackson) {
return initializeJsonLogging(config.file, config, useJackson);
JsonFactory jsonFactory) {
return initializeJsonLogging(config.file, config, jsonFactory);
}

public RuntimeValue<Optional<Formatter>> initializeJsonLogging(ConfigFormatter formatter, Config config,
boolean useJackson) {
JsonFactory jsonFactory) {
if (formatter == null || !formatter.isEnabled()) {
return new RuntimeValue<>(Optional.empty());
}
Expand Down Expand Up @@ -64,15 +62,6 @@ public RuntimeValue<Optional<Formatter>> initializeJsonLogging(ConfigFormatter f
log.debug("Installed json providers {}", installedProviders);
}

JsonFactory jsonFactory;
if (useJackson) {
log.debug("Using Jackson as the json implementation");
jsonFactory = new JacksonJsonFactory();
} else {
log.debug("Using Jsonb as the json implementation");
jsonFactory = new JsonbJsonFactory();
}

return new RuntimeValue<>(Optional.of(new JsonFormatter(providers, jsonFactory, config)));

}
Expand Down

0 comments on commit c18fdf3

Please sign in to comment.