From 4ba44428c799168f6bb316e76e2edd7ab47243c5 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sat, 27 Jan 2018 13:50:49 +0200 Subject: [PATCH] Include version number in extracted path Fixes #26 --- .../lazerycode/selenium/download/DownloadHandler.java | 8 ++++---- .../lazerycode/selenium/repository/DriverContext.java | 4 ++-- .../com/lazerycode/selenium/repository/DriverMap.java | 9 +++++++++ .../selenium/download/DownloadHandlerTest.java | 10 ++++++---- .../selenium/repository/DriverContextTest.java | 4 ++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/lazerycode/selenium/download/DownloadHandler.java b/src/main/java/com/lazerycode/selenium/download/DownloadHandler.java index 65e3a03..f4772c7 100644 --- a/src/main/java/com/lazerycode/selenium/download/DownloadHandler.java +++ b/src/main/java/com/lazerycode/selenium/download/DownloadHandler.java @@ -91,11 +91,11 @@ public DriverMap ensureStandaloneExecutableFilesExist() throws MojoFailureExcept for (final DriverContext driverContext : filesToDownload.getKeys()) { if (onlyGetLatestVersions) { DriverDetails driverDetails = filesToDownload.getDetailsForLatestVersionOfDriverContext(driverContext); - downloadAndExtractExecutableFiles(driverContext, driverDetails); + downloadAndExtractExecutableFiles(driverContext, driverDetails, filesToDownload.getLatestVersionOfDriverContext(driverContext)); } else { for (String version : filesToDownload.getAvailableVersionsForDriverContext(driverContext)) { DriverDetails driverDetails = filesToDownload.getDetailsForVersionOfDriverContext(driverContext, version); - downloadAndExtractExecutableFiles(driverContext, driverDetails); + downloadAndExtractExecutableFiles(driverContext, driverDetails, version); } } } @@ -103,7 +103,7 @@ public DriverMap ensureStandaloneExecutableFilesExist() throws MojoFailureExcept return filesToDownload; } - private void downloadAndExtractExecutableFiles(DriverContext driverContext, DriverDetails driverDetails) throws IOException, MojoExecutionException, URISyntaxException, MojoFailureException { + private void downloadAndExtractExecutableFiles(DriverContext driverContext, DriverDetails driverDetails, String version) throws IOException, MojoExecutionException, URISyntaxException, MojoFailureException { String localZipFileAbsolutePath = this.downloadedZipFileDirectory + File.separator + FilenameUtils.getName(driverDetails.fileLocation.getFile()); File localZipFile = new File(localZipFileAbsolutePath); boolean fileNeedsToBeDownloaded = true; @@ -122,7 +122,7 @@ private void downloadAndExtractExecutableFiles(DriverContext driverContext, Driv localZipFile = downloadFile(driverDetails, checkFileHash); } - String extractedFileLocation = this.rootStandaloneServerDirectory.getAbsolutePath() + File.separator + driverContext.buildExtractionPathFromDriverContext(); + String extractedFileLocation = this.rootStandaloneServerDirectory.getAbsolutePath() + File.separator + driverContext.buildExtractionPathFromDriverContext(version); FileExtractor fileExtractor = new FileExtractor(this.overwriteFilesThatExist); driverDetails.extractedLocation = fileExtractor.extractFileFromArchive(localZipFile, extractedFileLocation, driverContext.getBinaryTypeForContext()); } diff --git a/src/main/java/com/lazerycode/selenium/repository/DriverContext.java b/src/main/java/com/lazerycode/selenium/repository/DriverContext.java index 20cbfa1..a1369cd 100644 --- a/src/main/java/com/lazerycode/selenium/repository/DriverContext.java +++ b/src/main/java/com/lazerycode/selenium/repository/DriverContext.java @@ -35,8 +35,8 @@ public static DriverContext binaryDataFor(String osName, String browserType, Sys return new DriverContext(browserType, osName, architecture); } - public String buildExtractionPathFromDriverContext() { - return operatingSystem.toString().toLowerCase() + File.separator + driverType.getBinaryTypeAsString() + File.separator + systemArchitecture.getSystemArchitectureType() + File.separator; + public String buildExtractionPathFromDriverContext(String version) { + return operatingSystem.toString().toLowerCase() + File.separator + driverType.getBinaryTypeAsString() + File.separator + version.toLowerCase() + File.separator + systemArchitecture.getSystemArchitectureType() + File.separator; } public BinaryType getBinaryTypeForContext() { diff --git a/src/main/java/com/lazerycode/selenium/repository/DriverMap.java b/src/main/java/com/lazerycode/selenium/repository/DriverMap.java index 6b73700..36127b7 100644 --- a/src/main/java/com/lazerycode/selenium/repository/DriverMap.java +++ b/src/main/java/com/lazerycode/selenium/repository/DriverMap.java @@ -41,6 +41,15 @@ public DriverDetails getDetailsForLatestVersionOfDriverContext(DriverContext dri return driverVersions.get(driverVersions.lastKey()); } + public String getLatestVersionOfDriverContext(DriverContext driverContext) { + if (!repository.containsKey(driverContext)) { + throw new IllegalArgumentException("Driver context not found in driver repository"); + } + + TreeMap driverVersions = repository.get(driverContext); + return driverVersions.lastKey(); + } + public Set getKeys() { return repository.keySet(); } diff --git a/src/test/java/com/lazerycode/selenium/download/DownloadHandlerTest.java b/src/test/java/com/lazerycode/selenium/download/DownloadHandlerTest.java index da82a8a..0f2f148 100644 --- a/src/test/java/com/lazerycode/selenium/download/DownloadHandlerTest.java +++ b/src/test/java/com/lazerycode/selenium/download/DownloadHandlerTest.java @@ -134,8 +134,9 @@ public void filesAreExtractedIntoTheCorrectStandaloneServerPathAndCanBeOverwritt fileDetails.hash = validSHA1Hash; DriverContext driverContext = binaryDataFor(OSX, PHANTOMJS, ARCHITECTURE_64_BIT); DriverMap driverMap = new DriverMap(); - driverMap.getMapForDriverContext(driverContext).put("2.13", fileDetails); - File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + "64bit" + File.separator + "phantomjs"); + String version = "2.13"; + driverMap.getMapForDriverContext(driverContext).put(version, fileDetails); + File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + version + File.separator + "64bit" + File.separator + "phantomjs"); assertThat(expectedDownloadedFile.exists(), is(equalTo(false))); @@ -161,8 +162,9 @@ public void fileCanBeDownloadedIfThereIsNoHashInFileDownloadListFileDetails() th fileDetails.hashType = null; fileDetails.hash = null; DriverMap driverMap = new DriverMap(); - driverMap.getMapForDriverContext(binaryDataFor(OSX, PHANTOMJS, ARCHITECTURE_64_BIT)).put("2.13", fileDetails); - File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + "64bit" + File.separator + "phantomjs"); + String version = "2.13"; + driverMap.getMapForDriverContext(binaryDataFor(OSX, PHANTOMJS, ARCHITECTURE_64_BIT)).put(version, fileDetails); + File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + version + File.separator + "64bit" + File.separator + "phantomjs"); assertThat(expectedDownloadedFile.exists(), is(equalTo(false))); diff --git a/src/test/java/com/lazerycode/selenium/repository/DriverContextTest.java b/src/test/java/com/lazerycode/selenium/repository/DriverContextTest.java index 4fe675c..35b84e0 100644 --- a/src/test/java/com/lazerycode/selenium/repository/DriverContextTest.java +++ b/src/test/java/com/lazerycode/selenium/repository/DriverContextTest.java @@ -22,8 +22,8 @@ public void driverContextWithStringsMapsTpDriverContextWithEnums() { @Test public void driverContextCreatesAStringThatCanBeUsedAsAFilePath() { - String expectedFilepath = "osx" + File.separator + "googlechrome" + File.separator + "64bit" + File.separator; - String filePath = binaryDataFor(OSX, GOOGLECHROME, ARCHITECTURE_64_BIT).buildExtractionPathFromDriverContext(); + String expectedFilepath = "osx" + File.separator + "googlechrome" + File.separator + "1.2.3" + File.separator + "64bit" + File.separator; + String filePath = binaryDataFor(OSX, GOOGLECHROME, ARCHITECTURE_64_BIT).buildExtractionPathFromDriverContext("1.2.3"); assertThat(filePath, is(equalTo(expectedFilepath)));