Skip to content

Commit

Permalink
Apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Mar 11, 2024
1 parent f499a45 commit bd702cd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
21 changes: 14 additions & 7 deletions src/main/java/org/opentripplanner/standalone/OTPMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void logAllWarnings(Consumer<String> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -581,7 +581,7 @@ void valid() {
object.of("a").asBoolean();
object.of("b").asBoolean();

assertFalse(subject.hasInvalidProperties());
assertFalse(subject.hasUnknownProperties());
}
}

Expand Down

0 comments on commit bd702cd

Please sign in to comment.