Skip to content

Commit

Permalink
Do not exit early from platform detection
Browse files Browse the repository at this point in the history
Use single method exit point to ensure post-selection logic (currently, client starting) is performed for both automatic and manual platform selection
  • Loading branch information
andrewazores committed Nov 25, 2020
1 parent 3c276b4 commit 2534d8e
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,25 @@ static AuthManager provideAuthManager(
@Singleton
static PlatformDetectionStrategy<?> providePlatformStrategy(
Logger logger, Set<PlatformDetectionStrategy<?>> strategies, Environment env) {
PlatformDetectionStrategy<?> strat = null;
if (env.hasEnv(PLATFORM_STRATEGY_ENV_VAR)) {
String platform = env.getEnv(PLATFORM_STRATEGY_ENV_VAR);
logger.info(
String.format(
"Selecting configured PlatformDetectionStrategy \"%s\"", platform));
for (PlatformDetectionStrategy<?> strat : strategies) {
if (Objects.equals(platform, strat.getClass().getCanonicalName())) {
return strat;
for (PlatformDetectionStrategy<?> s : strategies) {
if (Objects.equals(platform, s.getClass().getCanonicalName())) {
strat = s;
break;
}
}
throw new RuntimeException(
String.format("Selected PlatformDetectionStrategy \"%s\" not found", platform));
if (strat == null) {
throw new RuntimeException(
String.format(
"Selected PlatformDetectionStrategy \"%s\" not found", platform));
}
}
PlatformDetectionStrategy<?> strat =
strat =
strategies.stream()
// reverse sort, higher priorities should be earlier in the stream
.sorted((a, b) -> Integer.compare(b.getPriority(), a.getPriority()))
Expand Down

0 comments on commit 2534d8e

Please sign in to comment.