From bd702cda23caf0b09aa342c932268f955a11469b Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 11 Mar 2024 12:58:43 +0100 Subject: [PATCH] Apply review feedback --- .../opentripplanner/standalone/OTPMain.java | 21 ++++++++++++------- .../standalone/config/BuildConfig.java | 4 ++-- .../standalone/config/ConfigModel.java | 8 +++---- .../standalone/config/OtpConfig.java | 4 ++-- .../standalone/config/RouterConfig.java | 4 ++-- .../config/framework/json/NodeAdapter.java | 2 +- .../framework/json/NodeAdapterTest.java | 4 ++-- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/opentripplanner/standalone/OTPMain.java b/src/main/java/org/opentripplanner/standalone/OTPMain.java index badfb73443d..eef7415644d 100644 --- a/src/main/java/org/opentripplanner/standalone/OTPMain.java +++ b/src/main/java/org/opentripplanner/standalone/OTPMain.java @@ -13,6 +13,7 @@ import org.opentripplanner.raptor.configure.RaptorConfig; import org.opentripplanner.routing.graph.SerializedGraphObject; import org.opentripplanner.standalone.config.CommandLineParameters; +import org.opentripplanner.standalone.config.ConfigModel; import org.opentripplanner.standalone.configure.ConstructApplication; import org.opentripplanner.standalone.configure.LoadApplication; import org.opentripplanner.standalone.server.GrizzlyServer; @@ -113,13 +114,7 @@ private static void startOTPServer(CommandLineParameters cli) { var loadApp = new LoadApplication(cli); var config = loadApp.config(); - // optionally check if the config is valid and if not abort the startup process - if (cli.configCheck && config.hasInvalidProperties()) { - throw new OtpAppException( - "Configuration contains invalid properties (see above for details). " + - "Please fix your configuration or remove --configCheck from your OTP CLI parameters." - ); - } + detectUnusedConfigParams(cli, config); // Validate data sources, command line arguments and config before loading and // processing input data to fail early @@ -180,6 +175,18 @@ private static void startOTPServer(CommandLineParameters cli) { } } + /** + * Optionally, check if the config is valid and if not abort the startup process. + */ + private static void detectUnusedConfigParams(CommandLineParameters cli, ConfigModel config) { + if (cli.configCheck && config.hasIUnknownProperties()) { + throw new OtpAppException( + "Configuration contains invalid properties (see above for details). " + + "Please fix your configuration or remove --configCheck from your OTP CLI parameters." + ); + } + } + private static void startOtpWebServer(CommandLineParameters params, ConstructApplication app) { // Index graph for travel search app.transitModel().index(); diff --git a/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java b/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java index 6ebd15019eb..b6912488173 100644 --- a/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java @@ -723,7 +723,7 @@ public NodeAdapter asNodeAdapter() { /** * Checks if any unknown or invalid properties were encountered while loading the configuration. */ - public boolean hasInvalidProperties() { - return root.hasInvalidProperties(); + public boolean hasUnknownProperties() { + return root.hasUnknownProperties(); } } diff --git a/src/main/java/org/opentripplanner/standalone/config/ConfigModel.java b/src/main/java/org/opentripplanner/standalone/config/ConfigModel.java index 820737ec8f9..a9506ed514e 100644 --- a/src/main/java/org/opentripplanner/standalone/config/ConfigModel.java +++ b/src/main/java/org/opentripplanner/standalone/config/ConfigModel.java @@ -109,11 +109,11 @@ public static void initializeOtpFeatures(OtpConfig otpConfig) { /** * Checks if any unknown or invalid properties were encountered while loading the configuration. */ - public boolean hasInvalidProperties() { + public boolean hasIUnknownProperties() { return ( - otpConfig.hasInvalidProperties() || - buildConfig.hasInvalidProperties() || - routerConfig.hasInvalidProperties() + otpConfig.hasUnknownProperties() || + buildConfig.hasUnknownProperties() || + routerConfig.hasUnknownProperties() ); } } diff --git a/src/main/java/org/opentripplanner/standalone/config/OtpConfig.java b/src/main/java/org/opentripplanner/standalone/config/OtpConfig.java index bb361c15d4f..29f866123e3 100644 --- a/src/main/java/org/opentripplanner/standalone/config/OtpConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/OtpConfig.java @@ -75,7 +75,7 @@ public OtpConfig(NodeAdapter nodeAdapter, boolean logUnusedParams) { /** * Checks if any unknown or invalid properties were encountered while loading the configuration. */ - public boolean hasInvalidProperties() { - return root.hasInvalidProperties(); + public boolean hasUnknownProperties() { + return root.hasUnknownProperties(); } } diff --git a/src/main/java/org/opentripplanner/standalone/config/RouterConfig.java b/src/main/java/org/opentripplanner/standalone/config/RouterConfig.java index d4df555c600..ee8c46aa447 100644 --- a/src/main/java/org/opentripplanner/standalone/config/RouterConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/RouterConfig.java @@ -154,7 +154,7 @@ public String toString() { /** * Checks if any unknown or invalid properties were encountered while loading the configuration. */ - public boolean hasInvalidProperties() { - return root.hasInvalidProperties(); + public boolean hasUnknownProperties() { + return root.hasUnknownProperties(); } } diff --git a/src/main/java/org/opentripplanner/standalone/config/framework/json/NodeAdapter.java b/src/main/java/org/opentripplanner/standalone/config/framework/json/NodeAdapter.java index 7a097b2edff..930b5c1799f 100644 --- a/src/main/java/org/opentripplanner/standalone/config/framework/json/NodeAdapter.java +++ b/src/main/java/org/opentripplanner/standalone/config/framework/json/NodeAdapter.java @@ -175,7 +175,7 @@ public void logAllWarnings(Consumer logger) { /** * Checks if any unknown or invalid properties were encountered while loading the configuration. */ - public boolean hasInvalidProperties() { + public boolean hasUnknownProperties() { return !unusedParams().isEmpty() || !allWarnings().toList().isEmpty(); } diff --git a/src/test/java/org/opentripplanner/standalone/config/framework/json/NodeAdapterTest.java b/src/test/java/org/opentripplanner/standalone/config/framework/json/NodeAdapterTest.java index 71bb9d380a2..4ab5545cc23 100644 --- a/src/test/java/org/opentripplanner/standalone/config/framework/json/NodeAdapterTest.java +++ b/src/test/java/org/opentripplanner/standalone/config/framework/json/NodeAdapterTest.java @@ -569,7 +569,7 @@ void invalidProperties() { // When: Access ONLY parameter 'a', but not 'b' subject.of("foo").asObject().of("a").asBoolean(); - assertTrue(subject.hasInvalidProperties()); + assertTrue(subject.hasUnknownProperties()); } @Test @@ -581,7 +581,7 @@ void valid() { object.of("a").asBoolean(); object.of("b").asBoolean(); - assertFalse(subject.hasInvalidProperties()); + assertFalse(subject.hasUnknownProperties()); } }