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 4ef818f
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,33 @@ 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));
}
}
if (strat == null) {
strat =
strategies.stream()
// reverse sort, higher priorities should be earlier in the stream
.sorted((a, b) -> Integer.compare(b.getPriority(), a.getPriority()))
.filter(PlatformDetectionStrategy::isAvailable)
.findFirst()
.orElseThrow();
}
PlatformDetectionStrategy<?> strat =
strategies.stream()
// reverse sort, higher priorities should be earlier in the stream
.sorted((a, b) -> Integer.compare(b.getPriority(), a.getPriority()))
.filter(PlatformDetectionStrategy::isAvailable)
.findFirst()
.orElseThrow();
strat.getPlatformClient().start();
return strat;
}
Expand Down

0 comments on commit 4ef818f

Please sign in to comment.