From b7192503ba6fadd93c4ed1f1e74f98526ad688d6 Mon Sep 17 00:00:00 2001 From: ethanbond64 Date: Mon, 26 Feb 2024 22:45:52 -0700 Subject: [PATCH 1/3] add changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cc10182 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +## 0.0.2 - 2024-02-25 +### Changed +- Changed the dependencies portion of the Runabout to be a Set of Strings representing the fully qualified class names of the dependencies. + +## 0.0.1 - 2024-02-25 +Initial release of the runabout-java library. \ No newline at end of file From 611a1a3781212950832e017f14938b293fef67e4 Mon Sep 17 00:00:00 2001 From: ethanbond64 Date: Mon, 26 Feb 2024 23:01:44 -0700 Subject: [PATCH 2/3] add datetime to json + supplier to service --- .../java/dev/runabout/RunaboutConstants.java | 1 + .../dev/runabout/RunaboutServiceBuilder.java | 23 +++++++++++++++++-- .../dev/runabout/RunaboutServiceImpl.java | 8 ++++++- src/main/resources/runabout.properties | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/runabout/RunaboutConstants.java b/src/main/java/dev/runabout/RunaboutConstants.java index 138f27d..91a0dd0 100644 --- a/src/main/java/dev/runabout/RunaboutConstants.java +++ b/src/main/java/dev/runabout/RunaboutConstants.java @@ -12,4 +12,5 @@ private RunaboutConstants() { public static final String EVAL_KEY = "eval"; public static final String DEPENDENCIES_KEY = "dependencies"; public static final String INPUTS_KEY = "inputs"; + public static final String DATETIME_KEY = "datetime"; } diff --git a/src/main/java/dev/runabout/RunaboutServiceBuilder.java b/src/main/java/dev/runabout/RunaboutServiceBuilder.java index 848e1df..c06ff39 100644 --- a/src/main/java/dev/runabout/RunaboutServiceBuilder.java +++ b/src/main/java/dev/runabout/RunaboutServiceBuilder.java @@ -1,6 +1,7 @@ package dev.runabout; import java.lang.reflect.Method; +import java.time.Instant; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -14,11 +15,12 @@ */ public class RunaboutServiceBuilder { + private boolean excludeSuper = false; private Supplier callerSupplier; private Set> callerClassBlacklist; private RunaboutSerializer customSerializer; private Consumer throwableConsumer; - private boolean excludeSuper = false; + private Supplier datetimeSupplier; private final Supplier jsonFactory; @@ -109,6 +111,20 @@ public RunaboutServiceBuilder setExcludeSuper(boolean excludeSuper) { this.excludeSuper = excludeSuper; return this; } + + /** + * Sets the datetime supplier for the RunaboutService. + * The supplier should return the current datetime UTC as an ISO-8601 formatted string. + * By default, the supplier will return the current datetime using {@link Instant#now()}. + * + * @param datetimeSupplier The datetime supplier. + * @return The RunaboutServiceBuilder. + */ + public RunaboutServiceBuilder setDatetimeSupplier(Supplier datetimeSupplier) { + this.datetimeSupplier = datetimeSupplier; + return this; + } + /** * Builds the RunaboutService. * @@ -130,8 +146,11 @@ public RunaboutService build() { final Consumer throwableConsumerFinal = Optional.ofNullable(throwableConsumer) .orElse(RunaboutServiceBuilder::defaultThrowableConsumer); + final Supplier datetimeSupplier = Optional.ofNullable(this.datetimeSupplier) + .orElseGet(() -> () -> Instant.now().toString()); + return new RunaboutServiceImpl<>(excludeSuper, throwableConsumerFinal, callerSupplierFinal, - customSerializerFinal, jsonFactory); + customSerializerFinal, jsonFactory, datetimeSupplier); } private static void defaultThrowableConsumer(Throwable t) { diff --git a/src/main/java/dev/runabout/RunaboutServiceImpl.java b/src/main/java/dev/runabout/RunaboutServiceImpl.java index e71bb3b..d49c4e6 100644 --- a/src/main/java/dev/runabout/RunaboutServiceImpl.java +++ b/src/main/java/dev/runabout/RunaboutServiceImpl.java @@ -19,16 +19,19 @@ class RunaboutServiceImpl implements RunaboutService { private final Supplier callerSupplier; private final RunaboutSerializer customSerializer; private final Supplier jsonFactory; + private final Supplier datetimeSupplier; private final DefaultSerializer defaultSerializer = DefaultSerializer.getInstance(); RunaboutServiceImpl(boolean excludeSuper, Consumer throwableConsumer, Supplier callerSupplier, - RunaboutSerializer customSerializer, Supplier jsonFactory) { + RunaboutSerializer customSerializer, Supplier jsonFactory, + Supplier datetimeSupplier) { this.throwableConsumer = throwableConsumer; this.excludeSuper = excludeSuper; this.callerSupplier = callerSupplier; this.customSerializer = customSerializer; this.jsonFactory = jsonFactory; + this.datetimeSupplier = datetimeSupplier; } @Override @@ -72,6 +75,9 @@ public T toRunaboutJson(Method method, Object... objects) { // Put method data in json. json.put(RunaboutConstants.METHOD_KEY, method.toString()); + // Put datetime data in json. + json.put(RunaboutConstants.DATETIME_KEY, datetimeSupplier.get()); + final List inputs = new ArrayList<>(); for (final Object object: objects) { final RunaboutInput input = serialize(object); diff --git a/src/main/resources/runabout.properties b/src/main/resources/runabout.properties index 5503089..735b9c4 100644 --- a/src/main/resources/runabout.properties +++ b/src/main/resources/runabout.properties @@ -1 +1 @@ -JSON_CONTRACT_VERSION=1.0.0 \ No newline at end of file +JSON_CONTRACT_VERSION=1.1.0 \ No newline at end of file From 4eaa42101f4bb449d9bf2bf2f95ed90b51259c7c Mon Sep 17 00:00:00 2001 From: ethanbond64 Date: Mon, 26 Feb 2024 23:06:36 -0700 Subject: [PATCH 3/3] version --- CHANGELOG.md | 7 +++++++ build.gradle | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc10182..8077dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 1.0.0 - 2024-02-26 +Official release + +### Added +- Added datetime field to the Runabout json object. +- Added a setter to the RunaboutServiceBuilder to provide custom datetime suppliers. + ## 0.0.2 - 2024-02-25 ### Changed - Changed the dependencies portion of the Runabout to be a Set of Strings representing the fully qualified class names of the dependencies. diff --git a/build.gradle b/build.gradle index 1b1f555..ca3840d 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'dev.runabout' -version = '0.0.2' +version = '1.0.0' repositories { mavenCentral()