Skip to content

Commit 5e7a380

Browse files
author
Allan Paiste
committed
introduce driver version aliases; change version polling output parser pattern type to regex; try polling version with multiple path schemes on Windows
1 parent a88681a commit 5e7a380

File tree

3 files changed

+58
-14
lines changed

3 files changed

+58
-14
lines changed

changelog.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"2.0.0": {
3+
"breaking": [
4+
"(config) version polling output parser switched to use refex pattern matching instead of relying on sscanf"
5+
],
6+
"feature": [
7+
"allow driver version polling to use version aliases (required for some drivers that use multiple versioning schemes (like EdgeDriver))",
8+
"try version polling with escaped path on Windows if normal call results in blank response"
9+
]
10+
},
211
"1.0.0": {
312
"feature": [
413
"allow webdriver binary download based on passed-in configuration"

src/Analysers/ProjectAnalyser.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Vaimo\WebDriverBinaryDownloader\Analysers;
77

88
use Vaimo\WebDriverBinaryDownloader\Interfaces\ConfigInterface;
9+
use Vaimo\WebDriverBinaryDownloader\Interfaces\PlatformAnalyserInterface as Platform;
910

1011
class ProjectAnalyser
1112
{
@@ -89,13 +90,38 @@ public function resolveInstalledDriverVersion($binaryDir)
8990
}
9091

9192
$executableName = $executableNames[$platformCode];
92-
93-
$driverPath = realpath($this->utils->composePath($binaryDir, $executableName));
93+
$executableRenames = $this->pluginConfig->getExecutableFileRenames();
94+
95+
$driverPath = realpath(
96+
$this->utils->composePath($binaryDir, $executableRenames[$executableName] ?? $executableName)
97+
);
98+
99+
$binaries = [$driverPath];
94100

95-
return $this->versionResolver->pollForVersion(
96-
[$driverPath],
101+
if ($platformCode === Platform::TYPE_WIN64 || $platformCode === Platform::TYPE_WIN32) {
102+
$binaries = array_merge($binaries, array_map(function ($item) {
103+
return str_replace('\\', '\\\\', $item);
104+
}, $binaries));
105+
}
106+
107+
$installedVersion = $this->versionResolver->pollForVersion(
108+
$binaries,
97109
$this->pluginConfig->getDriverVersionPollingConfig()
98110
);
111+
112+
$versionMap = $this->pluginConfig->getBrowserDriverVersionMap();
113+
114+
foreach ($versionMap as $driverVersion) {
115+
if (!is_array($driverVersion)) {
116+
$driverVersion = [$driverVersion];
117+
}
118+
119+
if (in_array($installedVersion, $driverVersion)) {
120+
$installedVersion = reset($driverVersion);
121+
}
122+
}
123+
124+
return $installedVersion;
99125
}
100126

101127
public function resolveRequiredDriverVersion()
@@ -118,7 +144,11 @@ public function resolveRequiredDriverVersion()
118144

119145
if (!$version) {
120146
$versionMap = array_filter($this->pluginConfig->getBrowserDriverVersionMap());
121-
$version = reset($versionMap);
147+
$version = reset($versionMap);
148+
149+
if (is_array($version)) {
150+
$version = reset($version);
151+
}
122152
}
123153
}
124154

@@ -148,7 +178,7 @@ private function resolveBrowserDriverVersion($browserVersion)
148178
continue;
149179
}
150180

151-
return $driverVersion;
181+
return is_array($driverVersion) ? reset($driverVersion) : $driverVersion;
152182
}
153183

154184
return '';

src/Installer/VersionResolver.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,31 @@ public function pollForVersion(array $binaryPaths, array $versionPollingConfig)
3030
$processExecutor::setTimeout(10);
3131

3232
foreach ($binaryPaths as $path) {
33-
if (!is_executable($path)) {
33+
if ($path !== null && !is_executable($path)) {
3434
continue;
3535
}
3636

3737
foreach ($versionPollingConfig as $callTemplate => $resultPatterns) {
3838
$output = '';
3939

40-
$processExecutor->execute(sprintf($callTemplate, $path), $output);
40+
$pollCommand = sprintf($callTemplate, $path);
41+
$processExecutor->execute($pollCommand, $output);
4142

42-
$output = trim($output);
43+
$output = str_replace(chr(0), '', trim($output));
44+
45+
if (!$output) {
46+
continue;
47+
}
4348

4449
foreach ($resultPatterns as $pattern) {
45-
$matches = sscanf($output, $pattern);
50+
preg_match(sprintf('/%s/i', $pattern), $output, $matches);
51+
52+
$result = $matches[1] ?? false;
4653

47-
if (!is_array($matches) || !$matches) {
54+
if (!$result) {
4855
continue;
4956
}
50-
51-
$result = reset($matches);
52-
57+
5358
try {
5459
$this->versionParser->parseConstraints($result);
5560
} catch (\UnexpectedValueException $exception) {

0 commit comments

Comments
 (0)