Skip to content

Commit

Permalink
Improve logic to read msedgedriver latest version (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Jul 25, 2024
1 parent 3b7165a commit d6f6d2d
Showing 1 changed file with 53 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,27 @@ public Optional<String> getDriverVersionFromRepository(
}
}

String osLabel = optOsLabel.isPresent() ? optOsLabel.get() : "";
String url = driverVersion.isPresent()
? driverUrl + latestLabel + "_" + driverVersion.get() + osLabel
: driverUrl + versionLabel;
Optional<String> result = Optional.empty();
String url = driverUrl + versionLabel;
if (!driverVersion.isPresent()) {
result = readUrlContent(url, driverName, versionCharset);
}
if (result.isPresent()) {
String osLabel = optOsLabel.isPresent() ? optOsLabel.get() : "";
url = driverUrl + latestLabel + "_" + getMajorVersion(result.get())
+ osLabel;
}
result = readUrlContent(url, driverName, versionCharset);
if (result.isPresent()) {
log.debug("Latest version of {} according to {} is {}", driverName,
url, result.get());
}

return result;
}

public Optional<String> readUrlContent(String url, String driverName,
Charset versionCharset) {
Optional<String> result = Optional.empty();
try (InputStream response = httpClient
.execute(httpClient.createHttpGet(new URL(url))).getEntity()
Expand All @@ -154,11 +171,6 @@ public Optional<String> getDriverVersionFromRepository(
log.warn("Exception reading {} to get latest version of {} ({})",
url, driverName, e.getMessage());
}
if (result.isPresent()) {
log.debug("Latest version of {} according to {} is {}", driverName,
url, result.get());
}

return result;
}

Expand Down Expand Up @@ -219,38 +231,38 @@ public Optional<Path> getBrowserPath(String browserName) {

public Optional<String> getBrowserVersionFromTheShell(String browserName) {
Optional<String> browserVersionUsingProperties = empty();
String browserVersionDetectionCommand = config
.getBrowserVersionDetectionCommand();
if (!isNullOrEmpty(browserVersionDetectionCommand)) {
browserVersionUsingProperties = getBrowserVersionUsingCommand(
browserVersionDetectionCommand);
}
if (browserVersionUsingProperties.isPresent()) {
return browserVersionUsingProperties;
}

boolean online = config.isCommandsPropertiesOnlineFirst();
String propertiesName = COMMANDS_PROPERTIES;
Properties commandsProperties = getProperties(propertiesName, online);

String onlineMessage = online ? ONLINE : LOCAL;
log.debug("Detecting {} version using {} {}", browserName,
onlineMessage, propertiesName);

browserVersionUsingProperties = getBrowserVersionUsingProperties(
browserName, commandsProperties);

if (!browserVersionUsingProperties.isPresent()) {
String notOnlineMessage = online ? LOCAL : ONLINE;
log.debug(
"Browser version for {} not detected using {} properties (using {} {})",
browserName, onlineMessage, notOnlineMessage,
propertiesName);

commandsProperties = getProperties(propertiesName, !online);
browserVersionUsingProperties = getBrowserVersionUsingProperties(
browserName, commandsProperties);
}
// String browserVersionDetectionCommand = config
// .getBrowserVersionDetectionCommand();
// if (!isNullOrEmpty(browserVersionDetectionCommand)) {
// browserVersionUsingProperties = getBrowserVersionUsingCommand(
// browserVersionDetectionCommand);
// }
// if (browserVersionUsingProperties.isPresent()) {
// return browserVersionUsingProperties;
// }
//
// boolean online = config.isCommandsPropertiesOnlineFirst();
// String propertiesName = COMMANDS_PROPERTIES;
// Properties commandsProperties = getProperties(propertiesName, online);
//
// String onlineMessage = online ? ONLINE : LOCAL;
// log.debug("Detecting {} version using {} {}", browserName,
// onlineMessage, propertiesName);
//
// browserVersionUsingProperties = getBrowserVersionUsingProperties(
// browserName, commandsProperties);
//
// if (!browserVersionUsingProperties.isPresent()) {
// String notOnlineMessage = online ? LOCAL : ONLINE;
// log.debug(
// "Browser version for {} not detected using {} properties (using {} {})",
// browserName, onlineMessage, notOnlineMessage,
// propertiesName);
//
// commandsProperties = getProperties(propertiesName, !online);
// browserVersionUsingProperties = getBrowserVersionUsingProperties(
// browserName, commandsProperties);
// }

return browserVersionUsingProperties;
}
Expand Down

0 comments on commit d6f6d2d

Please sign in to comment.